Support for afterFoundGet in HTTPDownloader
[email protected] Thu, 11 Mar 2010 02:19:41 -0000
| Newsgroups | gmane.comp.python.twisted.bugs |
|---|---|
| Message-ID | <[email protected]> |
New submission from zimmer <None>:
In twisted's current version HTTPDownloader [http://twistedmatrix.com/trac/browser/trunk/twisted/web/client.py#L353]
doesn't support afterFoundGet like HTTPClientFactory [http://twistedmatrix.com/trac/browser/trunk/twisted/web/client.py#L220] does. Here is a way to do (patch?) that.
Replace HTTPDownloader's _ _init_ _ with this
{{{
class HTTPDownloader(HTTPClientFactory):
"""Download to a file."""
protocol = HTTPPageDownloader
value = None
def __init__(self, url, fileOrName,
method='GET', postdata=None, headers=None,
agent="Twisted client", supportPartial=0,
timeout=0, cookies=None, followRedirect=1,
redirectLimit=20, afterFoundGet = False):
self.requestedPartial = 0
if isinstance(fileOrName, types.StringTypes):
self.fileName = fileOrName
self.file = None
if supportPartial and os.path.exists(self.fileName):
fileLength = os.path.getsize(self.fileName)
if fileLength:
self.requestedPartial = fileLength
if headers == None:
headers = {}
headers["range"] = "bytes=%d-" % fileLength
else:
self.file = fileOrName
HTTPClientFactory.__init__(
self, url, method=method, postdata=postdata, headers=headers,
agent=agent, timeout=timeout, cookies=cookies,
followRedirect=followRedirect, redirectLimit=redirectLimit,
afterFoundGet = afterFoundGet)
}}}
This code (above) adds a new argument to the __init__ of HTTPDownloader (afterFoundGet) and then also passes it to the unbound __init__ of HTTPClientFactory.
----------
Type : defect
Component: web
Keywords : HTTPClientFactory, HTTPDownloader, afterFoundGet, 302 HTTP Redirect,
Priority : normal
Nosy :
----------
http://twistedmatrix.com/trac/ticket/4364