当前位置: 首页>>代码示例>>Python>>正文


Python HTTPConnectionPool._factory方法代码示例

本文整理汇总了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)
开发者ID:russellhaering,项目名称:txmarconi,代码行数:32,代码来源:client.py

示例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)
开发者ID:jcollie,项目名称:txetcd,代码行数:18,代码来源:client.py

示例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)

开发者ID:luodaobin,项目名称:scratchbox,代码行数:31,代码来源:test1.py


注:本文中的twisted.web.client.HTTPConnectionPool._factory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。