Esempio n. 1
0
def safe_repr(fmt, *args, **kwargs):
    """Formatter that handles unicode arguments."""
    if not is_py3():
        # unicode fmt can take str args, str fmt cannot take unicode args
        fmt = fmt.decode("utf-8")
        out = fmt.format(*args, **kwargs)
        return out.encode("utf-8")
    else:
        return fmt.format(*args, **kwargs)
Esempio n. 2
0
def safe_repr(fmt, *args, **kwargs):
    """Formatter that handles unicode arguments."""
    if not is_py3():
        # unicode fmt can take str args, str fmt cannot take unicode args
        fmt = fmt.decode("utf-8")
        out = fmt.format(*args, **kwargs)
        return out.encode("utf-8")
    else:
        return fmt.format(*args, **kwargs)
Esempio n. 3
0
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from rtorrent.compat import is_py3
import os.path
import re
import rtorrent.lib.bencode as bencode
import hashlib

if is_py3():
    from urllib.request import urlopen  # @UnresolvedImport @UnusedImport
else:
    from urllib2 import urlopen  # @UnresolvedImport @Reimport


class TorrentParser():
    def __init__(self, torrent):
        """Decode and parse given torrent

        @param torrent: handles: urls, file paths, string of torrent data
        @type torrent: str

        @raise AssertionError: Can be raised for a couple reasons:
                               - If _get_raw_torrent() couldn't figure out
                               what X{torrent} is
Esempio n. 4
0
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import hashlib
import os.path
import re

import rtorrent.lib.bencode as bencode
from rtorrent.compat import is_py3

if is_py3():
    from urllib.request import urlopen  # @UnresolvedImport @UnusedImport
else:
    from urllib.request import urlopen  # @UnresolvedImport @Reimport


class TorrentParser():
    def __init__(self, torrent):
        """Decode and parse given torrent

        @param torrent: handles: urls, file paths, string of torrent data
        @type torrent: str

        @raise AssertionError: Can be raised for a couple reasons:
                               - If _get_raw_torrent() couldn't figure out
                               what X{torrent} is