set base_url in kwargs to be fully backward compatible

This commit is contained in:
Elias Dorneles 2015-08-11 14:06:24 -03:00
parent 8ef5aa2ffc
commit e50610bd3a
2 changed files with 8 additions and 0 deletions

View File

@ -46,6 +46,7 @@ class Selector(ParselSelector, object_ref):
if response is not None:
text = response.body_as_unicode()
kwargs.setdefault('base_url', response.url)
self.response = response
super(Selector, self).__init__(text=text, type=st, root=root, **kwargs)

View File

@ -33,6 +33,13 @@ class SelectorTestCase(unittest.TestCase):
self.assertEqual([x.extract() for x in sel.xpath("concat(//input[@name='a']/@value, //input[@name='b']/@value)")],
[u'12'])
def test_root_base_url(self):
body = b'<html><form action="/path"><input name="a" /></form></html>'
url = "http://example.com"
response = TextResponse(url=url, body=body, encoding='utf-8')
sel = Selector(response)
self.assertEqual(url, sel.root.base)
def test_deprecated_root_argument(self):
with warnings.catch_warnings(record=True) as w:
root = etree.fromstring(u'<html/>')