From 70a686c02b2be82fb25bc2076003a34a46e3f14a Mon Sep 17 00:00:00 2001 From: Daniel Grana Date: Wed, 25 Mar 2009 13:15:55 +0000 Subject: [PATCH] http: add errback to Request constructor --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%401018 --- scrapy/trunk/docs/ref/request-response.rst | 9 +++++++-- scrapy/trunk/scrapy/http/request/__init__.py | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/scrapy/trunk/docs/ref/request-response.rst b/scrapy/trunk/docs/ref/request-response.rst index 7fce0df4b..591742f9c 100644 --- a/scrapy/trunk/docs/ref/request-response.rst +++ b/scrapy/trunk/docs/ref/request-response.rst @@ -25,7 +25,7 @@ functionality not required in the base classes. See Request objects =============== -.. class:: Request(url, callback=None, method='GET', body=None, headers=None, cookies=None, meta=None, encoding='utf-8', dont_filter=None) +.. class:: Request(url, callback=None, method='GET', body=None, headers=None, cookies=None, meta=None, encoding='utf-8', dont_filter=False, errback=None) A :class:`Request` object represents an HTTP request, which is usually generated in the Spider and executed by the Downloader, and thus generating @@ -75,6 +75,11 @@ Request objects be filtered by the scheduler. This is used when you want to perform an identical request multiple times, for whatever reason + ``errback`` is a function that will be called if any exception was raised while + processing the request, it takes a `Twisted Failure`_ instance as first parameter. + +.. _Twisted Failure: http://twistedmatrix.com/documents/8.2.0/api/twisted.python.failure.Failure.html + Request Attributes ------------------ @@ -147,7 +152,7 @@ Copying Requests and callbacks When you copy a request using the :meth:`Request.copy` or :meth:`Request.replace` methods the callback of the request is not copied by default. This is because of legacy reasons along with limitations in the -underlying network library, which doesn't allow sharing `Twisted deferreds`. +underlying network library, which doesn't allow sharing `Twisted deferreds`_. .. _Twisted deferreds: http://twistedmatrix.com/projects/core/documentation/howto/defer.html diff --git a/scrapy/trunk/scrapy/http/request/__init__.py b/scrapy/trunk/scrapy/http/request/__init__.py index 71343f4cb..0055c7139 100644 --- a/scrapy/trunk/scrapy/http/request/__init__.py +++ b/scrapy/trunk/scrapy/http/request/__init__.py @@ -18,7 +18,8 @@ from scrapy.utils.defer import chain_deferred class Request(object): def __init__(self, url, callback=None, method='GET', headers=None, body=None, - cookies=None, meta=None, encoding='utf-8', dont_filter=False): + cookies=None, meta=None, encoding='utf-8', dont_filter=False, + errback=None): self._encoding = encoding # this one has to be set first self.method = method.upper() @@ -26,7 +27,7 @@ class Request(object): self.set_body(body) if callable(callback): - callback = defer.Deferred().addCallback(callback) + callback = defer.Deferred().addCallbacks(callback, errback) self.deferred = callback or defer.Deferred() self.cookies = cookies or {}