diff --git a/scrapy/http/cookies.py b/scrapy/http/cookies.py index e92c3fe73e184fe5a20150a7daf318fb091a7738..a1e95102e0c56c7d5c47154a9e39bceffa7bdc1d 100644 --- a/scrapy/http/cookies.py +++ b/scrapy/http/cookies.py @@ -137,13 +137,29 @@ class WrappedRequest(object): """ return self.request.meta.get('is_unverifiable', False) - # python3 uses request.unverifiable + def get_origin_req_host(self): + return urlparse_cached(self.request).hostname + + # python3 uses attributes instead of methods + @property + def full_url(self): + return self.get_full_url() + + @property + def host(self): + return self.get_host() + + @property + def type(self): + return self.get_type() + @property def unverifiable(self): return self.is_unverifiable() - def get_origin_req_host(self): - return urlparse_cached(self.request).hostname + @property + def origin_req_host(self): + return self.get_origin_req_host() def has_header(self, name): return name in self.request.headers diff --git a/tests/test_http_cookies.py b/tests/test_http_cookies.py index d529f609b5115f11aff49c4539526d0fef413262..549f779d8305223f3d398f1535bb6ab03af86b49 100644 --- a/tests/test_http_cookies.py +++ b/tests/test_http_cookies.py @@ -14,12 +14,15 @@ class WrappedRequestTest(TestCase): def test_get_full_url(self): self.assertEqual(self.wrapped.get_full_url(), self.request.url) + self.assertEqual(self.wrapped.full_url, self.request.url) def test_get_host(self): self.assertEqual(self.wrapped.get_host(), urlparse(self.request.url).netloc) + self.assertEqual(self.wrapped.host, urlparse(self.request.url).netloc) def test_get_type(self): self.assertEqual(self.wrapped.get_type(), urlparse(self.request.url).scheme) + self.assertEqual(self.wrapped.type, urlparse(self.request.url).scheme) def test_is_unverifiable(self): self.assertFalse(self.wrapped.is_unverifiable()) @@ -32,6 +35,7 @@ class WrappedRequestTest(TestCase): def test_get_origin_req_host(self): self.assertEqual(self.wrapped.get_origin_req_host(), 'www.example.com') + self.assertEqual(self.wrapped.origin_req_host, 'www.example.com') def test_has_header(self): self.assertTrue(self.wrapped.has_header('content-type'))