diff --git a/scrapy/selector/lxmldocument.py b/scrapy/selector/lxmldocument.py deleted file mode 100644 index 817349b58..000000000 --- a/scrapy/selector/lxmldocument.py +++ /dev/null @@ -1,31 +0,0 @@ -""" -This module contains a simple class (LxmlDocument) which provides cache and -garbage collection to lxml element tree documents. -""" - -import weakref -from lxml import etree -from scrapy.utils.trackref import object_ref - - -def _factory(response, parser_cls): - url = response.url - body = response.body_as_unicode().strip().encode('utf8') or '' - parser = parser_cls(recover=True, encoding='utf8') - return etree.fromstring(body, parser=parser, base_url=url) - - -class LxmlDocument(object_ref): - - cache = weakref.WeakKeyDictionary() - __slots__ = ['__weakref__'] - - def __new__(cls, response, parser=etree.HTMLParser): - cache = cls.cache.setdefault(response, {}) - if parser not in cache: - obj = object_ref.__new__(cls) - cache[parser] = _factory(response, parser) - return cache[parser] - - def __str__(self): - return "" % self.root.tag diff --git a/tests/py3-ignores.txt b/tests/py3-ignores.txt index 9be3a99a8..8f5c0de48 100644 --- a/tests/py3-ignores.txt +++ b/tests/py3-ignores.txt @@ -26,7 +26,6 @@ tests/test_pipeline_files.py tests/test_pipeline_images.py tests/test_proxy_connect.py tests/test_selector_csstranslator.py -tests/test_selector_lxmldocument.py tests/test_selector.py tests/test_spidermiddleware_depth.py tests/test_spidermiddleware_httperror.py diff --git a/tests/test_selector_lxmldocument.py b/tests/test_selector_lxmldocument.py deleted file mode 100644 index 090cc21bc..000000000 --- a/tests/test_selector_lxmldocument.py +++ /dev/null @@ -1,26 +0,0 @@ -import unittest -from scrapy.selector.lxmldocument import LxmlDocument -from scrapy.http import TextResponse, HtmlResponse - - -class LxmlDocumentTest(unittest.TestCase): - - def test_caching(self): - r1 = HtmlResponse('http://www.example.com', body=b'') - r2 = r1.copy() - - doc1 = LxmlDocument(r1) - doc2 = LxmlDocument(r1) - doc3 = LxmlDocument(r2) - - # make sure it's cached - assert doc1 is doc2 - assert doc1 is not doc3 - - def test_null_char(self): - # make sure bodies with null char ('\x00') don't raise a TypeError exception - body = b'test problematic \x00 body' - response = TextResponse('http://example.com/catalog/product/blabla-123', - headers={'Content-Type': 'text/plain; charset=utf-8'}, - body=body) - LxmlDocument(response)