def build_agent(self, proxy, headers): """Build an agent for this request """ fragments = common.parse_proxy(proxy) pool = self.build_pool() if fragments.host: # add proxy authentication header auth = base64.b64encode("%s:%s" % (fragments.username, fragments.password)) headers['Proxy-Authorization'] = ["Basic " + auth.strip()] # generate the agent endpoint = endpoints.TCP4ClientEndpoint( reactor, fragments.host, int(fragments.port), timeout=self.settings.timeout) agent = client.ProxyAgent(endpoint, reactor=reactor, pool=pool) else: agent = client.Agent(reactor, connectTimeout=self.settings.timeout, pool=pool) agent = client.ContentDecoderAgent(agent, [('gzip', client.GzipDecoder)]) # XXX if use same cookie for all then works... # cookies usually empty if proxy in self.cookiejars: cj = self.cookiejars[proxy] else: cj = cookielib.CookieJar() self.cookiejars[proxy] = cj agent = client.CookieAgent(agent, cj) return agent
def __init__(self, *args, **kwargs): self.proxy_username = None if "proxy_host" in kwargs: port = 80 if "proxy_port" in kwargs: port = kwargs["proxy_port"] del kwargs["proxy_port"] if "proxy_username" in kwargs: self.proxy_username = kwargs["proxy_username"] del kwargs["proxy_username"] if "proxy_password" in kwargs: self.proxy_password = kwargs["proxy_password"] del kwargs["proxy_password"] endpoint = endpoints.TCP4ClientEndpoint(reactor, kwargs["proxy_host"], port) self.agent = client.ProxyAgent(endpoint) del kwargs["proxy_host"] else: from twisted.web import version as twisted_version if twisted_version.major < 14: # FIXME: for Ubuntu 12.04 Twisted 11? (until 2017/04) self.agent = client.Agent(reactor) else: contextFactory = WebClientContextFactory() self.agent = client.Agent(reactor, contextFactory) Twitter.__init__(self, *args, **kwargs)
def make_client(listening_port): addr = listening_port.getHost() self.agent = client.ProxyAgent( endpoints.TCP4ClientEndpoint( self.reactor, addr.host, addr.port, ), self.reactor, )
def __init__(self, *args, **kwargs): self.proxy_username = None if "proxy_host" in kwargs: port = 80 if "proxy_port" in kwargs: port = kwargs["proxy_port"] del kwargs["proxy_port"] if "proxy_username" in kwargs: self.proxy_username = kwargs["proxy_username"] del kwargs["proxy_username"] if "proxy_password" in kwargs: self.proxy_password = kwargs["proxy_password"] del kwargs["proxy_password"] endpoint = endpoints.TCP4ClientEndpoint(reactor, kwargs["proxy_host"], port) self.agent = client.ProxyAgent(endpoint) del kwargs["proxy_host"] else: self.agent = client.Agent(reactor) Twitter.__init__(self, *args, **kwargs)