From 643dbeffcf6951991fdeed0069690c55684e66ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=9D=CE=B9=CE=BA=CF=8C=CE=BB=CE=B1=CE=BF=CF=82-=CE=94?= =?UTF-8?q?=CE=B9=CE=B3=CE=B5=CE=BD=CE=AE=CF=82=20=CE=9A=CE=B1=CF=81=CE=B1?= =?UTF-8?q?=CE=B3=CE=B9=CE=AC=CE=BD=CE=BD=CE=B7=CF=82?= Date: Fri, 29 Jul 2016 17:13:59 +0300 Subject: [PATCH] Selector should not receive both response and text --- scrapy/selector/unified.py | 4 ++++ tests/test_selector.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/scrapy/selector/unified.py b/scrapy/selector/unified.py index 15f3d26df..64cb0232c 100644 --- a/scrapy/selector/unified.py +++ b/scrapy/selector/unified.py @@ -46,6 +46,10 @@ class Selector(_ParselSelector, object_ref): selectorlist_cls = SelectorList def __init__(self, response=None, text=None, type=None, root=None, _root=None, **kwargs): + if not(response is None or text is None): + raise ValueError('%s.__init__() received both response and text' + % self.__class__.__name__) + st = _st(response, type or self._default_type) if _root is not None: diff --git a/tests/test_selector.py b/tests/test_selector.py index 141455b66..af0cc4de2 100644 --- a/tests/test_selector.py +++ b/tests/test_selector.py @@ -123,6 +123,10 @@ class SelectorTestCase(unittest.TestCase): sel.xpath('//p').extract_unquoted() self.assertSubstring('Use .extract() instead', str(w[-1].message)) + def test_selector_bad_args(self): + with self.assertRaisesRegexp(ValueError, 'received both response and text'): + Selector(TextResponse(url='http://example.com', body=b''), text=u'') + class DeprecatedXpathSelectorTest(unittest.TestCase):