def lineReceived(self, line): print 'received: %r' % line if not line: return app, context, node = (line + ' ').split(' ', 3) context = {'u': 'users', 'g': 'global'}.get(context, context) d = deferToGreenThread(client._get, app, node, globaltree=context == 'global') def callback(result): self.transport.write(str(result)) def errback(error): self.transport.write(error.getTraceback()) d.addCallback(callback) d.addErrback(errback)
def requestReceived(self, lines): request = re.match('^(\w+) http://(.*?)(/.*?) HTTP/1..$', lines[0]) #print request.groups() method, host, path = request.groups() headers = dict(x.split(': ', 1) for x in lines[1:]) def callback(result): self.transport.write(str(result)) self.transport.loseConnection() def errback(err): err.printTraceback() self.transport.loseConnection() d = deferToGreenThread(http_request, method, host, path, headers=headers) d.addCallbacks(callback, errback)
def authenticate(self, proxy): deferred = deferToGreenThread(self._authenticate, proxy) deferred.addCallback(self._auth_finished)