Ticket #413: client.diff

File client.diff, 1.4 KB (added by cce, 19 years ago)
  • client.py

    old new  
    2828from twisted.web import error
    2929import urlparse, os, types
    3030
     31from twisted.internet.error import ConnectionDone
     32class 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
    3140class HTTPPageGetter(http.HTTPClient):
    3241
    3342    quietLoss = 0
    34    
     43    followRedirect = 1
    3544    failed = 0
    3645
    3746    def connectionMade(self):
     
    7988        if not l:
    8089            self.handleStatusDefault()
    8190        url = l[0]
     91        if not self.followRedirect:
     92            self.handleStatusDefault()
     93            self.factory.noPage(PageRedirect(self.status,url))
     94            return
    8295        scheme, host, port, path = _parse(url, defaultPort=self.transport.addr[1])
    8396        self.factory.setURL(url)
    8497
     
    173186    path = None
    174187
    175188    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
    177192        self.timeout = timeout
    178193        self.agent = agent
    179194