# Path: txtorcon/util.py
# def create_tbb_web_headers():
# def version_at_least(version_string, major, minor, micro, patch):
# def create_geoip(fname):
# def maybe_create_db(path):
# def is_executable(path):
# def find_tor_binary(globs=('/usr/sbin/', '/usr/bin/',
#                            '/Applications/TorBrowser_*.app/Contents/MacOS/'),
#                     system_tor=True):
# def maybe_ip_addr(addr):
# def find_keywords(args, key_filter=lambda x: not x.startswith("$")):
# def delete_file_or_tree(*args):
# def process_from_address(addr, port, torstate=None):
# def hmac_sha256(key, msg):
# def compare_via_hash(x, y):
#     def __init__(self, ipaddr):
#     def noop(self, *args, **kw):
# def available_tcp_port(reactor):
# def unescape_quoted_string(string):
# def default_control_port():
#     def add(callback):
#     def remove(callback):
#     def notify(*args, **kw):
# def maybe_coroutine(obj):
#     def __init__(self):
#     def add(self, callback):
#     def remove(self, callback):
#     def notify(self, *args, **kw):
#         def failed(fail):
#     def __init__(self, valid_events):
#     def __call__(self, event, callback):
#     def remove(self, event, callback):
#     def notify(self, event, *args, **kw):
#     def __init__(self):
#     def when_fired(self):
#     def fire(self, value):
#     def __init__(self, package, major, minor, patch):
#     def short(self):
# def _is_non_public_numeric_address(host):
# CRYPTOVARIABLE_EQUALITY_COMPARISON_NONCE = os.urandom(32)
# class NetLocation(object):
# class NoOpProtocolFactory:
# class IListener(Interface):
# class _Listener(object):
# class _ListenerCollection(object):
# class SingleObserver(object):
# class _Version(object):


import six
import struct
import ipaddress
import automat
from socket import inet_pton, inet_ntoa, inet_aton, AF_INET6, AF_INET
from twisted.internet.defer import inlineCallbacks, returnValue, Deferred
from twisted.internet.protocol import Protocol, Factory
from twisted.internet.address import IPv4Address, IPv6Address, HostnameAddress
from twisted.python.failure import Failure
from twisted.protocols import portforward
from twisted.protocols import tls
from twisted.internet.interfaces import IStreamClientEndpoint
from zope.interface import implementer
from txtorcon import util
            from twisted.internet.ssl import optionsForClientTLS

    def _on_data(self, data):
        self.transport.write(data)

    def _create_connection(self, addr, port):
        addr = IPv4Address('TCP', addr, port)
        sender = self._factory.buildProtocol(addr)
        client_proxy = portforward.ProxyClient()
        sender.makeConnection(self.transport)
        # portforward.ProxyClient is going to call setPeer but this
        # probably doesn't have it...
        setattr(sender, 'setPeer', lambda _: None)
        client_proxy.setPeer(sender)
        self._sender = sender
        return sender

    def _on_disconnect(self, error_message):
        self.transport.loseConnection()
        # self.transport.abortConnection()#SocksError(error_message)) ?


class _TorSocksFactory(Factory):
    protocol = _TorSocksProtocol

    # XXX should do validation on this stuff so we get errors before
    # building the protocol
    def __init__(self, *args, **kw):
        self._args = args
        self._kw = kw
        self._host = None

# Path: txtorcon/util.py
# def create_tbb_web_headers():
# def version_at_least(version_string, major, minor, micro, patch):
# def create_geoip(fname):
# def maybe_create_db(path):
# def is_executable(path):
# def find_tor_binary(globs=('/usr/sbin/', '/usr/bin/',
#                            '/Applications/TorBrowser_*.app/Contents/MacOS/'),
#                     system_tor=True):
# def maybe_ip_addr(addr):
# def find_keywords(args, key_filter=lambda x: not x.startswith("$")):
# def delete_file_or_tree(*args):
# def process_from_address(addr, port, torstate=None):
# def hmac_sha256(key, msg):
# def compare_via_hash(x, y):
#     def __init__(self, ipaddr):
#     def noop(self, *args, **kw):
# def available_tcp_port(reactor):
# def unescape_quoted_string(string):
# def default_control_port():
#     def add(callback):
#     def remove(callback):
#     def notify(*args, **kw):
# def maybe_coroutine(obj):
#     def __init__(self):
#     def add(self, callback):
#     def remove(self, callback):
#     def notify(self, *args, **kw):
#         def failed(fail):
#     def __init__(self, valid_events):
#     def __call__(self, event, callback):
#     def remove(self, event, callback):
#     def notify(self, event, *args, **kw):
#     def __init__(self):
#     def when_fired(self):
#     def fire(self, value):
#     def __init__(self, package, major, minor, patch):
#     def short(self):
# def _is_non_public_numeric_address(host):
# CRYPTOVARIABLE_EQUALITY_COMPARISON_NONCE = os.urandom(32)
# class NetLocation(object):
# class NoOpProtocolFactory:
# class IListener(Interface):
# class _Listener(object):
# class _ListenerCollection(object):
# class SingleObserver(object):
# class _Version(object):


# Path: txtorcon/socks.py
import six
import struct
import ipaddress
import automat
from socket import inet_pton, inet_ntoa, inet_aton, AF_INET6, AF_INET
from twisted.internet.defer import inlineCallbacks, returnValue, Deferred
from twisted.internet.protocol import Protocol, Factory
from twisted.internet.address import IPv4Address, IPv6Address, HostnameAddress
from twisted.python.failure import Failure
from twisted.protocols import portforward
from twisted.protocols import tls
from twisted.internet.interfaces import IStreamClientEndpoint
from zope.interface import implementer
from txtorcon import util
            from twisted.internet.ssl import optionsForClientTLS


    def _on_data(self, data):
        self.transport.write(data)

    def _create_connection(self, addr, port):
        addr = IPv4Address('TCP', addr, port)
        sender = self._factory.buildProtocol(addr)
        client_proxy = portforward.ProxyClient()
        sender.makeConnection(self.transport)
        # portforward.ProxyClient is going to call setPeer but this
        # probably doesn't have it...
        setattr(sender, 'setPeer', lambda _: None)
        client_proxy.setPeer(sender)
        self._sender = sender
        return sender

    def _on_disconnect(self, error_message):
        self.transport.loseConnection()
        # self.transport.abortConnection()#SocksError(error_message)) ?


class _TorSocksFactory(Factory):
    protocol = _TorSocksProtocol

    # XXX should do validation on this stuff so we get errors before
    # building the protocol
    def __init__(self, *args, **kw):
        self._args = args
        self._kw = kw
        self._host = None

        self._when_connected = util.SingleObserver()