upgrade parsel and using promoted root attribute

This commit is contained in:
Elias Dorneles 2015-08-07 15:26:54 -03:00
parent 67c98b185b
commit 2fe6d128f5
5 changed files with 10 additions and 4 deletions

View File

@ -7,4 +7,4 @@ queuelib
six>=1.5.2
PyDispatcher>=2.0.5
service_identity
parsel>=0.9.1
parsel>=0.9.2

View File

@ -47,7 +47,7 @@ class LxmlParserLinkExtractor(object):
def _extract_links(self, selector, response_url, response_encoding, base_url):
links = []
# hacky way to get the underlying lxml parsed document
for el, attr, attr_val in self._iter_links(selector._root):
for el, attr, attr_val in self._iter_links(selector.root):
# pseudo lxml.html.HtmlElement.make_links_absolute(base_url)
attr_val = urljoin(base_url, attr_val)
url = self.process_attr(attr_val)

View File

@ -48,6 +48,12 @@ class Selector(ParselSelector, object_ref):
super(Selector, self).__init__(text=text, type=st, root=root, **kwargs)
# Deprecated api
@property
def _root(self):
warnings.warn("Attribute `_root` is deprecated, use `root` instead",
ScrapyDeprecationWarning, stacklevel=2)
return self.root
@deprecated(use_instead='.xpath()')
def select(self, xpath):
return self.xpath(xpath)

View File

@ -44,7 +44,7 @@ setup(
'pyOpenSSL',
'cssselect>=0.9',
'six>=1.5.2',
'parsel>=0.9.1',
'parsel>=0.9.2',
'PyDispatcher>=2.0.5',
'service_identity',
],

View File

@ -43,7 +43,7 @@ class SelectorTestCase(unittest.TestCase):
def test_deprecated_root_argument(self, warnings):
root = etree.fromstring(u'<html/>')
sel = self.sscls(_root=root)
self.assertIs(root, sel._root)
self.assertIs(root, sel.root)
warnings.warn.assert_called_once_with(
'Argument `_root` is deprecated, use `root` instead',
mock.ANY, stacklevel=2)