From b71de57b210cd3277b096b7124634be627386e8b Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Mon, 24 Aug 2009 09:47:26 -0300 Subject: [PATCH] some simplifications to Request and Response classes --- scrapy/http/request/form.py | 2 +- scrapy/http/request/rpc.py | 4 +++- scrapy/http/response/__init__.py | 12 ++++++---- scrapy/http/response/html.py | 2 +- scrapy/http/response/text.py | 41 +++++++++++++------------------- scrapy/http/response/xml.py | 2 +- 6 files changed, 31 insertions(+), 32 deletions(-) diff --git a/scrapy/http/request/form.py b/scrapy/http/request/form.py index ab4784d5d..0f3d85c8a 100644 --- a/scrapy/http/request/form.py +++ b/scrapy/http/request/form.py @@ -26,7 +26,7 @@ class FormRequest(Request): def __init__(self, *args, **kwargs): formdata = kwargs.pop('formdata', None) - Request.__init__(self, *args, **kwargs) + super(FormRequest, self).__init__(*args, **kwargs) if formdata: items = formdata.iteritems() if isinstance(formdata, dict) else formdata diff --git a/scrapy/http/request/rpc.py b/scrapy/http/request/rpc.py index e3dbd2816..e941bf70b 100644 --- a/scrapy/http/request/rpc.py +++ b/scrapy/http/request/rpc.py @@ -12,6 +12,8 @@ from scrapy.http.request import Request class XmlRpcRequest(Request): + __slots__ = () + def __init__(self, *args, **kwargs): if 'body' not in kwargs: params = kwargs.pop('params') @@ -24,5 +26,5 @@ class XmlRpcRequest(Request): # xmlrpc query multiples times over the same url kwargs.setdefault('dont_filter', True) - Request.__init__(self, *args, **kwargs) + super(XmlRpcRequest, self).__init__(*args, **kwargs) self.headers.setdefault('Content-Type', 'text/xml') diff --git a/scrapy/http/response/__init__.py b/scrapy/http/response/__init__.py index 8c133ca59..49a57dc5a 100644 --- a/scrapy/http/response/__init__.py +++ b/scrapy/http/response/__init__.py @@ -44,17 +44,20 @@ class Response(object_ref): if isinstance(body, str): self._body = body elif isinstance(body, unicode): - raise TypeError("Cannot assign a unicode body to a raw Response. Use TextResponse, HtmlResponse, etc") + raise TypeError("Cannot assign a unicode body to a raw Response. " \ + "Use TextResponse, HtmlResponse, etc") elif body is None: self._body = '' else: - raise TypeError("Response body must either str or unicode. Got: '%s'" % type(body).__name__) + raise TypeError("Response body must either str or unicode. Got: '%s'" \ + % type(body).__name__) body = property(_get_body, _set_body) def __repr__(self): return "%s(url=%s, headers=%s, status=%s, body=%s)" % \ - (type(self).__name__, repr(self.url), repr(self.headers), repr(self.status), repr(self.body)) + (type(self).__name__, repr(self.url), repr(self.headers), \ + repr(self.status), repr(self.body)) def __str__(self): flags = "(%s) " % ",".join(self.flags) if self.flags else "" @@ -65,7 +68,8 @@ class Response(object_ref): """Return a copy of this Response""" return self.replace() - def replace(self, url=None, status=None, headers=None, body=None, meta=None, flags=None, cls=None, **kwargs): + def replace(self, url=None, status=None, headers=None, body=None, meta=None, \ + flags=None, cls=None, **kwargs): """Create a new Response with the same attributes except for those given new values. """ diff --git a/scrapy/http/response/html.py b/scrapy/http/response/html.py index 6c7c43a10..61269f86c 100644 --- a/scrapy/http/response/html.py +++ b/scrapy/http/response/html.py @@ -24,7 +24,7 @@ class HtmlResponse(TextResponse): METATAG_RE2 = re.compile(r'