Пример #1
0
    def test_bytes(self):
        """Byte types should return bytes"""

        if PY2:
            self.assertEqual(bytes, type(make_bytes(bytes('string'))))
            self.assertEqual(bytes, type(make_bytes(bytearray('string'))))
            self.assertEqual(bytes, type(make_bytes(buffer('string'))))
        else:
            self.assertEqual(bytes, type(make_bytes(bytes('string', 'utf-8'))))
            self.assertEqual(bytes, type(make_bytes(bytearray('string', 'utf-8'))))
Пример #2
0
    def test_bytes(self):
        """Byte types should return bytes"""

        if PY2:
            self.assertEqual(bytes, type(make_bytes(bytes('string'))))
            self.assertEqual(bytes, type(make_bytes(bytearray('string'))))
            self.assertEqual(bytes, type(make_bytes(buffer('string'))))
        else:
            self.assertEqual(bytes, type(make_bytes(bytes('string', 'utf-8'))))
            self.assertEqual(bytes,
                             type(make_bytes(bytearray('string', 'utf-8'))))
Пример #3
0
    def search(self, show, language, cache=True):
        """
        :param show: The show name to search for
        :param language: The language abbreviation to search for. E.g. "en"
        :param cache: If False, the local cache will not be used and the
            resources will be reloaded from server.
        :return: A :class:`Search()` instance
        :raise: :exc:`pytvdbapi.error.TVDBValueError`

        Searches the server for a show with the provided show name in the
        provided language. The language should be one of the supported
        language abbreviations or it could be set to *all* to search all
        languages. It will raise :class:`pytvdbapi.error.TVDBValueError` if
        an invalid language is provided.

        Searches are always cached within a session to make subsequent
        searches with the same parameters fast. If *cache*
        is set to True searches will also be cached across sessions,
        this is recommended to increase speed and to reduce the workload of
        the servers.

        Example::

            >>> from pytvdbapi import api
            >>> db = api.TVDB("B43FF87DE395DF56")
            >>> result = db.search("House", "en")

            >>> print(result[0])
            <Show - House>

            >>> for show in result:
            ...     print(show) # doctest: +ELLIPSIS
            <Show - House>
            ...
            <Show - House Of Cards (2013)>
            ...
        """

        logger.debug(u"Searching for {0} using language {1}".format(
            show, language))

        if language != u'all' and language not in __LANGUAGES__:
            raise error.TVDBValueError(
                u"{0} is not a valid language".format(language))

        if (show, language) not in self.search_buffer or not cache:
            context = {'series': quote(make_bytes(show)), "language": language}
            data = generate_tree(
                self.loader.load(__search__.format(**context), cache))
            shows = [
                Show(d, self, language, self.config)
                for d in parse_xml(data, "Series")
            ]

            self.search_buffer[(show, language)] = shows

        return Search(self.search_buffer[(show, language)], show, language)
Пример #4
0
def generate_tree(xml_data):
    """
    :param xml_data: The string xml data to generate the tree from

    :return: A new ElementTree
    :raise: :class:`pytvdbapi.error.BadData`

    Converts the xml data into an element tree
    """
    try:
        return eTree.fromstring(make_bytes(xml_data, 'utf-8'))
    except ParseError:
        raise error.BadData(u"Bad XML data received")
Пример #5
0
def generate_tree(xml_data):
    """
    :param xml_data: The string xml data to generate the tree from

    :return: A new ElementTree
    :raise: :class:`pytvdbapi.error.BadData`

    Converts the xml data into an element tree
    """
    try:
        return eTree.fromstring(make_bytes(xml_data, 'utf-8'))
    except ParseError:
        raise error.BadData(u"Bad XML data received")
Пример #6
0
    def search(self, show, language, cache=True):
        """
        :param show: The show name to search for
        :param language: The language abbreviation to search for. E.g. "en"
        :param cache: If False, the local cache will not be used and the
            resources will be reloaded from server.
        :return: A :class:`Search()` instance
        :raise: :exc:`pytvdbapi.error.TVDBValueError`

        Searches the server for a show with the provided show name in the
        provided language. The language should be one of the supported
        language abbreviations or it could be set to *all* to search all
        languages. It will raise :class:`pytvdbapi.error.TVDBValueError` if
        an invalid language is provided.

        Searches are always cached within a session to make subsequent
        searches with the same parameters fast. If *cache*
        is set to True searches will also be cached across sessions,
        this is recommended to increase speed and to reduce the workload of
        the servers.

        Example::

            >>> from pytvdbapi import api
            >>> db = api.TVDB("B43FF87DE395DF56")
            >>> result = db.search("House", "en")

            >>> print(result[0])
            <Show - House>

            >>> for show in result:
            ...     print(show) # doctest: +ELLIPSIS
            <Show - House>
            ...
            <Show - House Of Cards (2013)>
            ...
        """

        logger.debug(u"Searching for {0} using language {1}".format(show, language))

        if language != u'all' and language not in __LANGUAGES__:
            raise error.TVDBValueError(u"{0} is not a valid language".format(language))

        if (show, language) not in self.search_buffer or not cache:
            context = {'series': quote(make_bytes(show)), "language": language}
            data = generate_tree(self.loader.load(__search__.format(**context), cache))
            shows = [Show(d, self, language, self.config) for d in parse_xml(data, "Series")]

            self.search_buffer[(show, language)] = shows

        return Search(self.search_buffer[(show, language)], show, language)
Пример #7
0
    def test_text(self):
        """Text arguments should be encoded properly"""
        _input = u"unicode text" if PY2 else "python 3 string"
        result = make_bytes(_input)

        self.assertEqual(type(result), bytes)
Пример #8
0
 def test_none(self):
     """Passing None should return None"""
     self.assertEqual(None, make_bytes(None))
Пример #9
0
    def test_text(self):
        """Text arguments should be encoded properly"""
        _input = u"unicode text" if PY2 else "python 3 string"
        result = make_bytes(_input)

        self.assertEqual(type(result), bytes)
Пример #10
0
 def test_none(self):
     """Passing None should return None"""
     self.assertEqual(None, make_bytes(None))