(reactor, torconfig, socks_config, pool=None)
This returns a Deferred that fires with an object that implements
    :class:`twisted.web.iweb.IAgent` and is thus suitable for passing
    to ``treq`` as the ``agent=`` kwarg. Of course can be used
    directly; see `using Twisted web cliet
    <http://twistedmatrix.com/documents/current/web/howto/client.html>`_. If
    you have a :class:`txtorcon.Tor` instance already, the preferred
    API is to call :meth:`txtorcon.Tor.web_agent` on it.

    :param torconfig: a :class:`txtorcon.TorConfig` instance.

    :param socks_config: anything valid for Tor's ``SocksPort``
        option. This is generally just a TCP port (e.g. ``9050``), but
        can also be a unix path like so ``unix:/path/to/socket`` (Tor
        has restrictions on the ownership/permissions of the directory
        containing ``socket``). If the given SOCKS option is not
        already available in the underlying Tor instance, it is
        re-configured to add the SOCKS option.
This returns a Deferred that fires with an object that implements
    :class:`twisted.web.iweb.IAgent` and is thus suitable for passing
    to ``treq`` as the ``agent=`` kwarg. Of course can be used
    directly; see `using Twisted web cliet
    <http://twistedmatrix.com/documents/current/web/howto/client.html>`_. If
    you have a :class:`txtorcon.Tor` instance already, the preferred
    API is to call :meth:`txtorcon.Tor.web_agent` on it.
This returns a Deferred that fires with an object that implements : class : twisted . web . iweb . IAgent and is thus suitable for passing to treq as the agent = kwarg . Of course can be used directly ; see using Twisted web cliet <http : // twistedmatrix . com / documents / current / web / howto / client . html > _ . If you have a : class : txtorcon . Tor instance already the preferred API is to call : meth : txtorcon . Tor . web_agent on it .
def agent_for_socks_port(reactor, torconfig, socks_config, pool=None):
    """
    This returns a Deferred that fires with an object that implements
    :class:`twisted.web.iweb.IAgent` and is thus suitable for passing
    to ``treq`` as the ``agent=`` kwarg. Of course can be used
    directly; see `using Twisted web cliet
    <http://twistedmatrix.com/documents/current/web/howto/client.html>`_. If
    you have a :class:`txtorcon.Tor` instance already, the preferred
    API is to call :meth:`txtorcon.Tor.web_agent` on it.

    :param torconfig: a :class:`txtorcon.TorConfig` instance.

    :param socks_config: anything valid for Tor's ``SocksPort``
        option. This is generally just a TCP port (e.g. ``9050``), but
        can also be a unix path like so ``unix:/path/to/socket`` (Tor
        has restrictions on the ownership/permissions of the directory
        containing ``socket``). If the given SOCKS option is not
        already available in the underlying Tor instance, it is
        re-configured to add the SOCKS option.
    """
    # :param tls: True (the default) will use Twisted's default options
    #     with the hostname in the URI -- that is, TLS verification
    #     similar to a Browser. Otherwise, you can pass whatever Twisted
    #     returns for `optionsForClientTLS
    #     <https://twistedmatrix.com/documents/current/api/twisted.internet.ssl.optionsForClientTLS.html>`_

    socks_config = str(socks_config)  # sadly, all lists are lists-of-strings to Tor :/
    if socks_config not in torconfig.SocksPort:
        txtorlog.msg("Adding SOCKS port '{}' to Tor".format(socks_config))
        torconfig.SocksPort.append(socks_config)
        try:
            yield torconfig.save()
        except Exception as e:
            raise RuntimeError(
                "Failed to reconfigure Tor with SOCKS port '{}': {}".format(
                    socks_config, str(e)
                )
            )

    if socks_config.startswith('unix:'):
        socks_ep = UNIXClientEndpoint(reactor, socks_config[5:])
    else:
        if ':' in socks_config:
            host, port = socks_config.split(':', 1)
        else:
            host = '127.0.0.1'
            port = int(socks_config)
        socks_ep = TCP4ClientEndpoint(reactor, host, port)

    returnValue(
        Agent.usingEndpointFactory(
            reactor,
            _AgentEndpointFactoryUsingTor(reactor, socks_ep),
            pool=pool,
        )
    )
def agent_for_socks_port ( reactor , torconfig , socks_config , pool = None ) : # :param tls: True (the default) will use Twisted's default options #     with the hostname in the URI -- that is, TLS verification #     similar to a Browser. Otherwise, you can pass whatever Twisted #     returns for `optionsForClientTLS #     <https://twistedmatrix.com/documents/current/api/twisted.internet.ssl.optionsForClientTLS.html>`_ socks_config = str ( socks_config ) # sadly, all lists are lists-of-strings to Tor :/ if socks_config not in torconfig . SocksPort : txtorlog . msg ( "Adding SOCKS port '{}' to Tor" . format ( socks_config ) ) torconfig . SocksPort . append ( socks_config ) try : yield torconfig . save ( ) except Exception as e : raise RuntimeError ( "Failed to reconfigure Tor with SOCKS port '{}': {}" . format ( socks_config , str ( e ) ) ) if socks_config . startswith ( 'unix:' ) : socks_ep = UNIXClientEndpoint ( reactor , socks_config [ 5 : ] ) else : if ':' in socks_config : host , port = socks_config . split ( ':' , 1 ) else : host = '127.0.0.1' port = int ( socks_config ) socks_ep = TCP4ClientEndpoint ( reactor , host , port ) returnValue ( Agent . usingEndpointFactory ( reactor , _AgentEndpointFactoryUsingTor ( reactor , socks_ep ) , pool = pool , ) )