本文整理汇总了Python中twisted.web.client.HTTPConnectionPool._factory方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPConnectionPool._factory方法的具体用法?Python HTTPConnectionPool._factory怎么用?Python HTTPConnectionPool._factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.client.HTTPConnectionPool
的用法示例。
在下文中一共展示了HTTPConnectionPool._factory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import _factory [as 别名]
def __init__(self, base_url='http://localhost:8888', quiet_requests=True, **kwargs):
self.client_id = str(uuid4())
self.base_url = base_url
pool = HTTPConnectionPool(reactor, persistent=True)
agent = ContentDecoderAgent(RedirectAgent(Agent(reactor, pool=pool)), [('gzip', GzipDecoder)])
if quiet_requests:
pool._factory = QuieterHTTP11ClientFactory
auth_url = kwargs.get('auth_url')
if auth_url:
username = kwargs.get('username')
password = kwargs.get('password')
api_key = kwargs.get('api_key')
if not username:
raise RuntimeError('Marconi "auth_url" specified with no username')
if api_key:
cred = api_key
auth_type = 'api_key'
elif password:
cred = password
auth_type = 'password'
else:
raise RuntimeError('Marconi "auth_url" specified with no "password" or "api_key"')
agent = KeystoneAgent(agent, auth_url, (username, cred), auth_type=auth_type)
self.http_client = HTTPClient(agent)
示例2: __init__
# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import _factory [as 别名]
def __init__(self, reactor, node=('localhost', 4001), ca=None, cert=None):
self.reactor = reactor
self.node = node
self.scheme = 'http'
self.ca = ca
self.cert = cert
context = None
if ca:
self.scheme = 'https'
context = PolicyForHTTPS(ca, cert)
quietPool = HTTPConnectionPool(reactor, persistent = True)
quietPool.maxPersistentPerHost = 2
quietPool._factory = QuietHTTP11ClientFactory
self.agent = Agent(self.reactor, contextFactory=context, pool=quietPool)
示例3: _HTTP11ClientFactoryPatched
# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import _factory [as 别名]
'to finalize request: %s' % self._state)
_requestDeferred.addCallbacks(cbRequestWrotten, ebRequestWriting)
return self._finishedRequest
class _HTTP11ClientFactoryPatched(_HTTP11ClientFactory):
def buildProtocol(self, addr):
proto = HTTP11ClientProtocolPatched(self._quiescentCallback)
proto.timeout = 2 #self.timeout
return proto
pool = HTTPConnectionPool(reactor, True)
pool._factory = _HTTP11ClientFactoryPatched
pool.timeout = 2
agent = Agent(reactor, connectTimeout = 2, pool = pool)
#agent = Agent(reactor)
d = agent.request(
'GET',
'http://192.168.1.141/test1/php/api.php',
Headers({'User-Agent': ['Twisted Web Client Example']}),
None)
#reactor.callLater(2, d.cancel)