Ticket #413: client.diff
File client.diff, 1.4 KB (added by , 19 years ago) |
---|
-
client.py
old new 28 28 from twisted.web import error 29 29 import urlparse, os, types 30 30 31 from twisted.internet.error import ConnectionDone 32 class PageRedirect(ConnectionDone): 33 """A request resulted in a redirect (followRedirect = 0) """ 34 def __init__(self, status, location): 35 Exception.__init__(self, 36 "%s redirection to: %s" % (status, location)) 37 self.status = status 38 self.location = location 39 31 40 class HTTPPageGetter(http.HTTPClient): 32 41 33 42 quietLoss = 0 34 43 followRedirect = 1 35 44 failed = 0 36 45 37 46 def connectionMade(self): … … 79 88 if not l: 80 89 self.handleStatusDefault() 81 90 url = l[0] 91 if not self.followRedirect: 92 self.handleStatusDefault() 93 self.factory.noPage(PageRedirect(self.status,url)) 94 return 82 95 scheme, host, port, path = _parse(url, defaultPort=self.transport.addr[1]) 83 96 self.factory.setURL(url) 84 97 … … 173 186 path = None 174 187 175 188 def __init__(self, url, method='GET', postdata=None, headers=None, 176 agent="Twisted PageGetter", timeout=0, cookies=None): 189 agent="Twisted PageGetter", timeout=0, cookies=None, 190 followRedirect=1): 191 self.protocol.followRedirect = followRedirect 177 192 self.timeout = timeout 178 193 self.agent = agent 179 194