http: add errback to Request constructor

--HG--
extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%401018
This commit is contained in:
Daniel Grana 2009-03-25 13:15:55 +00:00
parent 828c3e0988
commit 70a686c02b
2 changed files with 10 additions and 4 deletions

View File

@ -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

View File

@ -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 {}