twisted之http.client Agent

Posted on 2020-04-11 20:44  王将军之武库  阅读(410)  评论(0编辑  收藏  举报
@implementer(IAgent)
class Agent(_AgentBase):
    def __init__(self, reactor,
                 contextFactory=BrowserLikePolicyForHTTPS(),
                 connectTimeout=None, bindAddress=None,
                 pool=None):
        if not IPolicyForHTTPS.providedBy(contextFactory):
            warnings.warn(
                repr(contextFactory) +
                " was passed as the HTTPS policy for an Agent, but it does "
                "not provide IPolicyForHTTPS.  Since Twisted 14.0, you must "
                "pass a provider of IPolicyForHTTPS.",
                stacklevel=2, category=DeprecationWarning
            )
            contextFactory = _DeprecatedToCurrentPolicyForHTTPS(contextFactory)
        endpointFactory = _StandardEndpointFactory(
            reactor, contextFactory, connectTimeout, bindAddress)
        self._init(reactor, endpointFactory, pool)
    """
        _AgentBase.__init__(self, reactor, pool)
        self._endpointFactory = endpointFactory

@implementer(IAgentEndpointFactory)
class _StandardEndpointFactory(object):

@implementer(interfaces.IStreamClientEndpoint)
class HostnameEndpoint(object):

def resolvedAddressesToEndpoints(addresses):
            # Yield an endpoint for every address resolved from the name.
            for eachAddress in addresses:
                if isinstance(eachAddress, IPv6Address):
                    yield TCP6ClientEndpoint(
                        self._reactor, eachAddress.host, eachAddress.port,
                        self._timeout, self._bindAddress
                    )
                if isinstance(eachAddress, IPv4Address):
                    yield TCP4ClientEndpoint(
                        self._reactor, eachAddress.host, eachAddress.port,
                        self._timeout, self._bindAddress

 

 agent相当于浏览器,agent的request方法通过完成一个请求。request会先dns,得到地址后生成tcp4clientendpoint(reactor.connectTCP())

Copyright © 2024 王将军之武库
Powered by .NET 9.0 on Kubernetes