def _negotiatesocks5_gen(self): from struct import pack, unpack from util import Storage destaddr, destport = self.end uname, password = self._proxyinfo.get('username', ''), self._proxyinfo.get('password', '') this = Storage() this.errors = False this.authtype = 0 this.incoming_host_type = 0 def pstring(s): return chr(len(s)) + s def single_use_handler(f): @wraps(f) def wrapper(data): self.pop_handler() return f(data) return wrapper def if_errors_close(f): def wrapper(*a, **k): ok = not this.errors if ok: try: return f(*a, **k) except Exception, e: import traceback; traceback.print_exc() log.info('ProxySocket._negotiatesocks5: there was an error calling %r(*%r, **%r). the exception was: %r', f, a, k, e) this.errors = True self.close() return '',None else: