Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Simplified Request/Response __repr__ to be the same as __str__. This improves legibility and shouldn't affect any functionality, since we never use __repr__ for reconstructing a response AFAIK. Also fixes #318

Pablo Hoffman88e33ad0ad95
diff --git a/scrapy/http/request/__init__.py b/scrapy/http/request/__init__.py
index 7fd034890..a9d81d8b6 100644
--- a/scrapy/http/request/__init__.py
+++ b/scrapy/http/request/__init__.py
@@ -88,10 +88,7 @@ class Request(object_ref):
def __str__(self):
return "<%s %s>" % (self.method, self.url)
- def __repr__(self):
- attrs = ['url', 'method', 'body', 'headers', 'cookies', 'meta']
- args = ", ".join(["%s=%r" % (a, getattr(self, a)) for a in attrs])
- return "%s(%s)" % (self.__class__.__name__, args)
+ __repr__ = __str__
def copy(self):
"""Return a copy of this Request"""
diff --git a/scrapy/http/response/__init__.py b/scrapy/http/response/__init__.py
index 2d0ff5fa8..ed4e3e3b4 100644
--- a/scrapy/http/response/__init__.py
+++ b/scrapy/http/response/__init__.py
@@ -61,14 +61,11 @@ class Response(object_ref):
body = property(_get_body, deprecated_setter(_set_body, 'body'))
- def __repr__(self):
- attrs = ['url', 'status', 'body', 'headers', 'request', 'flags']
- args = ", ".join(["%s=%r" % (a, getattr(self, a)) for a in attrs])
- return "%s(%s)" % (self.__class__.__name__, args)
-
def __str__(self):
return "<%d %s>" % (self.status, self.url)
+ __repr__ = __str__
+
def copy(self):
"""Return a copy of this Response"""
return self.replace()