Scrapy, a fast high-level web crawling & scraping framework for Python.
Implement Response.cb_kwargs
Adrián Chavesdf937d8280fe
diff --git a/docs/topics/request-response.rst b/docs/topics/request-response.rstindex 4cf367d96..05b7bb5c7 100644--- a/docs/topics/request-response.rst+++ b/docs/topics/request-response.rst@@ -672,6 +672,18 @@ Response objects.. seealso:: :attr:`Request.meta` attribute+ .. attribute:: Response.cb_kwargs++ A shortcut to the :attr:`Request.cb_kwargs` attribute of the+ :attr:`Response.request` object (ie. ``self.request.cb_kwargs``).++ Unlike the :attr:`Response.request` attribute, the+ :attr:`Response.cb_kwargs` attribute is propagated along redirects and+ retries, so you will get the original :attr:`Request.cb_kwargs` sent+ from your spider.++ .. seealso:: :attr:`Request.cb_kwargs` attribute+.. attribute:: Response.flagsA list that contains flags for this response. Flags are labels used fordiff --git a/scrapy/http/response/__init__.py b/scrapy/http/response/__init__.pyindex 64e9c6c20..ee9720d52 100644--- a/scrapy/http/response/__init__.py+++ b/scrapy/http/response/__init__.py@@ -24,6 +24,16 @@ class Response(object_ref):self.request = requestself.flags = [] if flags is None else list(flags)+ @property+ def cb_kwargs(self):+ try:+ return self.request.cb_kwargs+ except AttributeError:+ raise AttributeError(+ "Response.cb_kwargs not available, this response "+ "is not tied to any request"+ )+@propertydef meta(self):try: