# Path: txtorcon/util.py
# def default_control_port():
#     """
#     This returns a default control port, which respects an environment
#     variable `TX_CONTROL_PORT`. Without the environment variable, this
#     returns 9151 (the Tor Browser Bundle default).
# 
#     You shouldn't use this in "normal" code, this is a convenience for
#     the examples.
#     """
#     try:
#         return int(os.environ['TX_CONTROL_PORT'])
#     except KeyError:
#         return 9151


from twisted.internet.defer import inlineCallbacks
from twisted.internet.task import react
from twisted.internet.endpoints import TCP4ClientEndpoint
from twisted.web.client import readBody
from txtorcon.util import default_control_port
import txtorcon
# this example shows how to use Twisted's web client with Tor via
# txtorcon

from __future__ import print_function




@react
@inlineCallbacks
def main(reactor):
    # use port 9051 for system tor instances, or:
    # ep = UNIXClientEndpoint(reactor, '/var/run/tor/control')
    # ep = UNIXClientEndpoint(reactor, '/var/run/tor/control')
    ep = TCP4ClientEndpoint(reactor, '127.0.0.1', default_control_port())
    tor = yield txtorcon.connect(reactor, ep)
    print("Connected to {tor} via localhost:{port}".format(
        tor=tor,

# Path: txtorcon/util.py
# def default_control_port():
#     """
#     This returns a default control port, which respects an environment
#     variable `TX_CONTROL_PORT`. Without the environment variable, this
#     returns 9151 (the Tor Browser Bundle default).
# 
#     You shouldn't use this in "normal" code, this is a convenience for
#     the examples.
#     """
#     try:
#         return int(os.environ['TX_CONTROL_PORT'])
#     except KeyError:
#         return 9151


# Path: examples/web_client.py
from twisted.internet.defer import inlineCallbacks
from twisted.internet.task import react
from twisted.internet.endpoints import TCP4ClientEndpoint
from twisted.web.client import readBody
from txtorcon.util import default_control_port
import txtorcon

# this example shows how to use Twisted's web client with Tor via
# txtorcon

from __future__ import print_function




@react
@inlineCallbacks
def main(reactor):
    # use port 9051 for system tor instances, or:
    # ep = UNIXClientEndpoint(reactor, '/var/run/tor/control')
    # ep = UNIXClientEndpoint(reactor, '/var/run/tor/control')
    ep = TCP4ClientEndpoint(reactor, '127.0.0.1', default_control_port())
    tor = yield txtorcon.connect(reactor, ep)
    print("Connected to {tor} via localhost:{port}".format(
        tor=tor,

        port=default_control_port(),