def socket_proxy(af, socktype, proto): # Create a socket, old school : sock = socket.socket_formal(af, socktype, proto) # Wrap it within a proxy socket return ProxySock(sock, proxy_host, proxy_port)
def socket_proxy(af, socktype, proto) : # Create a socket, old school : sock = socket.socket_formal(af, socktype, proto) # Wrap it within a proxy socket return ProxySock( sock, proxy_host, proxy_port)
def connect(self, address) : # Store the real remote adress (self.host, self.port) = address # Try to connect to the proxy for (family, socktype, proto, canonname, sockaddr) in socket.getaddrinfo( self.proxy_host, self.proxy_port, 0, 0, socket.SOL_TCP) : try: # Replace the socket by a connection to the proxy self.socket = socket.socket_formal(family, socktype, proto) self.socket.connect(sockaddr) except socket.error, msg: if self.socket: self.socket.close() self.socket = None continue break