# Path: seedbox/torrent/bencode.py
# def bencode(x):
#     """Public method for encoding message
# 
#     :param x: message
#     :return: encoded string
#     :rtype: string
#     """
#     r = []
#     encode_func[type(x)](x, r)
#     return b''.join(r)


import io
import logging
import os
import six
from seedbox.torrent import bencode
        """
        if not os.path.exists(filepath):
            raise IOError('No file found at %s' % filepath)

        self.file = filepath
        self._content = None

    @property
    def content(self):
        if self._content is None:
            self._content = self.load_content()
        return self._content

    def load_content(self):
        """Reads the torrent file and decodes content.

        .. note::
            bencode is supremely more efficient parser for torrents but
            extremely strict in the format of the file. A custom parser based
            on another implementation handles parsing that is more flexible
            but it is not as efficient. Therefore when the file is well formed
            bencode is used but if it fails then the custom parser is used.
            If the custom parser fails then a ParsingError is raised.
        """

        with io.open(file=self.file, mode='rb') as handle:
            content = handle.read()

        try:
            return bencode.bdecode(content)

# Path: seedbox/torrent/bencode.py
# def bencode(x):
#     """Public method for encoding message
# 
#     :param x: message
#     :return: encoded string
#     :rtype: string
#     """
#     r = []
#     encode_func[type(x)](x, r)
#     return b''.join(r)


# Path: seedbox/torrent/parser.py
import io
import logging
import os
import six
from seedbox.torrent import bencode

        """
        if not os.path.exists(filepath):
            raise IOError('No file found at %s' % filepath)

        self.file = filepath
        self._content = None

    @property
    def content(self):
        if self._content is None:
            self._content = self.load_content()
        return self._content

    def load_content(self):
        """Reads the torrent file and decodes content.

        .. note::
            bencode is supremely more efficient parser for torrents but
            extremely strict in the format of the file. A custom parser based
            on another implementation handles parsing that is more flexible
            but it is not as efficient. Therefore when the file is well formed
            bencode is used but if it fails then the custom parser is used.
            If the custom parser fails then a ParsingError is raised.
        """

        with io.open(file=self.file, mode='rb') as handle:
            content = handle.read()

        try:
            return bencode.bdecode(content)

        except bencode.BTFailure as bterr: