'Connects to the specified destination through a proxy.
Uses the same API as socket\'s connect().
To select the proxy server, use set_proxy().
dest_pair - 2-tuple of (IP/hostname, port).'

def connect(self, dest_pair):

    if ((len(dest_pair) != 2) or dest_pair[0].startswith('[')):
        raise socket.error("PySocks    doesn't    support    IPv6")
    (dest_addr, dest_port) = dest_pair
    if (self.type == socket.SOCK_DGRAM):
        if (not self._proxyconn):
            self.bind(('', 0))
        dest_addr = socket.gethostbyname(dest_addr)
        if ((dest_addr == '0.0.0.0') and (not dest_port)):
            self.proxy_peername = None
        else:
            self.proxy_peername = (dest_addr, dest_port)
        return
    (proxy_type, proxy_addr, proxy_port, rdns, username, password) = self.proxy
    if ((not isinstance(dest_pair, (list, tuple))) or (len(dest_pair) != 2) or (not dest_addr) or (not isinstance(dest_port, int))):
        raise GeneralProxyError('Invalid    destination-connection    (host,    port)    pair')
    if (proxy_type is None):
        self.proxy_peername = dest_pair
        _BaseSocket.connect(self, (dest_addr, dest_port))
        return
    proxy_addr = self._proxy_addr()
    try:
        _BaseSocket.connect(self, proxy_addr)
    except socket.error as error:
        self.close()
        (proxy_addr, proxy_port) = proxy_addr
        proxy_server = '{0}:{1}'.format(proxy_addr, proxy_port)
        printable_type = PRINTABLE_PROXY_TYPES[proxy_type]
        msg = 'Error    connecting    to    {0}    proxy    {1}'.format(printable_type, proxy_server)
        raise ProxyConnectionError(msg, error)
    else:
        try:
            negotiate = self._proxy_negotiators[proxy_type]
            negotiate(self, dest_addr, dest_port)
        except socket.error as error:
            self.close()
            raise GeneralProxyError('Socket    error', error)
        except ProxyError:
            self.close()
            raise
