bugged
stringlengths 4
228k
| fixed
stringlengths 0
96.3M
| __index_level_0__
int64 0
481k
|
|---|---|---|
def getJobs(self, selector): predefined = { 'TODO': 'SUBMITTED,WAITING,READY,QUEUED', 'ALL': 'SUBMITTED,WAITING,READY,QUEUED,RUNNING', 'COMPLETE': str.join(',', Job.states)} jobFilter = predefined.get(selector.upper(), selector.upper())
|
def getJobs(self, selector): predefined = { 'TODO': 'SUBMITTED,WAITING,READY,QUEUED', 'ALL': str.join(',', Job.states)} jobFilter = predefined.get(selector.upper(), selector.upper())
| 476,500
|
def siteFilter(jobObj): dest = jobObj.get("dest") if not dest: return False dest = str.join("/", map(lambda x: x.split(":")[0], dest.upper().split("/"))) for site in jobFilter.split(','): regex = re.compile(site) if regex.search(dest) and jobObj.state not in (Job.SUCCESS, Job.FAILED): return True return False
|
def siteFilter(jobObj): dest = jobObj.get("dest") if not dest: return False dest = str.join("/", map(lambda x: x.split(":")[0], dest.upper().split("/"))) for site in jobFilter.split(','): if re.compile(site).search(dest): return True return False
| 476,501
|
def unique(seq): set = {} map(set.__setitem__, seq, []) return set.keys()
|
def unique(seq): set = {} map(set.__setitem__, seq, []) return set.keys()
| 476,502
|
def interrupt(sig, frame): global opts, log, handler opts.abort = True log = utils.ActivityLog('Quitting grid-control! (This can take a few seconds...)') signal.signal(signal.SIGINT, handler)
|
def interrupt(sig, frame): global opts, log, handler opts.abort = True log = utils.ActivityLog('Quitting grid-control! (This can take a few seconds...)') signal.signal(signal.SIGINT, handler)
| 476,503
|
def getMissing(self, nJobs): self.nJobs = nJobs if len(self._jobs) < nJobs: return filter(lambda x: x not in self._jobs, range(nJobs)) return []
|
def extendJobDB(self, nJobs): self.nJobs = nJobs if len(self._jobs) < nJobs: return filter(lambda x: x not in self._jobs, range(nJobs)) return []
| 476,504
|
def selectByID(jobNum, jobObj, arg): try: return jobNum in map(int, arg.split(",")) except: raise UserError('Job identifiers must be integers.')
|
def selectByID(jobNum, jobObj, arg): try: def checkID(idArg): (start, end) = (idArg.split('-')[0], idArg.split('-')[-1]) if (start == '') or jobNum >= int(start): if (end == '') or jobNum <= int(end): return True return False return reduce(operator.or_, map(checkID, arg.split(","))) except: raise UserError('Job identifiers must be integers.')
| 476,505
|
def selectByID(jobNum, jobObj, arg): try: return jobNum in map(int, arg.split(",")) except: raise UserError('Job identifiers must be integers.')
|
def selectByID(jobNum, jobObj, arg): try: return jobNum in map(int, arg.split(",")) except: raise UserError('Job identifiers must be integers.')
| 476,506
|
def selectSpecific(specific): selectorType = QM(sepcific.isdigit(), 'id', 'state') if ':' in specific: selectorType = specific.split(':', 1)[0].lower() return selectorMap[selectorType](jobNum, jobObj, specific.split(':', 1)[-1])
|
def selectSpecific(specific): cmpValue = QM(specific[0] == '~', False, True) specific = specific.lstrip('~') selectorType = QM(specific[0].isdigit(), 'id', 'state') if ':' in specific: selectorType = specific.split(':', 1)[0].lower() return selectorMap[selectorType](jobNum, jobObj, specific.split(':', 1)[-1])
| 476,507
|
def selectSpecific(specific): selectorType = QM(sepcific.isdigit(), 'id', 'state') if ':' in specific: selectorType = specific.split(':', 1)[0].lower() return selectorMap[selectorType](jobNum, jobObj, specific.split(':', 1)[-1])
|
def selectSpecific(specific): selectorType = QM(sepcific.isdigit(), 'id', 'state') if ':' in specific: selectorType = specific.split(':', 1)[0].lower() return selectorMap[selectorType](jobNum, jobObj, specific.split(':', 1)[-1])
| 476,508
|
def __init__(self, config, module, monitor): (self.module, self.monitor) = (module, monitor) self.errorDict = module.errorDict self._dbPath = os.path.join(config.workDir, 'jobs') self.disableLog = os.path.join(config.workDir, 'disabled') try: if not os.path.exists(self._dbPath): if config.opts.init: os.mkdir(self._dbPath) else: raise ConfigError("Not a properly initialized work directory '%s'." % config.workDir) except IOError: raise RethrowError("Problem creating work directory '%s'" % self._dbPath)
|
def __init__(self, config, module, monitor): (self.module, self.monitor) = (module, monitor) self.errorDict = module.errorDict self._dbPath = os.path.join(config.workDir, 'jobs') self.disableLog = os.path.join(config.workDir, 'disabled') try: if not os.path.exists(self._dbPath): if config.opts.init: os.mkdir(self._dbPath) else: raise ConfigError("Not a properly initialized work directory '%s'." % config.workDir) except IOError: raise RethrowError("Problem creating work directory '%s'" % self._dbPath)
| 476,509
|
def resetState(jobs, newState): jobSet = utils.set(jobs) for jobNum in jobs: jobObj = self.jobDB.get(jobNum) if jobObj.state in [ Job.INIT, Job.DISABLED, Job.ABORTED, Job.CANCELLED, Job.DONE, Job.FAILED, Job.SUCCESS ]: self._update(jobObj, jobNum, newState) jobSet.remove(jobNum) jobObj.attempt = 0 if len(jobSet) > 0: output = (Job.states[newState], str.join(', ', map(str, jobSet))) raise RuntimeError('For the following jobs it was not possible to reset the state to %s:\n%s' % output)
|
def resetState(jobs, newState): jobSet = utils.set(jobs) for jobNum in jobs: jobObj = self.jobDB.get(jobNum) if jobObj.state in [ Job.INIT, Job.DISABLED, Job.ABORTED, Job.CANCELLED, Job.DONE, Job.FAILED, Job.SUCCESS ]: self._update(jobObj, jobNum, newState) jobSet.remove(jobNum) jobObj.attempt = 0 if len(jobSet) > 0: output = (Job.states[newState], str.join(', ', map(str, jobSet))) raise RuntimeError('For the following jobs it was not possible to reset the state to %s:\n%s' % output)
| 476,510
|
def getSubmitArguments(self, jobNum, sandbox, stdout, stderr, addAttr): reqMap = { WMS.MEMORY: ("pvmem", lambda m: "%dmb" % m) } params = PBSGE.getSubmitArguments(self, jobNum, sandbox, stdout, stderr, addAttr, reqMap) # Job requirements reqs = dict(self.wms.getRequirements(jobNum)) if reqs.get(WMS.SITES, (None, None))[1]: params += ' -l host=%s' % str.join("+", reqs[WMS.SITES][1]) return params
|
def getSubmitArguments(self, jobNum, sandbox, stdout, stderr, addAttr): reqMap = { WMS.MEMORY: ("pvmem", lambda m: "%dmb" % m) } params = PBSGECommon.getSubmitArguments(self, jobNum, sandbox, stdout, stderr, addAttr, reqMap) # Job requirements reqs = dict(self.wms.getRequirements(jobNum)) if reqs.get(WMS.SITES, (None, None))[1]: params += ' -l host=%s' % str.join("+", reqs[WMS.SITES][1]) return params
| 476,511
|
def getTaskConfig(self): taskConfig = { # Space limits 'SCRATCH_UL' : self.seSDUpperLimit, 'SCRATCH_LL' : self.seSDLowerLimit, 'LANDINGZONE_UL': self.seLZUpperLimit, 'LANDINGZONE_LL': self.seLZLowerLimit, # Storage element 'SE_MINFILESIZE': self.seMinSize, 'SE_OUTPUT_FILES': str.join(' ', self.seOutputFiles), 'SE_INPUT_FILES': str.join(' ', self.seInputFiles), 'SE_OUTPUT_PATTERN': self.seOutputPattern, 'SE_INPUT_PATTERN': self.seInputPattern, # Sandbox 'SB_OUTPUT_FILES': str.join(' ', self.getOutFiles()), 'SB_INPUT_FILES': str.join(' ', map(utils.shellEscape, map(os.path.basename, self.getInFiles()))), # Runtime 'DOBREAK': self.nodeTimeout, 'MY_RUNTIME': self.getCommand(), 'GC_DEPFILES': str.join(' ', self.getDependencies()), # Seeds and substitutions 'SEEDS': str.join(' ', map(str, self.seeds)), 'SUBST_FILES': str.join(' ', map(os.path.basename, self.getSubstFiles())), # Task infos 'TASK_ID': self.taskID, 'GC_CONF': self.config.confName, 'GC_VERSION': utils.getVersion(), 'DB_EXEC': 'shellscript' } if len(self.sePaths) <= 1: taskConfig['SE_PATH'] = self.sePaths[0] return dict(taskConfig.items() + self.constants.items())
|
def getTaskConfig(self): taskConfig = { # Space limits 'SCRATCH_UL' : self.seSDUpperLimit, 'SCRATCH_LL' : self.seSDLowerLimit, 'LANDINGZONE_UL': self.seLZUpperLimit, 'LANDINGZONE_LL': self.seLZLowerLimit, # Storage element 'SE_MINFILESIZE': self.seMinSize, 'SE_OUTPUT_FILES': str.join(' ', self.seOutputFiles), 'SE_INPUT_FILES': str.join(' ', self.seInputFiles), 'SE_OUTPUT_PATTERN': self.seOutputPattern, 'SE_INPUT_PATTERN': self.seInputPattern, # Sandbox 'SB_OUTPUT_FILES': str.join(' ', self.getOutFiles()), 'SB_INPUT_FILES': str.join(' ', map(utils.shellEscape, map(os.path.basename, self.getInFiles()))), # Runtime 'DOBREAK': self.nodeTimeout, 'MY_RUNTIME': self.getCommand(), 'GC_DEPFILES': str.join(' ', self.getDependencies()), # Seeds and substitutions 'SEEDS': str.join(' ', map(str, self.seeds)), 'SUBST_FILES': str.join(' ', map(os.path.basename, self.getSubstFiles())), # Task infos 'TASK_ID': self.taskID, 'GC_CONF': self.config.confName, 'GC_VERSION': utils.getVersion(), 'DB_EXEC': 'shellscript' } if len(self.sePaths) == 1: taskConfig['SE_PATH'] = self.sePaths[0] return dict(taskConfig.items() + self.constants.items())
| 476,512
|
def doFilter(blockinfo): name = self._filter if self._filter: name = blockinfo[DataProvider.Dataset] if DataProvider.BlockName in blockinfo and "#" in self._filter: name = "%s#%s" % (name, blockinfo[DataProvider.BlockName]) if name.startswith(self._filter): return True return False
|
def doFilter(blockinfo): name = self._filter if self._filter: name = blockinfo[DataProvider.Dataset] if DataProvider.BlockName in blockinfo and "#" in self._filter: name = "%s#%s" % (name, blockinfo[DataProvider.BlockName]) if name.startswith(self._filter): return True return False
| 476,513
|
def getRequirements(self, jobNum): reqs = Module.getRequirements(self, jobNum) if self.dataSplitter != None: selist = self.dataSplitter.getSplitInfo(jobNum).get(DataSplitter.SEList, []) if selist != None: reqs.append((WMS.STORAGE, selist)) return reqs
|
def getRequirements(self, jobNum): reqs = Module.getRequirements(self, jobNum) if self.dataSplitter != None: selist = self.dataSplitter.getSplitInfo(jobNum).get(DataSplitter.SEList, False) if selist != False: reqs.append((WMS.STORAGE, selist)) return reqs
| 476,514
|
def listFileInfoThread(self, result): result.extend(api.listFiles(self.datasetPath, retriveList=([], ['retrive_lumi'])[self.selectedLumis]))
|
def listFileInfoThread(self, result): result.extend(api.listFiles(self.datasetPath, retriveList=([], ['retrive_lumi'])[self.selectedLumis]))
| 476,515
|
def parseMap(x, parser): result = {} for entry in x.split('\n'): if "=>" in entry: nick, value = map(str.strip, entry.split('=>')) else: nick, value = (None, entry) result[nick] = filter(lambda x: x, parser(value.strip())) return result
|
def parseMap(x, parser): result = {} for entry in x.split('\n'): if "=>" in entry: nick, value = map(str.strip, entry.split('=>')) else: nick, value = (None, entry) result[nick] = filter(lambda x: x, parser(value.strip())) return result
| 476,516
|
def lumiFilter(lfn): for lumi in listLumiInfo[lfn]: if selectLumi(lumi, self.selectedLumis): return True return self.selectedLumis == None
|
def lumiFilter(lfn): for lumi in listLumiInfo[lfn]: if selectLumi(lumi, self.selectedLumis): return True return self.selectedLumis == None
| 476,517
|
def se_runcmd(cmd, urls): runLib = utils.pathGC('share', 'gc-run.lib') urlargs = str.join(' ', map(lambda x: '"%s"' % x.replace('dir://', 'file://'), urls)) return 'source %s || exit 1; print_and_eval "%s" %s' % (runLib, cmd, urlargs)
|
def se_runcmd(cmd, urls): runLib = utils.pathGC('share', 'gc-run.lib') urlargs = str.join(' ', map(lambda x: '"%s"' % x.replace('dir://', 'file://'), urls)) return 'source %s || exit 1; print_and_eval "%s" %s' % (runLib, cmd, urlargs)
| 476,518
|
def lenSplit(list, maxlen): clen = 0 tmp = [] for item in list: if clen + len(item) < maxlen: tmp.append(item) clen += len(item) else: tmp.append('') yield tmp tmp = [item] clen = len(item) yield tmp
|
def lenSplit(list, maxlen): clen = 0 tmp = [] for item in list: if clen + len(item) < maxlen: tmp.append(item) clen += len(item) else: tmp.append('') yield tmp tmp = [item] clen = len(item) yield tmp
| 476,519
|
def bytes(obj, enc = None): return obj
|
def bytes(obj, enc=None): return obj
| 476,520
|
def __str__(self): return repr(self.value)
|
def __str__(self): return repr(self.value)
| 476,521
|
def __str__(self): return repr(self.value)
|
def __str__(self): return repr(self.value)
| 476,522
|
def __str__(self): return repr(self.value)
|
def __str__(self): return repr(self.value)
| 476,523
|
def __str__(self): return repr(self.value)
|
def __str__(self): return repr(self.value)
| 476,524
|
def setdefaultproxy(proxytype=None,addr=None,port=None,rdns=True,username=None,password=None): """setdefaultproxy(proxytype, addr[, port[, rdns[, username[, password]]]]) Sets a default proxy which all further socksocket objects will use, unless explicitly changed. """ global _defaultproxy _defaultproxy = (proxytype,addr,port,rdns,username,password)
|
def setdefaultproxy(proxytype=None,addr=None,port=None,rdns=True,username=None,password=None): """setdefaultproxy(proxytype, addr[, port[, rdns[, username[, password]]]]) Sets a default proxy which all further socksocket objects will use, unless explicitly changed. """ global _defaultproxy _defaultproxy = (proxytype, addr, port, rdns, username, password)
| 476,525
|
def __init__(self, family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0, _sock=None): _orgsocket.__init__(self,family,type,proto,_sock) if _defaultproxy != None: self.__proxy = _defaultproxy else: self.__proxy = (None, None, None, None, None, None) self.__proxysockname = None self.__proxypeername = None
|
def __init__(self, family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0, _sock=None): socket.socket.__init__(self, family, type, proto, _sock) if _defaultproxy != None: self.__proxy = _defaultproxy else: self.__proxy = (None, None, None, None, None, None) self.__proxysockname = None self.__proxypeername = None
| 476,526
|
def __decode(self, bytes): if 'decode' in dir(bytes): try: bytes = bytes.decode() except Exception: pass return bytes
|
def __decode(self, bytes): if getattr(bytes, 'decode', False): try: bytes = bytes.decode() except Exception: pass return bytes
| 476,527
|
def __encode(self, bytes): if 'encode' in dir(bytes): try: bytes = bytes.encode() except Exception: pass return bytes
|
def __encode(self, bytes): if getattr(bytes, 'encode', False): try: bytes = bytes.encode() except Exception: pass return bytes
| 476,528
|
def __recvall(self, count): """__recvall(count) -> data Receive EXACTLY the number of bytes requested from the socket. Blocks until the required number of bytes have been received. """ data = bytes("") while len(data) < count: d = self.recv(count-len(data)) if not d: raise GeneralProxyError((0,"connection closed unexpectedly")) data = data + self.__decode(d) return data
|
def __recvall(self, count): """__recvall(count) -> data Receive EXACTLY the number of bytes requested from the socket. Blocks until the required number of bytes have been received. """ data = bytes("") while len(data) < count: d = self.recv(count - len(data)) if not d: raise GeneralProxyError( (0, "connection closed unexpectedly")) data = data + self.__decode(d) return data
| 476,529
|
def setproxy(self,proxytype=None,addr=None,port=None,rdns=True,username=None,password=None): """setproxy(proxytype, addr[, port[, rdns[, username[, password]]]]) Sets the proxy to be used. proxytype - The type of the proxy to be used. Three types are supported: PROXY_TYPE_SOCKS4 (including socks4a), PROXY_TYPE_SOCKS5 and PROXY_TYPE_HTTP addr - The address of the server (IP or DNS). port - The port of the server. Defaults to 1080 for SOCKS servers and 8080 for HTTP proxy servers. rdns - Should DNS queries be preformed on the remote side (rather than the local side). The default is True. Note: This has no effect with SOCKS4 servers. username - Username to authenticate with to the server. The default is no authentication. password - Password to authenticate with to the server. Only relevant when username is also provided. """ self.__proxy = (proxytype,addr,port,rdns,username,password)
|
def setproxy(self, proxytype=None, addr=None, port=None, rdns=True, username=None, password=None): """setproxy(proxytype, addr[, port[, rdns[, username[, password]]]]) Sets the proxy to be used. proxytype - The type of the proxy to be used. Three types are supported: PROXY_TYPE_SOCKS4 (including socks4a), PROXY_TYPE_SOCKS5 and PROXY_TYPE_HTTP addr - The address of the server (IP or DNS). port - The port of the server. Defaults to 1080 for SOCKS servers and 8080 for HTTP proxy servers. rdns - Should DNS queries be preformed on the remote side (rather than the local side). The default is True. Note: This has no effect with SOCKS4 servers. username - Username to authenticate with to the server. The default is no authentication. password - Password to authenticate with to the server. Only relevant when username is also provided. """ self.__proxy = (proxytype,addr,port,rdns,username,password)
| 476,530
|
def setproxy(self,proxytype=None,addr=None,port=None,rdns=True,username=None,password=None): """setproxy(proxytype, addr[, port[, rdns[, username[, password]]]]) Sets the proxy to be used. proxytype - The type of the proxy to be used. Three types are supported: PROXY_TYPE_SOCKS4 (including socks4a), PROXY_TYPE_SOCKS5 and PROXY_TYPE_HTTP addr - The address of the server (IP or DNS). port - The port of the server. Defaults to 1080 for SOCKS servers and 8080 for HTTP proxy servers. rdns - Should DNS queries be preformed on the remote side (rather than the local side). The default is True. Note: This has no effect with SOCKS4 servers. username - Username to authenticate with to the server. The default is no authentication. password - Password to authenticate with to the server. Only relevant when username is also provided. """ self.__proxy = (proxytype,addr,port,rdns,username,password)
|
def setproxy(self,proxytype=None,addr=None,port=None,rdns=True,username=None,password=None): """setproxy(proxytype, addr[, port[, rdns[, username[, password]]]]) Sets the proxy to be used. proxytype - The type of the proxy to be used. Three types are supported: PROXY_TYPE_SOCKS4 (including socks4a), PROXY_TYPE_SOCKS5 and PROXY_TYPE_HTTP addr - The address of the server (IP or DNS). port - The port of the server. Defaults to 1080 for SOCKS servers and 8080 for HTTP proxy servers. rdns - Should DNS queries be preformed on the remote side (rather than the local side). The default is True. Note: This has no effect with SOCKS4 servers. username - Username to authenticate with to the server. The default is no authentication. password - Password to authenticate with to the server. Only relevant when username is also provided. """ self.__proxy = (proxytype,addr,port,rdns,username,password)
| 476,531
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4] != None) and (self.__proxy[5] != None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,532
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1, _generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1, _generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1, _generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1, _generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1, _generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,533
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,534
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1, _generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1, _generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1, _generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1, _generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1, _generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,535
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3, _socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,536
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2, _socks5autherrors[2])) else: raise GeneralProxyError((1, _generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,537
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3] == True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,538
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H", destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,539
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1, _generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1, _generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1, _generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1, _generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1, _generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,540
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1]) <= 8: raise Socks5Error((ord(resp[1]), _socks5errors[ord(resp[1])])) else: raise Socks5Error((9, _socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,541
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1, _generalerrors[1])) boundport = struct.unpack(">H", bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = boundaddr, boundport if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,542
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks5(self,destaddr,destport): """__negotiatesocks5(self,destaddr,destport) Negotiates a connection through a SOCKS5 server. """ # First we'll send the authentication packages we support. if (self.__proxy[4]!=None) and (self.__proxy[5]!=None): # The username/password details were supplied to the # setproxy method so we support the USERNAME/PASSWORD # authentication (in addition to the standard none). self.sendall("\x05\x02\x00\x02") else: # No username/password were entered, therefore we # only support connections with no authentication. self.sendall("\x05\x01\x00") # We'll receive the server's response to determine which # method was selected chosenauth = self.__recvall(2) if chosenauth[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) # Check the chosen authentication method if chosenauth[1] == "\x00": # No authentication is required pass elif chosenauth[1] == "\x02": # Okay, we need to perform a basic username/password # authentication. self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5]) authstat = self.__recvall(2) if authstat[0] != "\x01": # Bad response self.close() raise GeneralProxyError((1,_generalerrors[1])) if authstat[1] != "\x00": # Authentication failed self.close() raise Socks5AuthError((3,_socks5autherrors[3])) # Authentication succeeded else: # Reaching here is always bad self.close() if chosenauth[1] == "\xFF": raise Socks5AuthError((2,_socks5autherrors[2])) else: raise GeneralProxyError((1,_generalerrors[1])) # Now we can request the actual connection req = "\x05\x01\x00" # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: ipaddr = socket.inet_aton(destaddr) req = req + "\x01" + ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. if self.__proxy[3]==True: # Resolve remotely ipaddr = None req = req + "\x03" + chr(len(destaddr)) + destaddr else: # Resolve locally ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) req = req + "\x01" + ipaddr req = req + self.__decode(struct.pack(">H",destport)) self.sendall(req) # Get the response resp = self.__recvall(4) if resp[0] != "\x05": self.close() raise GeneralProxyError((1,_generalerrors[1])) elif resp[1] != "\x00": # Connection failed self.close() if ord(resp[1])<=8: raise Socks5Error((ord(resp[1]),_socks5errors[ord(resp[1])])) else: raise Socks5Error((9,_socks5errors[9])) # Get the bound address/port elif resp[3] == "\x01": boundaddr = self.__recvall(4) elif resp[3] == "\x03": resp = resp + self.recv(1) boundaddr = self.__recvall(ord(resp[4])) else: self.close() raise GeneralProxyError((1,_generalerrors[1])) boundport = struct.unpack(">H",bytes(self.__recvall(2), 'utf8'))[0] self.__proxysockname = (boundaddr,boundport) if ipaddr != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,543
|
def getproxypeername(self): """getproxypeername() -> address info Returns the IP and port number of the proxy. """ return _orgsocket.getpeername(self)
|
def getproxypeername(self): """getproxypeername() -> address info Returns the IP and port number of the proxy. """ return _orgsocket.getpeername(self)
| 476,544
|
def __negotiatesocks4(self,destaddr,destport): """__negotiatesocks4(self,destaddr,destport) Negotiates a connection through a SOCKS4 server. """ # Check if the destination address provided is an IP address rmtrslv = False try: ipaddr = socket.inet_aton(destaddr) except socket.error: # It's a DNS name. Check where it should be resolved. if self.__proxy[3]==True: ipaddr = "\x00\x00\x00\x01" rmtrslv = True else: ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) # Construct the request packet req = "\x04\x01" + self.__decode(struct.pack(">H",destport)) + ipaddr # The username parameter is considered userid for SOCKS4 if self.__proxy[4] != None: req = req + self.__proxy[4] req = req + "\x00" # DNS name if remote resolving is required # NOTE: This is actually an extension to the SOCKS4 protocol # called SOCKS4A and may not be supported in all cases. if rmtrslv==True: req = req + destaddr + "\x00" self.sendall(req) # Get the response from the server resp = self.__recvall(8) if resp[0] != "\x00": # Bad data self.close() raise GeneralProxyError((1,_generalerrors[1])) if resp[1] != "\x5A": # Server returned an error self.close() if ord(resp[1]) in (91,92,93): self.close() raise Socks4Error((ord(resp[1]),_socks4errors[ord(resp[1])-90])) else: raise Socks4Error((94,_socks4errors[4])) # Get the bound address/port self.__proxysockname = (socket.inet_ntoa(resp[4:]),struct.unpack(">H",bytes(resp[2:4],'utf8'))[0]) if rmtrslv != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks4(self, destaddr, destport): """__negotiatesocks4(self,destaddr,destport) Negotiates a connection through a SOCKS4 server. """ # Check if the destination address provided is an IP address rmtrslv = False try: ipaddr = socket.inet_aton(destaddr) except socket.error: # It's a DNS name. Check where it should be resolved. if self.__proxy[3]==True: ipaddr = "\x00\x00\x00\x01" rmtrslv = True else: ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) # Construct the request packet req = "\x04\x01" + self.__decode(struct.pack(">H",destport)) + ipaddr # The username parameter is considered userid for SOCKS4 if self.__proxy[4] != None: req = req + self.__proxy[4] req = req + "\x00" # DNS name if remote resolving is required # NOTE: This is actually an extension to the SOCKS4 protocol # called SOCKS4A and may not be supported in all cases. if rmtrslv==True: req = req + destaddr + "\x00" self.sendall(req) # Get the response from the server resp = self.__recvall(8) if resp[0] != "\x00": # Bad data self.close() raise GeneralProxyError((1,_generalerrors[1])) if resp[1] != "\x5A": # Server returned an error self.close() if ord(resp[1]) in (91,92,93): self.close() raise Socks4Error((ord(resp[1]),_socks4errors[ord(resp[1])-90])) else: raise Socks4Error((94,_socks4errors[4])) # Get the bound address/port self.__proxysockname = (socket.inet_ntoa(resp[4:]),struct.unpack(">H",bytes(resp[2:4],'utf8'))[0]) if rmtrslv != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,545
|
def __negotiatesocks4(self,destaddr,destport): """__negotiatesocks4(self,destaddr,destport) Negotiates a connection through a SOCKS4 server. """ # Check if the destination address provided is an IP address rmtrslv = False try: ipaddr = socket.inet_aton(destaddr) except socket.error: # It's a DNS name. Check where it should be resolved. if self.__proxy[3]==True: ipaddr = "\x00\x00\x00\x01" rmtrslv = True else: ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) # Construct the request packet req = "\x04\x01" + self.__decode(struct.pack(">H",destport)) + ipaddr # The username parameter is considered userid for SOCKS4 if self.__proxy[4] != None: req = req + self.__proxy[4] req = req + "\x00" # DNS name if remote resolving is required # NOTE: This is actually an extension to the SOCKS4 protocol # called SOCKS4A and may not be supported in all cases. if rmtrslv==True: req = req + destaddr + "\x00" self.sendall(req) # Get the response from the server resp = self.__recvall(8) if resp[0] != "\x00": # Bad data self.close() raise GeneralProxyError((1,_generalerrors[1])) if resp[1] != "\x5A": # Server returned an error self.close() if ord(resp[1]) in (91,92,93): self.close() raise Socks4Error((ord(resp[1]),_socks4errors[ord(resp[1])-90])) else: raise Socks4Error((94,_socks4errors[4])) # Get the bound address/port self.__proxysockname = (socket.inet_ntoa(resp[4:]),struct.unpack(">H",bytes(resp[2:4],'utf8'))[0]) if rmtrslv != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks4(self,destaddr,destport): """__negotiatesocks4(self,destaddr,destport) Negotiates a connection through a SOCKS4 server. """ # Check if the destination address provided is an IP address rmtrslv = False try: ipaddr = socket.inet_aton(destaddr) except socket.error: # It's a DNS name. Check where it should be resolved. if self.__proxy[3] == True: ipaddr = "\x00\x00\x00\x01" rmtrslv = True else: ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) # Construct the request packet req = "\x04\x01" + self.__decode(struct.pack(">H",destport)) + ipaddr # The username parameter is considered userid for SOCKS4 if self.__proxy[4] != None: req = req + self.__proxy[4] req = req + "\x00" # DNS name if remote resolving is required # NOTE: This is actually an extension to the SOCKS4 protocol # called SOCKS4A and may not be supported in all cases. if rmtrslv==True: req = req + destaddr + "\x00" self.sendall(req) # Get the response from the server resp = self.__recvall(8) if resp[0] != "\x00": # Bad data self.close() raise GeneralProxyError((1,_generalerrors[1])) if resp[1] != "\x5A": # Server returned an error self.close() if ord(resp[1]) in (91,92,93): self.close() raise Socks4Error((ord(resp[1]),_socks4errors[ord(resp[1])-90])) else: raise Socks4Error((94,_socks4errors[4])) # Get the bound address/port self.__proxysockname = (socket.inet_ntoa(resp[4:]),struct.unpack(">H",bytes(resp[2:4],'utf8'))[0]) if rmtrslv != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,546
|
def __negotiatesocks4(self,destaddr,destport): """__negotiatesocks4(self,destaddr,destport) Negotiates a connection through a SOCKS4 server. """ # Check if the destination address provided is an IP address rmtrslv = False try: ipaddr = socket.inet_aton(destaddr) except socket.error: # It's a DNS name. Check where it should be resolved. if self.__proxy[3]==True: ipaddr = "\x00\x00\x00\x01" rmtrslv = True else: ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) # Construct the request packet req = "\x04\x01" + self.__decode(struct.pack(">H",destport)) + ipaddr # The username parameter is considered userid for SOCKS4 if self.__proxy[4] != None: req = req + self.__proxy[4] req = req + "\x00" # DNS name if remote resolving is required # NOTE: This is actually an extension to the SOCKS4 protocol # called SOCKS4A and may not be supported in all cases. if rmtrslv==True: req = req + destaddr + "\x00" self.sendall(req) # Get the response from the server resp = self.__recvall(8) if resp[0] != "\x00": # Bad data self.close() raise GeneralProxyError((1,_generalerrors[1])) if resp[1] != "\x5A": # Server returned an error self.close() if ord(resp[1]) in (91,92,93): self.close() raise Socks4Error((ord(resp[1]),_socks4errors[ord(resp[1])-90])) else: raise Socks4Error((94,_socks4errors[4])) # Get the bound address/port self.__proxysockname = (socket.inet_ntoa(resp[4:]),struct.unpack(">H",bytes(resp[2:4],'utf8'))[0]) if rmtrslv != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks4(self,destaddr,destport): """__negotiatesocks4(self,destaddr,destport) Negotiates a connection through a SOCKS4 server. """ # Check if the destination address provided is an IP address rmtrslv = False try: ipaddr = socket.inet_aton(destaddr) except socket.error: # It's a DNS name. Check where it should be resolved. if self.__proxy[3]==True: ipaddr = "\x00\x00\x00\x01" rmtrslv = True else: ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) # Construct the request packet req = "\x04\x01" + self.__decode(struct.pack(">H", destport)) + ipaddr # The username parameter is considered userid for SOCKS4 if self.__proxy[4] != None: req = req + self.__proxy[4] req = req + "\x00" # DNS name if remote resolving is required # NOTE: This is actually an extension to the SOCKS4 protocol # called SOCKS4A and may not be supported in all cases. if rmtrslv==True: req = req + destaddr + "\x00" self.sendall(req) # Get the response from the server resp = self.__recvall(8) if resp[0] != "\x00": # Bad data self.close() raise GeneralProxyError((1,_generalerrors[1])) if resp[1] != "\x5A": # Server returned an error self.close() if ord(resp[1]) in (91,92,93): self.close() raise Socks4Error((ord(resp[1]),_socks4errors[ord(resp[1])-90])) else: raise Socks4Error((94,_socks4errors[4])) # Get the bound address/port self.__proxysockname = (socket.inet_ntoa(resp[4:]),struct.unpack(">H",bytes(resp[2:4],'utf8'))[0]) if rmtrslv != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,547
|
def __negotiatesocks4(self,destaddr,destport): """__negotiatesocks4(self,destaddr,destport) Negotiates a connection through a SOCKS4 server. """ # Check if the destination address provided is an IP address rmtrslv = False try: ipaddr = socket.inet_aton(destaddr) except socket.error: # It's a DNS name. Check where it should be resolved. if self.__proxy[3]==True: ipaddr = "\x00\x00\x00\x01" rmtrslv = True else: ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) # Construct the request packet req = "\x04\x01" + self.__decode(struct.pack(">H",destport)) + ipaddr # The username parameter is considered userid for SOCKS4 if self.__proxy[4] != None: req = req + self.__proxy[4] req = req + "\x00" # DNS name if remote resolving is required # NOTE: This is actually an extension to the SOCKS4 protocol # called SOCKS4A and may not be supported in all cases. if rmtrslv==True: req = req + destaddr + "\x00" self.sendall(req) # Get the response from the server resp = self.__recvall(8) if resp[0] != "\x00": # Bad data self.close() raise GeneralProxyError((1,_generalerrors[1])) if resp[1] != "\x5A": # Server returned an error self.close() if ord(resp[1]) in (91,92,93): self.close() raise Socks4Error((ord(resp[1]),_socks4errors[ord(resp[1])-90])) else: raise Socks4Error((94,_socks4errors[4])) # Get the bound address/port self.__proxysockname = (socket.inet_ntoa(resp[4:]),struct.unpack(">H",bytes(resp[2:4],'utf8'))[0]) if rmtrslv != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks4(self,destaddr,destport): """__negotiatesocks4(self,destaddr,destport) Negotiates a connection through a SOCKS4 server. """ # Check if the destination address provided is an IP address rmtrslv = False try: ipaddr = socket.inet_aton(destaddr) except socket.error: # It's a DNS name. Check where it should be resolved. if self.__proxy[3]==True: ipaddr = "\x00\x00\x00\x01" rmtrslv = True else: ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) # Construct the request packet req = "\x04\x01" + self.__decode(struct.pack(">H",destport)) + ipaddr # The username parameter is considered userid for SOCKS4 if self.__proxy[4] != None: req = req + self.__proxy[4] req = req + "\x00" # DNS name if remote resolving is required # NOTE: This is actually an extension to the SOCKS4 protocol # called SOCKS4A and may not be supported in all cases. if rmtrslv==True: req = req + destaddr + "\x00" self.sendall(req) # Get the response from the server resp = self.__recvall(8) if resp[0] != "\x00": # Bad data self.close() raise GeneralProxyError((1, _generalerrors[1])) if resp[1] != "\x5A": # Server returned an error self.close() if ord(resp[1]) in (91,92,93): self.close() raise Socks4Error((ord(resp[1]),_socks4errors[ord(resp[1])-90])) else: raise Socks4Error((94,_socks4errors[4])) # Get the bound address/port self.__proxysockname = (socket.inet_ntoa(resp[4:]),struct.unpack(">H",bytes(resp[2:4],'utf8'))[0]) if rmtrslv != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,548
|
def __negotiatesocks4(self,destaddr,destport): """__negotiatesocks4(self,destaddr,destport) Negotiates a connection through a SOCKS4 server. """ # Check if the destination address provided is an IP address rmtrslv = False try: ipaddr = socket.inet_aton(destaddr) except socket.error: # It's a DNS name. Check where it should be resolved. if self.__proxy[3]==True: ipaddr = "\x00\x00\x00\x01" rmtrslv = True else: ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) # Construct the request packet req = "\x04\x01" + self.__decode(struct.pack(">H",destport)) + ipaddr # The username parameter is considered userid for SOCKS4 if self.__proxy[4] != None: req = req + self.__proxy[4] req = req + "\x00" # DNS name if remote resolving is required # NOTE: This is actually an extension to the SOCKS4 protocol # called SOCKS4A and may not be supported in all cases. if rmtrslv==True: req = req + destaddr + "\x00" self.sendall(req) # Get the response from the server resp = self.__recvall(8) if resp[0] != "\x00": # Bad data self.close() raise GeneralProxyError((1,_generalerrors[1])) if resp[1] != "\x5A": # Server returned an error self.close() if ord(resp[1]) in (91,92,93): self.close() raise Socks4Error((ord(resp[1]),_socks4errors[ord(resp[1])-90])) else: raise Socks4Error((94,_socks4errors[4])) # Get the bound address/port self.__proxysockname = (socket.inet_ntoa(resp[4:]),struct.unpack(">H",bytes(resp[2:4],'utf8'))[0]) if rmtrslv != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks4(self,destaddr,destport): """__negotiatesocks4(self,destaddr,destport) Negotiates a connection through a SOCKS4 server. """ # Check if the destination address provided is an IP address rmtrslv = False try: ipaddr = socket.inet_aton(destaddr) except socket.error: # It's a DNS name. Check where it should be resolved. if self.__proxy[3]==True: ipaddr = "\x00\x00\x00\x01" rmtrslv = True else: ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) # Construct the request packet req = "\x04\x01" + self.__decode(struct.pack(">H",destport)) + ipaddr # The username parameter is considered userid for SOCKS4 if self.__proxy[4] != None: req = req + self.__proxy[4] req = req + "\x00" # DNS name if remote resolving is required # NOTE: This is actually an extension to the SOCKS4 protocol # called SOCKS4A and may not be supported in all cases. if rmtrslv==True: req = req + destaddr + "\x00" self.sendall(req) # Get the response from the server resp = self.__recvall(8) if resp[0] != "\x00": # Bad data self.close() raise GeneralProxyError((1,_generalerrors[1])) if resp[1] != "\x5A": # Server returned an error self.close() if ord(resp[1]) in (91,92,93): self.close() raise Socks4Error((ord(resp[1]), _socks4errors[ord(resp[1])-90])) else: raise Socks4Error((94,_socks4errors[4])) # Get the bound address/port self.__proxysockname = (socket.inet_ntoa(resp[4:]),struct.unpack(">H",bytes(resp[2:4],'utf8'))[0]) if rmtrslv != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,549
|
def __negotiatesocks4(self,destaddr,destport): """__negotiatesocks4(self,destaddr,destport) Negotiates a connection through a SOCKS4 server. """ # Check if the destination address provided is an IP address rmtrslv = False try: ipaddr = socket.inet_aton(destaddr) except socket.error: # It's a DNS name. Check where it should be resolved. if self.__proxy[3]==True: ipaddr = "\x00\x00\x00\x01" rmtrslv = True else: ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) # Construct the request packet req = "\x04\x01" + self.__decode(struct.pack(">H",destport)) + ipaddr # The username parameter is considered userid for SOCKS4 if self.__proxy[4] != None: req = req + self.__proxy[4] req = req + "\x00" # DNS name if remote resolving is required # NOTE: This is actually an extension to the SOCKS4 protocol # called SOCKS4A and may not be supported in all cases. if rmtrslv==True: req = req + destaddr + "\x00" self.sendall(req) # Get the response from the server resp = self.__recvall(8) if resp[0] != "\x00": # Bad data self.close() raise GeneralProxyError((1,_generalerrors[1])) if resp[1] != "\x5A": # Server returned an error self.close() if ord(resp[1]) in (91,92,93): self.close() raise Socks4Error((ord(resp[1]),_socks4errors[ord(resp[1])-90])) else: raise Socks4Error((94,_socks4errors[4])) # Get the bound address/port self.__proxysockname = (socket.inet_ntoa(resp[4:]),struct.unpack(">H",bytes(resp[2:4],'utf8'))[0]) if rmtrslv != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
|
def __negotiatesocks4(self,destaddr,destport): """__negotiatesocks4(self,destaddr,destport) Negotiates a connection through a SOCKS4 server. """ # Check if the destination address provided is an IP address rmtrslv = False try: ipaddr = socket.inet_aton(destaddr) except socket.error: # It's a DNS name. Check where it should be resolved. if self.__proxy[3]==True: ipaddr = "\x00\x00\x00\x01" rmtrslv = True else: ipaddr = socket.inet_aton(socket.gethostbyname(destaddr)) # Construct the request packet req = "\x04\x01" + self.__decode(struct.pack(">H",destport)) + ipaddr # The username parameter is considered userid for SOCKS4 if self.__proxy[4] != None: req = req + self.__proxy[4] req = req + "\x00" # DNS name if remote resolving is required # NOTE: This is actually an extension to the SOCKS4 protocol # called SOCKS4A and may not be supported in all cases. if rmtrslv==True: req = req + destaddr + "\x00" self.sendall(req) # Get the response from the server resp = self.__recvall(8) if resp[0] != "\x00": # Bad data self.close() raise GeneralProxyError((1,_generalerrors[1])) if resp[1] != "\x5A": # Server returned an error self.close() if ord(resp[1]) in (91,92,93): self.close() raise Socks4Error((ord(resp[1]),_socks4errors[ord(resp[1])-90])) else: raise Socks4Error((94,_socks4errors[4])) # Get the bound address/port self.__proxysockname = (socket.inet_ntoa(resp[4:]),struct.unpack(">H",bytes(resp[2:4],'utf8'))[0]) if rmtrslv != None: self.__proxypeername = (socket.inet_ntoa(ipaddr),destport) else: self.__proxypeername = (destaddr,destport)
| 476,550
|
def __negotiatehttp(self,destaddr,destport): """__negotiatehttp(self,destaddr,destport) Negotiates a connection through an HTTP server. """ # If we need to resolve locally, we do this now if self.__proxy[3] == False: addr = socket.gethostbyname(destaddr) else: addr = destaddr self.sendall("CONNECT " + addr + ":" + str(destport) + " HTTP/1.1\r\n" + "Host: " + destaddr + "\r\n\r\n") # We read the response until we get the string "\r\n\r\n" resp = self.recv(1) while resp.find("\r\n\r\n")==-1: resp = resp + self.recv(1) # We just need the first line to check if the connection # was successful statusline = resp.splitlines()[0].split(" ",2) if statusline[0] not in ("HTTP/1.0","HTTP/1.1"): self.close() raise GeneralProxyError((1,_generalerrors[1])) try: statuscode = int(statusline[1]) except ValueError: self.close() raise GeneralProxyError((1,_generalerrors[1])) if statuscode != 200: self.close() raise HTTPError((statuscode,statusline[2])) self.__proxysockname = ("0.0.0.0",0) self.__proxypeername = (addr,destport)
|
def __negotiatehttp(self,destaddr,destport): """__negotiatehttp(self,destaddr,destport) Negotiates a connection through an HTTP server. """ # If we need to resolve locally, we do this now if self.__proxy[3] == False: addr = socket.gethostbyname(destaddr) else: addr = destaddr self.sendall(("CONNECT %s:%s HTTP/1.1\r\n" "Host: %s\r\n\r\n") % (addr, destport, destaddr)) # We read the response until we get the string "\r\n\r\n" resp = self.recv(1) while resp.find("\r\n\r\n")==-1: resp = resp + self.recv(1) # We just need the first line to check if the connection # was successful statusline = resp.splitlines()[0].split(" ",2) if statusline[0] not in ("HTTP/1.0","HTTP/1.1"): self.close() raise GeneralProxyError((1,_generalerrors[1])) try: statuscode = int(statusline[1]) except ValueError: self.close() raise GeneralProxyError((1,_generalerrors[1])) if statuscode != 200: self.close() raise HTTPError((statuscode,statusline[2])) self.__proxysockname = ("0.0.0.0",0) self.__proxypeername = (addr,destport)
| 476,551
|
def __negotiatehttp(self,destaddr,destport): """__negotiatehttp(self,destaddr,destport) Negotiates a connection through an HTTP server. """ # If we need to resolve locally, we do this now if self.__proxy[3] == False: addr = socket.gethostbyname(destaddr) else: addr = destaddr self.sendall("CONNECT " + addr + ":" + str(destport) + " HTTP/1.1\r\n" + "Host: " + destaddr + "\r\n\r\n") # We read the response until we get the string "\r\n\r\n" resp = self.recv(1) while resp.find("\r\n\r\n")==-1: resp = resp + self.recv(1) # We just need the first line to check if the connection # was successful statusline = resp.splitlines()[0].split(" ",2) if statusline[0] not in ("HTTP/1.0","HTTP/1.1"): self.close() raise GeneralProxyError((1,_generalerrors[1])) try: statuscode = int(statusline[1]) except ValueError: self.close() raise GeneralProxyError((1,_generalerrors[1])) if statuscode != 200: self.close() raise HTTPError((statuscode,statusline[2])) self.__proxysockname = ("0.0.0.0",0) self.__proxypeername = (addr,destport)
|
def __negotiatehttp(self,destaddr,destport): """__negotiatehttp(self,destaddr,destport) Negotiates a connection through an HTTP server. """ # If we need to resolve locally, we do this now if self.__proxy[3] == False: addr = socket.gethostbyname(destaddr) else: addr = destaddr self.sendall("CONNECT " + addr + ":" + str(destport) + " HTTP/1.1\r\n" + "Host: " + destaddr + "\r\n\r\n") # We read the response until we get the string "\r\n\r\n" resp = self.recv(1) while resp.find("\r\n\r\n") == -1: resp = resp + self.recv(1) # We just need the first line to check if the connection # was successful statusline = resp.splitlines()[0].split(" ",2) if statusline[0] not in ("HTTP/1.0","HTTP/1.1"): self.close() raise GeneralProxyError((1,_generalerrors[1])) try: statuscode = int(statusline[1]) except ValueError: self.close() raise GeneralProxyError((1,_generalerrors[1])) if statuscode != 200: self.close() raise HTTPError((statuscode,statusline[2])) self.__proxysockname = ("0.0.0.0",0) self.__proxypeername = (addr,destport)
| 476,552
|
def __negotiatehttp(self,destaddr,destport): """__negotiatehttp(self,destaddr,destport) Negotiates a connection through an HTTP server. """ # If we need to resolve locally, we do this now if self.__proxy[3] == False: addr = socket.gethostbyname(destaddr) else: addr = destaddr self.sendall("CONNECT " + addr + ":" + str(destport) + " HTTP/1.1\r\n" + "Host: " + destaddr + "\r\n\r\n") # We read the response until we get the string "\r\n\r\n" resp = self.recv(1) while resp.find("\r\n\r\n")==-1: resp = resp + self.recv(1) # We just need the first line to check if the connection # was successful statusline = resp.splitlines()[0].split(" ",2) if statusline[0] not in ("HTTP/1.0","HTTP/1.1"): self.close() raise GeneralProxyError((1,_generalerrors[1])) try: statuscode = int(statusline[1]) except ValueError: self.close() raise GeneralProxyError((1,_generalerrors[1])) if statuscode != 200: self.close() raise HTTPError((statuscode,statusline[2])) self.__proxysockname = ("0.0.0.0",0) self.__proxypeername = (addr,destport)
|
def __negotiatehttp(self,destaddr,destport): """__negotiatehttp(self,destaddr,destport) Negotiates a connection through an HTTP server. """ # If we need to resolve locally, we do this now if self.__proxy[3] == False: addr = socket.gethostbyname(destaddr) else: addr = destaddr self.sendall("CONNECT " + addr + ":" + str(destport) + " HTTP/1.1\r\n" + "Host: " + destaddr + "\r\n\r\n") # We read the response until we get the string "\r\n\r\n" resp = self.recv(1) while resp.find("\r\n\r\n")==-1: resp = resp + self.recv(1) # We just need the first line to check if the connection # was successful statusline = resp.splitlines()[0].split(" ", 2) if statusline[0] not in ("HTTP/1.0", "HTTP/1.1"): self.close() raise GeneralProxyError((1, _generalerrors[1])) try: statuscode = int(statusline[1]) except ValueError: self.close() raise GeneralProxyError((1,_generalerrors[1])) if statuscode != 200: self.close() raise HTTPError((statuscode,statusline[2])) self.__proxysockname = ("0.0.0.0",0) self.__proxypeername = (addr,destport)
| 476,553
|
def __negotiatehttp(self,destaddr,destport): """__negotiatehttp(self,destaddr,destport) Negotiates a connection through an HTTP server. """ # If we need to resolve locally, we do this now if self.__proxy[3] == False: addr = socket.gethostbyname(destaddr) else: addr = destaddr self.sendall("CONNECT " + addr + ":" + str(destport) + " HTTP/1.1\r\n" + "Host: " + destaddr + "\r\n\r\n") # We read the response until we get the string "\r\n\r\n" resp = self.recv(1) while resp.find("\r\n\r\n")==-1: resp = resp + self.recv(1) # We just need the first line to check if the connection # was successful statusline = resp.splitlines()[0].split(" ",2) if statusline[0] not in ("HTTP/1.0","HTTP/1.1"): self.close() raise GeneralProxyError((1,_generalerrors[1])) try: statuscode = int(statusline[1]) except ValueError: self.close() raise GeneralProxyError((1,_generalerrors[1])) if statuscode != 200: self.close() raise HTTPError((statuscode,statusline[2])) self.__proxysockname = ("0.0.0.0",0) self.__proxypeername = (addr,destport)
|
def __negotiatehttp(self,destaddr,destport): """__negotiatehttp(self,destaddr,destport) Negotiates a connection through an HTTP server. """ # If we need to resolve locally, we do this now if self.__proxy[3] == False: addr = socket.gethostbyname(destaddr) else: addr = destaddr self.sendall("CONNECT " + addr + ":" + str(destport) + " HTTP/1.1\r\n" + "Host: " + destaddr + "\r\n\r\n") # We read the response until we get the string "\r\n\r\n" resp = self.recv(1) while resp.find("\r\n\r\n")==-1: resp = resp + self.recv(1) # We just need the first line to check if the connection # was successful statusline = resp.splitlines()[0].split(" ",2) if statusline[0] not in ("HTTP/1.0","HTTP/1.1"): self.close() raise GeneralProxyError((1, _generalerrors[1])) try: statuscode = int(statusline[1]) except ValueError: self.close() raise GeneralProxyError((1, _generalerrors[1])) if statuscode != 200: self.close() raise HTTPError((statuscode,statusline[2])) self.__proxysockname = ("0.0.0.0",0) self.__proxypeername = (addr,destport)
| 476,554
|
def __negotiatehttp(self,destaddr,destport): """__negotiatehttp(self,destaddr,destport) Negotiates a connection through an HTTP server. """ # If we need to resolve locally, we do this now if self.__proxy[3] == False: addr = socket.gethostbyname(destaddr) else: addr = destaddr self.sendall("CONNECT " + addr + ":" + str(destport) + " HTTP/1.1\r\n" + "Host: " + destaddr + "\r\n\r\n") # We read the response until we get the string "\r\n\r\n" resp = self.recv(1) while resp.find("\r\n\r\n")==-1: resp = resp + self.recv(1) # We just need the first line to check if the connection # was successful statusline = resp.splitlines()[0].split(" ",2) if statusline[0] not in ("HTTP/1.0","HTTP/1.1"): self.close() raise GeneralProxyError((1,_generalerrors[1])) try: statuscode = int(statusline[1]) except ValueError: self.close() raise GeneralProxyError((1,_generalerrors[1])) if statuscode != 200: self.close() raise HTTPError((statuscode,statusline[2])) self.__proxysockname = ("0.0.0.0",0) self.__proxypeername = (addr,destport)
|
def __negotiatehttp(self,destaddr,destport): """__negotiatehttp(self,destaddr,destport) Negotiates a connection through an HTTP server. """ # If we need to resolve locally, we do this now if self.__proxy[3] == False: addr = socket.gethostbyname(destaddr) else: addr = destaddr self.sendall("CONNECT " + addr + ":" + str(destport) + " HTTP/1.1\r\n" + "Host: " + destaddr + "\r\n\r\n") # We read the response until we get the string "\r\n\r\n" resp = self.recv(1) while resp.find("\r\n\r\n")==-1: resp = resp + self.recv(1) # We just need the first line to check if the connection # was successful statusline = resp.splitlines()[0].split(" ",2) if statusline[0] not in ("HTTP/1.0","HTTP/1.1"): self.close() raise GeneralProxyError((1,_generalerrors[1])) try: statuscode = int(statusline[1]) except ValueError: self.close() raise GeneralProxyError((1,_generalerrors[1])) if statuscode != 200: self.close() raise HTTPError((statuscode,statusline[2])) self.__proxysockname = ("0.0.0.0",0) self.__proxypeername = (addr,destport)
| 476,555
|
def slider3_sat(out_type, size, offset): s = size/20 start1 = [1, 2*s+3, 2*s+1, size/2-1-3*s, size/2-1, size/2+1] start2 = [1, 2*s-1, 2*s+2, size/2-1-4*s, size/2-1-2*s, size/2-1-s, size/2+1] ''' print >> sys.stderr, start1 print >> sys.stderr, start2 ''' print "p bdd %d %d" % (size+offset,size+2*offset) print "; automatically generated SAT slider3 with size=%d " % size print "; Disclaimer: no formal analysis was done to verify SAT and UNSAT" #first function print "#define add_state1(1, 2, 3, 5, 4, 6)" print "#equ(xor(1, and(-3, 5), nand(6, 4)), ite(2, or(5, -6), -5)))" for i in range(0, size/2+offset): sys.stdout.write("add_state1") print tuple(start1) for item in range(len(start1)): start1[item] += 1 #second and third function print("#define add_state2(1, 2, 3, 4, 5, 6)") print("#xor(-1, xor(3, and(-4, 5), 4), equ(6, 2))") print("#define add_state3(1, 2, 3, 4, 5, 6)") print("#xor(-1, xor(3, and(-4, 5), 4), equ(6, 2))") for i in range(0, size-size/2+offset): test = (i%2)+2 sys.stdout.write("add_state%d" % test) print tuple(start2[0:5]+start2[6:]) for item in range(len(start2)): start2[item] += 1
|
def slider3_sat(out_type, size, offset): s = size/20 start1 = [1, 2*s+3, 2*s+1, size/2-1-3*s, size/2-1, size/2] start2 = [1, 2*s-1, 2*s+2, size/2-1-4*s, size/2-1-2*s, size/2-1-s, size/2] ''' print >> sys.stderr, start1 print >> sys.stderr, start2 ''' print "p bdd %d %d" % (size+offset,size+2*offset) print "; automatically generated SAT slider3 with size=%d " % size print "; Disclaimer: no formal analysis was done to verify SAT and UNSAT" #first function print "#define add_state1(1, 2, 3, 5, 4, 6)" print "#equ(xor(1, and(-3, 5), nand(6, 4)), ite(2, or(5, -6), -5)))" for i in range(0, size/2+offset): sys.stdout.write("add_state1") print tuple(start1) for item in range(len(start1)): start1[item] += 1 #second and third function print("#define add_state2(1, 2, 3, 4, 5, 6)") print("#xor(-1, xor(3, and(-4, 5), 4), equ(6, 2))") print("#define add_state3(1, 2, 3, 4, 5, 6)") print("#xor(-1, xor(3, and(-4, 5), 4), equ(6, 2))") for i in range(0, size-size/2+offset): test = (i%2)+2 sys.stdout.write("add_state%d" % test) print tuple(start2[0:5]+start2[6:]) for item in range(len(start2)): start2[item] += 1
| 476,556
|
def slider3_sat(out_type, size, offset): s = size/20 start1 = [1, 2*s+3, 2*s+1, size/2-1-3*s, size/2-1, size/2+1] start2 = [1, 2*s-1, 2*s+2, size/2-1-4*s, size/2-1-2*s, size/2-1-s, size/2+1] ''' print >> sys.stderr, start1 print >> sys.stderr, start2 ''' print "p bdd %d %d" % (size+offset,size+2*offset) print "; automatically generated SAT slider3 with size=%d " % size print "; Disclaimer: no formal analysis was done to verify SAT and UNSAT" #first function print "#define add_state1(1, 2, 3, 5, 4, 6)" print "#equ(xor(1, and(-3, 5), nand(6, 4)), ite(2, or(5, -6), -5)))" for i in range(0, size/2+offset): sys.stdout.write("add_state1") print tuple(start1) for item in range(len(start1)): start1[item] += 1 #second and third function print("#define add_state2(1, 2, 3, 4, 5, 6)") print("#xor(-1, xor(3, and(-4, 5), 4), equ(6, 2))") print("#define add_state3(1, 2, 3, 4, 5, 6)") print("#xor(-1, xor(3, and(-4, 5), 4), equ(6, 2))") for i in range(0, size-size/2+offset): test = (i%2)+2 sys.stdout.write("add_state%d" % test) print tuple(start2[0:5]+start2[6:]) for item in range(len(start2)): start2[item] += 1
|
def slider3_sat(out_type, size, offset): s = size/20 start1 = [1, 2*s+3, 2*s+1, size/2-1-3*s, size/2-1, size/2+1] start2 = [1, 2*s-1, 2*s+2, size/2-1-4*s, size/2-1-2*s, size/2-1-s, size/2+1] ''' print >> sys.stderr, start1 print >> sys.stderr, start2 ''' print "p bdd %d %d" % (size+offset,size+2*offset) print "; automatically generated SAT slider3 with size=%d " % size print "; Disclaimer: no formal analysis was done to verify SAT and UNSAT" #first function print "#define add_state1(1, 2, 3, 5, 4, 6)" print "#equ(xor(1, and(-3, 5), nand(6, 4)), ite(2, or(5, -6), -5)))" for i in range(0, size/2+offset): sys.stdout.write("add_state1") print tuple(start1) for item in range(len(start1)): start1[item] += 1 #second and third function print("#define add_state2(1, 2, 3, 4, 5, 6)") print("#xor(-1, xor(3, and(-4, 5), 4), equ(6, 2))") print("#define add_state3(1, 2, 3, 4, 5, 6)") print("#xor(-1, xor(3, and(-4, 5), 4), equ(6, 2))") for i in range(0, size-size/2+offset): test = (i%2)+2 sys.stdout.write("add_state%d" % test) print tuple(start2[0:5]+start2[6:]) for item in range(len(start2)): start2[item] += 1
| 476,557
|
def __init__(self, target_file, target_dir, materials = None, textures = None): self.target_file = target_file self.target_dir = target_dir self.exported_materials = [] self.exported_textures = [] self.materials = materials if materials != None else bpy.data.textures self.textures = textures if textures != None else bpy.data.textures
|
def __init__(self, target_file, target_dir, materials = None, textures = None): self.target_file = target_file self.target_dir = target_dir self.exported_materials = [] self.exported_textures = [] self.materials = materials if materials != None else bpy.data.materials self.textures = textures if textures != None else bpy.data.textures
| 476,558
|
def findMaterial(self, name): if name in self.materials: return self.materials[name] else: raise Exception('Failed to find material "%s"' % name)
|
def findMaterial(self, name): if name in self.materials: return self.materials[name] else: raise Exception('Failed to find material "%s"' % name)
| 476,559
|
def dict_merge(*args): vis = {} for vis_dict in args: vis.update(deepcopy(vis_dict)) return vis
|
def dict_merge(*args): vis = {} for vis_dict in args: vis.update(deepcopy(vis_dict)) return vis
| 476,560
|
def execute(self, context): pv = [ 'bpy.context.material.mitsuba_material.%s'%v['attr'] for v in bpy.types.mitsuba_material.get_exportable_properties() ]
|
def execute(self, context): pv = [ 'bpy.context.material.mitsuba_material.%s'%v['attr'] for v in bpy.types.mitsuba_material.get_exportable_properties() ]
| 476,561
|
def execute(self, context): try: if self.properties.scene == '': scene = context.scene else: scene = bpy.data.scenes[self.properties.scene]
|
def execute(self, context): try: if self.properties.scene == '': scene = context.scene else: scene = bpy.data.scenes[self.properties.scene]
| 476,562
|
def exportLamp(self, lamp, idx): ltype = lamp.data.mitsuba_lamp.type name = translate_id(lamp.data.name) if ltype == 'POINT': self.out.write('\t<luminaire id="%s-light" type="point">\n' % name) mult = lamp.data.mitsuba_lamp.intensity self.exportWorldtrafo(lamp.matrix_world) self.out.write('\t\t<rgb name="intensity" value="%f %f %f"/>\n' % (lamp.data.color.r*mult, lamp.data.color.g*mult, lamp.data.color.b*mult)) self.out.write('\t\t<float name="samplingWeight" value="%f"/>\n' % lamp.data.mitsuba_lamp.samplingWeight) self.out.write('\t</luminaire>\n') elif ltype == 'AREA': self.out.write('\t<shape type="obj">\n') size_x = lamp.data.size size_y = lamp.data.size if lamp.data.shape == 'RECTANGLE': size_y = lamp.data.size_y mts_meshes_dir = os.path.join(self.target_dir, 'meshes') filename = "area_luminaire_%d.obj" % idx
|
def exportLamp(self, lamp, idx): ltype = lamp.data.mitsuba_lamp.type name = translate_id(lamp.data.name) if ltype == 'POINT': self.out.write('\t<luminaire id="%s-light" type="point">\n' % name) mult = lamp.data.mitsuba_lamp.intensity self.exportWorldtrafo(lamp.matrix_world) self.out.write('\t\t<rgb name="intensity" value="%f %f %f"/>\n' % (lamp.data.color.r*mult, lamp.data.color.g*mult, lamp.data.color.b*mult)) self.out.write('\t\t<float name="samplingWeight" value="%f"/>\n' % lamp.data.mitsuba_lamp.samplingWeight) self.out.write('\t</luminaire>\n') elif ltype == 'AREA': self.out.write('\t<shape type="obj">\n') size_x = lamp.data.size size_y = lamp.data.size if lamp.data.shape == 'RECTANGLE': size_y = lamp.data.size_y mts_meshes_dir = os.path.join(self.target_dir, 'meshes') filename = "area_luminaire_%d.obj" % idx
| 476,563
|
def test_get_json_attr_types(self): self.assertEqual(DashboardBundle.get_json_attr_types(), {'test_runs': [TestRun]})
|
def test_get_json_attr_types(self): self.assertEqual(DashboardBundle.get_json_attr_types(), {'test_runs': [TestRun]})
| 476,564
|
def test_construction_1(self): hw_context = HardwareContext() self.assertEqual(context.devices, [])
|
def test_construction_1(self): hw_context = HardwareContext() self.assertEqual(context.devices, [])
| 476,565
|
def test_construction_2(self): devices = object() hw_context = HardwareContext(devices) self.assertTrue(context.devices is devices)
|
def test_construction_2(self): devices = object() hw_context = HardwareContext(devices) self.assertTrue(context.devices is devices)
| 476,566
|
def test_construction_3(self): devices = object() hw_context = HardwareContext(devices=devices) self.assertTrue(context.devices is devices)
|
def test_construction_3(self): devices = object() hw_context = HardwareContext(devices=devices) self.assertTrue(context.devices is devices)
| 476,567
|
def test_get_json_attr_types(self): self.assertEqual(HardwareContext.get_json_attr_types(), {'devices': [HardwareDevice]})
|
def test_get_json_attr_types(self): self.assertEqual(HardwareContext.get_json_attr_types(), {'devices': [HardwareDevice]})
| 476,568
|
def test_device_types(self): self.assertEqual(HardwareDevice.DEVICE_CPU, "device.cpu") self.assertEqual(HardwareDevice.DEVICE_MEM, "device.mem") self.assertEqual(HardwareDevice.DEVICE_USB, "device.usb") self.assertEqual(HardwareDevice.DEVICE_PCI, "device.pci") self.assertEqual(HardwareDevice.DEVICE_BOARD, "device.board")
|
def test_device_types(self): self.assertEqual(HardwareDevice.DEVICE_CPU, "device.cpu") self.assertEqual(HardwareDevice.DEVICE_MEM, "device.mem") self.assertEqual(HardwareDevice.DEVICE_USB, "device.usb") self.assertEqual(HardwareDevice.DEVICE_PCI, "device.pci") self.assertEqual(HardwareDevice.DEVICE_BOARD, "device.board")
| 476,569
|
def test_get_json_attr_types(self): self.assertEqual(SoftwareContext.get_json_attr_types(), {'packages': [SoftwarePackage], 'sw_image': SoftwareImage})
|
def test_get_json_attr_types(self): self.assertEqual(SoftwareContext.get_json_attr_types(), {'packages': [SoftwarePackage], 'sw_image': SoftwareImage})
| 476,570
|
def test_get_json_attr_types(self): self.assertRaises(NotImplementedError, SoftwareImage.get_json_attr_types)
|
def test_get_json_attr_types(self): self.assertRaises(NotImplementedError, SoftwareImage.get_json_attr_types)
| 476,571
|
def test_get_json_attr_types(self): self.assertRaises(NotImplementedError, SoftwarePackage.get_json_attr_types)
|
def test_get_json_attr_types(self): self.assertRaises(NotImplementedError, SoftwarePackage.get_json_attr_types)
| 476,572
|
def test_get_stats(self): test_run = TestRun() for result, count in [ [TestResult.RESULT_PASS, 3], [TestResult.RESULT_FAIL, 5], [TestResult.RESULT_SKIP, 2], [TestResult.RESULT_UNKNOWN, 1]]: for i in range(count): test_run.test_results.append(TestResult(None, result)) stats = test_run.get_stats() self.assertEqual(stats, { TestResult.RESULT.PASS: 3, TestResult.RESULT_FAIL: 5, TestResult.RESULT_SKIP: 2, TestResult.RESULT_UNKNOWN: 1})
|
def test_get_stats(self): test_run = TestRun() for result, count in [ [TestResult.RESULT_PASS, 3], [TestResult.RESULT_FAIL, 5], [TestResult.RESULT_SKIP, 2], [TestResult.RESULT_UNKNOWN, 1]]: for i in range(count): test_run.test_results.append(TestResult(None, result)) stats = test_run.get_stats() self.assertEqual(stats, { TestResult.RESULT_PASS: 3, TestResult.RESULT_FAIL: 5, TestResult.RESULT_SKIP: 2, TestResult.RESULT_UNKNOWN: 1})
| 476,573
|
def _set_test_id(self, test_id): if test_id is not None and not self._TEST_ID_PATTERN.match(test_id): raise ValueError("Test id must be None or a string with reverse domain name") self._test_id = test_id
|
def _set_test_id(self, test_id): if test_id is not None and not self._TEST_ID_PATTERN.match(test_id): raise ValueError("Test id must be None or a string with reverse " "domain name") self._test_id = test_id
| 476,574
|
def __repr__(self): """ Produce more-less human readable encoding of all fields.
|
def __repr__(self): """ Produce more-less human readable encoding of all fields.
| 476,575
|
def __repr__(self): """ Produce more-less human readable encoding of all fields.
|
def __repr__(self): """ Produce more-less human readable encoding of all fields.
| 476,576
|
def _set_timestamp(self, timestamp): if timestamp is not None and not isinstance(timestamp, datetime.datetime): raise TypeError("Timestamp must be None or datetime.datetime() instance") self._timestamp = timestamp
|
def _set_timestamp(self, timestamp): if timestamp is not None and not isinstance(timestamp, datetime.datetime): raise TypeError("Timestamp must be None or datetime.datetime() " "instance") self._timestamp = timestamp
| 476,577
|
def _set_duration(self, duration): if duration is not None and not isinstance(duration, datetime.timedelta): raise TypeError("duration must be None or datetime.timedelta() instance") if duration is not None and duration.days < 0: raise ValueError("duration cannot be negative") self._duration = duration
|
def _set_duration(self, duration): if duration is not None and not isinstance(duration, datetime.timedelta): raise TypeError("duration must be None or datetime.timedelta() " "instance") if duration is not None and duration.days < 0: raise ValueError("duration cannot be negative") self._duration = duration
| 476,578
|
def __cmp__(self, other): return cmp(self.message, other.message) or cmp(self.new_message, self.other_messge)
|
def __cmp__(self, other): return cmp(self.message, other.message) or cmp(self.new_message, self.other_messge)
| 476,579
|
def __str__(self): return ("ValidationError: {0} " "object_expr={1!r}, " "schema_expr={2!r})").format( self.new_message, self.object_expr, self.schema_expr)
|
def __str__(self): return ("ValidationError: {0} " "object_expr={1!r}, " "schema_expr={2!r})").format( self.new_message, self.object_expr, self.schema_expr)
| 476,580
|
def _report_error(self, legacy_message, new_message=None, object_suffix=None, schema_suffix=None): """ Report an error during validation.
|
def _report_error(self, legacy_message, new_message=None, schema_suffix=None): """ Report an error during validation.
| 476,581
|
def _report_error(self, legacy_message, new_message=None, object_suffix=None, schema_suffix=None): """ Report an error during validation.
|
def _report_error(self, legacy_message, new_message=None, object_suffix=None, schema_suffix=None): """ Report an error during validation.
| 476,582
|
def _report_error(self, legacy_message, new_message=None, object_suffix=None, schema_suffix=None): """ Report an error during validation.
|
def _report_error(self, legacy_message, new_message=None, object_suffix=None, schema_suffix=None): """ Report an error during validation.
| 476,583
|
def __init__(self, devices=None): self.devices = devices or []
|
def __init__(self, devices=None): self.devices = devices or []
| 476,584
|
def __init__(self): self.parser = argparse.ArgumentParser( description=""" Command line tool for interacting with Launch Control """, epilog=""" Please report all bugs using the Launchpad bug tracker: http://bugs.launchpad.net/launch-control/+filebug """, add_help=False) self.subparsers = self.parser.add_subparsers(title="Sub-command to invoke") for command_cls in Command.get_subclasses(): sub_parser = self.subparsers.add_parser( command_cls.get_name(), help=command_cls.get_help()) sub_parser.set_defaults(command_cls=command_cls) command_cls.register_arguments(sub_parser)
|
def __init__(self): self.parser = argparse.ArgumentParser( description=""" Command line tool for interacting with Launch Control """, epilog=""" Please report all bugs using the Launchpad bug tracker: http://bugs.launchpad.net/launch-control/+filebug """, add_help=False) self.subparsers = self.parser.add_subparsers( title="Sub-command to invoke") for command_cls in Command.get_subclasses(): sub_parser = self.subparsers.add_parser( command_cls.get_name(), help=command_cls.get_help()) sub_parser.set_defaults(command_cls=command_cls) command_cls.register_arguments(sub_parser)
| 476,585
|
def test_construction_1(self): name = object() sw_image = SoftwareImage(name) self.assertTrue(sw_image.name is name)
|
def test_construction_1(self): name = object() sw_image = SoftwareImage(name) self.assertTrue(sw_image.name is name)
| 476,586
|
def test_allowed_for_anyone(self): with fixtures.created_bundle_streams(self.bundle_streams): pathnames = [bundle_stream.pathname for bundle_stream in BundleStream.objects.allowed_for_anyone().order_by('pathname')] self.assertEqual(pathnames, self.expected_pathnames)
|
def test_allowed_for_anyone(self): with fixtures.created_bundle_streams(self.bundle_streams): pathnames = [bundle_stream.pathname for bundle_stream in BundleStream.objects.allowed_for_anyone().order_by('pathname')] self.assertEqual(pathnames, self.expected_pathnames)
| 476,587
|
def save(self, *args, **kwargs): if self.content: sha1 = hashlib.sha1() for chunk in self.content.chunks(): sha1.update(chunk) self.content_sha1 = sha1.hexdigest() self.content.seek(0) return super(Bundle, self).save(*args, **kwargs)
|
def save(self, *args, **kwargs): if self.content: sha1 = hashlib.sha1() for chunk in self.content.chunks(): sha1.update(chunk) self.content_sha1 = sha1.hexdigest() self.content.seek(0) return super(Bundle, self).save(*args, **kwargs)
| 476,588
|
def pod_attrs(self): """ Return a list of sorted attributes.
|
def pod_attrs(self): """ Return a list of sorted attributes.
| 476,589
|
... def __init__(self, name):
|
... def __init__(self, name):
| 476,590
|
... def name(self):
|
... def name(self):
| 476,591
|
def __repr__(self): """ Produce more-less human readable encoding of all fields.
|
def __repr__(self): """ Produce more-less human readable encoding of all fields.
| 476,592
|
def _fill_args(self, *args, **kwargs): a_out = [] used_kwargs = set() # Walk through all arguments of the original function. Ff the argument # is present in `args' then use it. If we run out of positional # arguments look for keyword arguments with the same name for i, arg_name in enumerate(self._args): # find the argument if i < len(args): # positional arguments get passed as-is arg = args[i] elif arg_name in kwargs: # keyword arguments take over arg = kwargs[arg_name] # also remember we got it from a keyword argument used_kwargs.add(arg_name) else: # otherwise the function defaults kick in # with a yet another fall-back to special DUMMY value arg = self._args_with_defaults.get(arg_name, self.DUMMY) # resolve the argument if arg is self.DEFAULT: if arg_name not in self._args_with_defaults: import sys print >>sys.stderr, "args:", self._args print >>sys.stderr, "args with defaults:", self._args_with_defaults raise ValueError("You passed DEFAULT argument to %s " "which has no default value" % (arg_name,)) arg = self._args_with_defaults[arg_name] elif arg is self.DUMMY: arg = self._get_dummy_for(arg_name) # store the argument a_out.append(arg) # Now check if we have too many / not enough arguments if len(a_out) != len(self._args): raise TypeError("%s takes exactly %d argument, %d given" % ( self._func. len(self._args), len(args))) # Now check keyword arguments for arg_name in kwargs: # Check for duplicate definitions of positional/keyword arguments if arg_name in self._args and arg_name not in used_kwargs: raise TypeError("%s() got multiple values for keyword " "argument '%s'" % (self._func.func_name, arg_name))
|
def _fill_args(self, *args, **kwargs): a_out = [] used_kwargs = set() # Walk through all arguments of the original function. Ff the argument # is present in `args' then use it. If we run out of positional # arguments look for keyword arguments with the same name for i, arg_name in enumerate(self._args): # find the argument if i < len(args): # positional arguments get passed as-is arg = args[i] elif arg_name in kwargs: # keyword arguments take over arg = kwargs[arg_name] # also remember we got it from a keyword argument used_kwargs.add(arg_name) else: # otherwise the function defaults kick in # with a yet another fall-back to special DUMMY value arg = self._args_with_defaults.get(arg_name, self.DUMMY) # resolve the argument if arg is self.DEFAULT: if arg_name not in self._args_with_defaults: import sys print >>sys.stderr, "args:", self._args print >>sys.stderr, "args with defaults:", self._args_with_defaults raise ValueError("You passed DEFAULT argument to %s " "which has no default value" % (arg_name,)) arg = self._args_with_defaults[arg_name] elif arg is self.DUMMY: arg = self._get_dummy_for(arg_name) # store the argument a_out.append(arg) # Now check if we have too many / not enough arguments if len(a_out) != len(self._args): raise TypeError("%s takes exactly %d argument, %d given" % ( self._func, len(self._args), len(args))) # Now check keyword arguments for arg_name in kwargs: # Check for duplicate definitions of positional/keyword arguments if arg_name in self._args and arg_name not in used_kwargs: raise TypeError("%s() got multiple values for keyword " "argument '%s'" % (self._func.func_name, arg_name))
| 476,593
|
def bundles(self, pathname): """ Name ---- `bundles` (`pathname`)
|
def bundles(self, pathname): """ Name ---- `bundles` (`pathname`)
| 476,594
|
def test_deserialize_clears_old_error_on_success(self): BundleDeserializationError.objects.create( bundle = self.bundle, error_message="not important").save() mock = self.mocker.patch(self.bundle) expect(mock._do_deserialize()) self.mocker.replay() self.bundle.deserialize() # note we cannot check for self.bundle.deserialization_error # directly due to the way django handles operations that affect # existing instances (it does not touch them like storm would # IIRC). self.assertRaises( BundleDeserializationError.DoesNotExist, BundleDeserializationError.objects.get, bundle=self.bundle)
|
def test_deserialize_clears_old_error_on_success(self): BundleDeserializationError.objects.create( bundle = self.bundle, error_message="not important").save() mock = self.mocker.patch(self.bundle) expect(mock._do_deserialize()) self.mocker.replay() self.bundle.deserialize() # note we cannot check for self.bundle.deserialization_error # directly due to the way django handles operations that affect # existing instances (it does not touch them like storm would # IIRC). self.assertRaises( BundleDeserializationError.DoesNotExist, BundleDeserializationError.objects.get, bundle=self.bundle)
| 476,595
|
def test_deserialize_clears_old_error_on_success(self): BundleDeserializationError.objects.create( bundle = self.bundle, error_message="not important").save() mock = self.mocker.patch(self.bundle) expect(mock._do_deserialize()) self.mocker.replay() self.bundle.deserialize() # note we cannot check for self.bundle.deserialization_error # directly due to the way django handles operations that affect # existing instances (it does not touch them like storm would # IIRC). self.assertRaises( BundleDeserializationError.DoesNotExist, BundleDeserializationError.objects.get, bundle=self.bundle)
|
def test_deserialize_clears_old_error_on_success(self): BundleDeserializationError.objects.create( bundle = self.bundle, error_message="not important").save() mock = self.mocker.patch(self.bundle) expect(mock._do_deserialize()) self.mocker.replay() self.bundle.deserialize() # note we cannot check for self.bundle.deserialization_error # directly due to the way django handles operations that affect # existing instances (it does not touch them like storm would # IIRC). self.assertRaises( BundleDeserializationError.DoesNotExist, BundleDeserializationError.objects.get, bundle=self.bundle)
| 476,596
|
def test_deserialize_clears_old_error_on_success(self): BundleDeserializationError.objects.create( bundle = self.bundle, error_message="not important").save() mock = self.mocker.patch(self.bundle) expect(mock._do_deserialize()) self.mocker.replay() self.bundle.deserialize() # note we cannot check for self.bundle.deserialization_error # directly due to the way django handles operations that affect # existing instances (it does not touch them like storm would # IIRC). self.assertRaises( BundleDeserializationError.DoesNotExist, BundleDeserializationError.objects.get, bundle=self.bundle)
|
def test_deserialize_clears_old_error_on_success(self): BundleDeserializationError.objects.create( bundle = self.bundle, error_message="not important").save() mock = self.mocker.patch(self.bundle) expect(mock._do_deserialize()) self.mocker.replay() self.bundle.deserialize() # note we cannot check for self.bundle.deserialization_error # directly due to the way django handles operations that affect # existing instances (it does not touch them like storm would # IIRC). self.assertRaises( BundleDeserializationError.DoesNotExist, BundleDeserializationError.objects.get, bundle=self.bundle)
| 476,597
|
def test_deserialize_clears_old_error_on_success(self): BundleDeserializationError.objects.create( bundle = self.bundle, error_message="not important").save() mock = self.mocker.patch(self.bundle) expect(mock._do_deserialize()) self.mocker.replay() self.bundle.deserialize() # note we cannot check for self.bundle.deserialization_error # directly due to the way django handles operations that affect # existing instances (it does not touch them like storm would # IIRC). self.assertRaises( BundleDeserializationError.DoesNotExist, BundleDeserializationError.objects.get, bundle=self.bundle)
|
def test_deserialize_clears_old_error_on_success(self): BundleDeserializationError.objects.create( bundle = self.bundle, error_message="not important").save() mock = self.mocker.patch(self.bundle) expect(mock._do_deserialize()) self.mocker.replay() self.bundle.deserialize() # note we cannot check for self.bundle.deserialization_error # directly due to the way django handles operations that affect # existing instances (it does not touch them like storm would # IIRC). self.assertRaises( BundleDeserializationError.DoesNotExist, BundleDeserializationError.objects.get, bundle=self.bundle)
| 476,598
|
def test_deserialize_clears_old_error_on_success(self): BundleDeserializationError.objects.create( bundle = self.bundle, error_message="not important").save() mock = self.mocker.patch(self.bundle) expect(mock._do_deserialize()) self.mocker.replay() self.bundle.deserialize() # note we cannot check for self.bundle.deserialization_error # directly due to the way django handles operations that affect # existing instances (it does not touch them like storm would # IIRC). self.assertRaises( BundleDeserializationError.DoesNotExist, BundleDeserializationError.objects.get, bundle=self.bundle)
|
def test_deserialize_clears_old_error_on_success(self): BundleDeserializationError.objects.create( bundle = self.bundle, error_message="not important").save() mock = self.mocker.patch(self.bundle) expect(mock._do_deserialize()) self.mocker.replay() self.bundle.deserialize() # note we cannot check for self.bundle.deserialization_error # directly due to the way django handles operations that affect # existing instances (it does not touch them like storm would # IIRC). self.assertRaises( BundleDeserializationError.DoesNotExist, BundleDeserializationError.objects.get, bundle=self.bundle)
| 476,599
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.