# Path: txtorcon/socks.py
# def _create_ip_address(host, port):
#     def __init__(self, req_type, host,
#                  port=0,
#                  on_disconnect=None,
#                  on_data=None,
#                  create_connection=None):
#     def when_done(self):
#     def _data_to_send(self, data):
#     def send_data(self, callback):
#     def feed_data(self, data):
#     def _parse_version_reply(self):
#     def _parse_ipv4_reply(self):
#     def _parse_ipv6_reply(self):
#     def _parse_domain_name_reply(self):
#     def _parse_request_reply(self):
#     def _make_connection(self, addr, port):
#     def _domain_name_resolved(self, domain):
#     def connection(self):
#     def disconnected(self, error):
#     def got_data(self):
#     def version_reply(self, auth_method):
#     def version_error(self, error):
#     def reply_error(self, error):
#     def reply_ipv4(self, addr, port):
#     def reply_ipv6(self, addr, port):
#     def reply_domain_name(self, domain):
#     def answer(self):
#     def _send_version(self):
#     def _disconnect(self, error):
#     def _send_request(self, auth_method):
#     def _relay_data(self):
#     def _send_connect_request(self):
#     def _send_resolve_request(self):
#     def _send_resolve_ptr_request(self):
#     def unconnected(self):
#     def sent_version(self):
#     def sent_request(self):
#     def relaying(self):
#     def abort(self, error_message):
#     def done(self):
#     def __init__(self, host, port, socks_method, factory):
#     def when_done(self):
#     def connectionMade(self):
#     def connectionLost(self, reason):
#     def dataReceived(self, data):
#     def _on_data(self, data):
#     def _create_connection(self, addr, port):
#     def _on_disconnect(self, error_message):
#     def __init__(self, *args, **kw):
#     def _get_address(self):
#     def _did_connect(self, host):
#     def buildProtocol(self, addr):
#     def __init__(self, message='', code=None):
# def _create_socks_error(code):
# def resolve(tor_endpoint, hostname):
# def resolve_ptr(tor_endpoint, ip):
#     def __init__(self, socks_endpoint, host, port, tls=False):
#     def _get_address(self):
#     def connect(self, factory):
# class _SocksMachine(object):
# class _TorSocksProtocol(Protocol):
# class _TorSocksFactory(Factory):
# class SocksError(Exception):
# class GeneralServerFailureError(SocksError):
# class ConnectionNotAllowedError(SocksError):
# class NetworkUnreachableError(SocksError):
# class HostUnreachableError(SocksError):
# class ConnectionRefusedError(SocksError):
# class TtlExpiredError(SocksError):
# class CommandNotSupportedError(SocksError):
# class AddressTypeNotSupportedError(SocksError):
# class TorSocksEndpoint(object):
#     SUCCEEDED = 0x00
#     REPLY_IPV4 = 0x01
#     REPLY_HOST = 0x03
#     REPLY_IPV6 = 0x04


from six import BytesIO, text_type
from mock import Mock, patch
from twisted.trial import unittest
from twisted.internet import defer
from twisted.internet.address import IPv4Address
from twisted.internet.protocol import Protocol
from twisted.internet.interfaces import IStreamClientEndpoint
from twisted.test import proto_helpers
from twisted.test.iosim import connect, FakeTransport
from zope.interface import directlyProvides
from txtorcon import socks
        from OpenSSL import SSL
    @patch('txtorcon.socks._TorSocksFactory')
    def test_resolve_ptr_bytes(self, fac):
        socks_ep = Mock()
        d = socks.resolve_ptr(socks_ep, b'meejah.ca')
        self.assertEqual(1, len(fac.mock_calls))
        self.assertTrue(
            isinstance(fac.mock_calls[0][1][0], text_type)
        )
        return d

    @patch('txtorcon.socks._TorSocksFactory')
    def test_resolve_bytes(self, fac):
        socks_ep = Mock()
        d = socks.resolve(socks_ep, b'meejah.ca')
        self.assertEqual(1, len(fac.mock_calls))
        self.assertTrue(
            isinstance(fac.mock_calls[0][1][0], text_type)
        )
        return d


class SocksErrorTests(unittest.TestCase):
    def _check_error(self, error, cls_, code, message):
        self.assertTrue(isinstance(error, cls_))
        self.assertEqual(error.code, code)
        self.assertEqual(error.message, message)
        self.assertEqual(str(error), message)

    def test_error_factory(self):
        for cls in socks.SocksError.__subclasses__():

