##class get(http.HTTPClient): ## def handleStatus_301(self): ## ##class GetPageFactory(protocol.ClientFactory): ## """A factory for LogBots. ## ## A new protocol instance will be created each time we connect to the server. ## """ ## ## # the class of the protocol to build when new connection is made ## protocol = get ## ## def __init__(self, url, method='GET', postdata=None, headers=None,agent="Twisted PageGetter", timeout=0, cookies=None,followRedirect=0): ## self.protocol.followRedirect = followRedirect ## self.timeout = timeout ## self.agent = agent ## if cookies is None: ## cookies = {} ## self.cookies = cookies ## if headers is not None: ## self.headers = InsensitiveDict(headers) ## else: ## self.headers = InsensitiveDict() ## if postdata is not None: ## self.headers.setdefault('Content-Length', len(postdata)) ## # just in case a broken http/1.1 decides to keep connection alive ## self.headers.setdefault("connection", "close") ## self.postdata = postdata ## self.method = method ## ## self.setURL(url) ## ## self.waiting = 1 ## self.deferred = defer.Deferred() ## self.response_headers = None ## ## def clientConnectionLost(self, connector, reason): ## """If we get disconnected, reconnect to server.""" ## connector.connect() ## ## def clientConnectionFailed(self, connector, reason): ## print "connection failed:", reason ## reactor.stop()