twisted之http.client Agent

@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

 

 The agent is equivalent to a browser, and the request method of the agent completes a request. The request will first dns, generate tcp4clientendpoint (reactor.connectTCP ())

Guess you like

Origin www.cnblogs.com/pyhai/p/12682108.html