Scrapy, a fast high-level web crawling & scraping framework for Python.
upgrade parsel and add shim for deprecated selectorlist methods
Elias Dorneles766c25515275
diff --git a/requirements.txt b/requirements.txtindex afefb9d33..368e9340b 100644--- a/requirements.txt+++ b/requirements.txt@@ -7,4 +7,4 @@ queuelibsix>=1.5.2PyDispatcher>=2.0.5service_identity-parsel>=0.9.3+parsel>=0.9.5diff --git a/scrapy/selector/unified.py b/scrapy/selector/unified.pyindex 25cf6c98d..dddf80c06 100644--- a/scrapy/selector/unified.py+++ b/scrapy/selector/unified.py@@ -3,7 +3,7 @@ XPath selectors based on lxml"""import warnings-from parsel import Selector as ParselSelector, SelectorList+from parsel import Selector as ParselSelector, SelectorList as ParselSelectorListfrom scrapy.utils.trackref import object_reffrom scrapy.utils.python import to_bytesfrom scrapy.http import HtmlResponse, XmlResponse@@ -26,9 +26,24 @@ def _response_from_text(text, st):body=to_bytes(text, 'utf-8'))+class SelectorList(ParselSelectorList, object_ref):+ @deprecated(use_instead='.extract()')+ def extract_unquoted(self):+ return [x.extract_unquoted() for x in self]++ @deprecated(use_instead='.xpath()')+ def x(self, xpath):+ return self.select(xpath)++ @deprecated(use_instead='.xpath()')+ def select(self, xpath):+ return self.xpath(xpath)++class Selector(ParselSelector, object_ref):__slots__ = ['response']+ selectorlist_cls = SelectorListdef __init__(self, response=None, text=None, type=None, root=None, _root=None, **kwargs):st = _st(response, type or self._default_type)diff --git a/tests/test_selector.py b/tests/test_selector.pyindex 19b807a3f..141455b66 100644--- a/tests/test_selector.py+++ b/tests/test_selector.py@@ -101,6 +101,28 @@ class SelectorTestCase(unittest.TestCase):assert not hasattr(x, '__dict__'), "%s does not use __slots__" % \x.__class__.__name__+ def test_deprecated_selector_methods(self):+ sel = Selector(TextResponse(url="http://example.com", body=b'<p>some text</p>'))++ with warnings.catch_warnings(record=True) as w:+ sel.select('//p')+ self.assertSubstring('Use .xpath() instead', str(w[-1].message))++ with warnings.catch_warnings(record=True) as w:+ sel.extract_unquoted()+ self.assertSubstring('Use .extract() instead', str(w[-1].message))++ def test_deprecated_selectorlist_methods(self):+ sel = Selector(TextResponse(url="http://example.com", body=b'<p>some text</p>'))++ with warnings.catch_warnings(record=True) as w:+ sel.xpath('//p').select('.')+ self.assertSubstring('Use .xpath() instead', str(w[-1].message))++ with warnings.catch_warnings(record=True) as w:+ sel.xpath('//p').extract_unquoted()+ self.assertSubstring('Use .extract() instead', str(w[-1].message))+class DeprecatedXpathSelectorTest(unittest.TestCase):