# Path: txtorcon/socks.py
# def _create_ip_address(host, port):
#     def __init__(self, req_type, host,
#                  port=0,
#                  on_disconnect=None,
#                  on_data=None,
#                  create_connection=None):
#     def when_done(self):
#     def _data_to_send(self, data):
#     def send_data(self, callback):
#     def feed_data(self, data):
#     def _parse_version_reply(self):
#     def _parse_ipv4_reply(self):
#     def _parse_ipv6_reply(self):
#     def _parse_domain_name_reply(self):
#     def _parse_request_reply(self):
#     def _make_connection(self, addr, port):
#     def _domain_name_resolved(self, domain):
#     def connection(self):
#     def disconnected(self, error):
#     def got_data(self):
#     def version_reply(self, auth_method):
#     def version_error(self, error):
#     def reply_error(self, error):
#     def reply_ipv4(self, addr, port):
#     def reply_ipv6(self, addr, port):
#     def reply_domain_name(self, domain):
#     def answer(self):
#     def _send_version(self):
#     def _disconnect(self, error):
#     def _send_request(self, auth_method):
#     def _relay_data(self):
#     def _send_connect_request(self):
#     def _send_resolve_request(self):
#     def _send_resolve_ptr_request(self):
#     def unconnected(self):
#     def sent_version(self):
#     def sent_request(self):
#     def relaying(self):
#     def abort(self, error_message):
#     def done(self):
#     def __init__(self, host, port, socks_method, factory):
#     def when_done(self):
#     def connectionMade(self):
#     def connectionLost(self, reason):
#     def dataReceived(self, data):
#     def _on_data(self, data):
#     def _create_connection(self, addr, port):
#     def _on_disconnect(self, error_message):
#     def __init__(self, *args, **kw):
#     def _get_address(self):
#     def _did_connect(self, host):
#     def buildProtocol(self, addr):
#     def __init__(self, message='', code=None):
# def _create_socks_error(code):
# def resolve(tor_endpoint, hostname):
# def resolve_ptr(tor_endpoint, ip):
#     def __init__(self, socks_endpoint, host, port, tls=False):
#     def _get_address(self):
#     def connect(self, factory):
# class _SocksMachine(object):
# class _TorSocksProtocol(Protocol):
# class _TorSocksFactory(Factory):
# class SocksError(Exception):
# class GeneralServerFailureError(SocksError):
# class ConnectionNotAllowedError(SocksError):
# class NetworkUnreachableError(SocksError):
# class HostUnreachableError(SocksError):
# class ConnectionRefusedError(SocksError):
# class TtlExpiredError(SocksError):
# class CommandNotSupportedError(SocksError):
# class AddressTypeNotSupportedError(SocksError):
# class TorSocksEndpoint(object):
#     SUCCEEDED = 0x00
#     REPLY_IPV4 = 0x01
#     REPLY_HOST = 0x03
#     REPLY_IPV6 = 0x04


# Path: test/test_socks.py
from six import BytesIO, text_type
from mock import Mock, patch
from twisted.trial import unittest
from twisted.internet import defer
from twisted.internet.address import IPv4Address
from twisted.internet.protocol import Protocol
from twisted.internet.interfaces import IStreamClientEndpoint
from twisted.test import proto_helpers
from twisted.test.iosim import connect, FakeTransport
from zope.interface import directlyProvides
from txtorcon import socks
        from OpenSSL import SSL

    @patch('txtorcon.socks._TorSocksFactory')
    def test_resolve_ptr_bytes(self, fac):
        socks_ep = Mock()
        d = socks.resolve_ptr(socks_ep, b'meejah.ca')
        self.assertEqual(1, len(fac.mock_calls))
        self.assertTrue(
            isinstance(fac.mock_calls[0][1][0], text_type)
        )
        return d

    @patch('txtorcon.socks._TorSocksFactory')
    def test_resolve_bytes(self, fac):
        socks_ep = Mock()
        d = socks.resolve(socks_ep, b'meejah.ca')
        self.assertEqual(1, len(fac.mock_calls))
        self.assertTrue(
            isinstance(fac.mock_calls[0][1][0], text_type)
        )
        return d


class SocksErrorTests(unittest.TestCase):
    def _check_error(self, error, cls_, code, message):
        self.assertTrue(isinstance(error, cls_))
        self.assertEqual(error.code, code)
        self.assertEqual(error.message, message)
        self.assertEqual(str(error), message)

    def test_error_factory(self):
        for cls in socks.SocksError.__subclasses__():

            error = socks._create_socks_error(cls.code)