How to use the treq._utils.default_pool function in treq

To help you get started, we’ve selected a few treq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github modera / mcloud / mcloud / txhttp.py View on Github external
def _client(*args, **kwargs):
    reactor = default_reactor(kwargs.get('reactor'))
    pool = default_pool(reactor,
                        kwargs.get('pool'),
                        persistent=False)
                        #kwargs.get('persistent'))
    agent = UNIXAwareHttpAgent(reactor, pool=pool, **kwargs)
    return UNIXAwareHttpClient(agent)
github twisted / treq / src / treq / api.py View on Github external
def _client(*args, **kwargs):
    agent = kwargs.get('agent')
    if agent is None:
        reactor = default_reactor(kwargs.get('reactor'))
        pool = default_pool(reactor,
                            kwargs.get('pool'),
                            kwargs.get('persistent'))
        agent = Agent(reactor, pool=pool)
    return HTTPClient(agent)
github praekeltfoundation / vumi / vumi / utils.py View on Github external
def http_request_full(url, data=None, headers={}, method='POST',
                      timeout=None, data_limit=None, context_factory=None,
                      agent_class=None, reactor=None):
    """
    This is a drop in replacement for the original `http_request_full` method
    but it has its internals completely replaced by treq. Treq supports SNI
    and our implementation does not for some reason. Also, we do not want
    to continue maintaining this because we're favouring treq everywhere
    anyway.

    """
    agent_class = agent_class or Agent
    if reactor is None:
        # The import replaces the local variable.
        from twisted.internet import reactor
    pool = default_pool(reactor, pool=None, persistent=False)
    context_factory = context_factory or WebClientContextFactory()
    agent = agent_class(reactor, pool=pool, contextFactory=context_factory)
    client = HTTPClient(agent)

    def handle_response(response):
        return SimplishReceiver(response, data_limit).deferred

    d = client.request(method, url, headers=headers, data=data)
    d.addCallback(handle_response)

    if timeout is not None:
        cancelling_on_timeout = [False]

        def raise_timeout(reason):
            if not cancelling_on_timeout[0] or reason.check(HttpTimeoutError):
                return reason