MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / connect

Method connect

src/socks/__init__.py:391–450  ·  view source on GitHub ↗

connect(self, despair) Connects to the specified destination through a proxy. destpar - A tuple of the IP/DNS address and the port number. (identical to socket's connect). To select the proxy server use setproxy().

(self, destpair)

Source from the content-addressed store, hash-verified

389 self.__proxypeername = (addr, destport)
390
391 def connect(self, destpair):
392 """connect(self, despair)
393 Connects to the specified destination through a proxy.
394 destpar - A tuple of the IP/DNS address and the port number.
395 (identical to socket's connect).
396 To select the proxy server use setproxy().
397 """
398 # Do a minimal input check first
399 if (not type(destpair) in (list,tuple)) or (len(destpair) < 2) or (type(destpair[0]) != type('')) or (type(destpair[1]) != int):
400 raise GeneralProxyError((5, _generalerrors[5]))
401 if self.__proxy[0] == PROXY_TYPE_SOCKS5:
402 if self.__proxy[2] != None:
403 portnum = self.__proxy[2]
404 else:
405 portnum = 1080
406 try:
407 _orgsocket.connect(self, (self.__proxy[1], portnum))
408 except socket.error as e:
409 # ENETUNREACH, WSAENETUNREACH
410 if e[0] in [101, 10051]:
411 raise GeneralProxyError((7, _generalerrors[7]))
412 # ECONNREFUSED, WSAECONNREFUSED
413 if e[0] in [111, 10061]:
414 raise GeneralProxyError((8, _generalerrors[8]))
415 # EHOSTUNREACH, WSAEHOSTUNREACH
416 if e[0] in [113, 10065]:
417 raise GeneralProxyError((9, _generalerrors[9]))
418 raise
419 self.__negotiatesocks5()
420 self.__connectsocks5(destpair[0], destpair[1])
421 elif self.__proxy[0] == PROXY_TYPE_SOCKS4:
422 if self.__proxy[2] != None:
423 portnum = self.__proxy[2]
424 else:
425 portnum = 1080
426 _orgsocket.connect(self,(self.__proxy[1], portnum))
427 self.__negotiatesocks4(destpair[0], destpair[1])
428 elif self.__proxy[0] == PROXY_TYPE_HTTP:
429 if self.__proxy[2] != None:
430 portnum = self.__proxy[2]
431 else:
432 portnum = 8080
433 try:
434 _orgsocket.connect(self,(self.__proxy[1], portnum))
435 except socket.error as e:
436 # ENETUNREACH, WSAENETUNREACH
437 if e[0] in [101, 10051]:
438 raise GeneralProxyError((7, _generalerrors[7]))
439 # ECONNREFUSED, WSAECONNREFUSED
440 if e[0] in [111, 10061]:
441 raise GeneralProxyError((8, _generalerrors[8]))
442 # EHOSTUNREACH, WSAEHOSTUNREACH
443 if e[0] in [113, 10065]:
444 raise GeneralProxyError((9, _generalerrors[9]))
445 raise
446 self.__negotiatehttp(destpair[0], destpair[1])
447 elif self.__proxy[0] == None:
448 _orgsocket.connect(self, (destpair[0], destpair[1]))

Callers 15

bloomfiltertest.pyFile · 0.45
check_sqliteFunction · 0.45
queryServerMethod · 0.45
runMethod · 0.45
runMethod · 0.45
stopThreadMethod · 0.45
stopThreadMethod · 0.45
getLocalIPMethod · 0.45
stopThreadMethod · 0.45
resolveMethod · 0.45
setupUiMethod · 0.45

Calls 5

__negotiatesocks5Method · 0.95
__connectsocks5Method · 0.95
__negotiatesocks4Method · 0.95
__negotiatehttpMethod · 0.95
GeneralProxyErrorClass · 0.70

Tested by

no test coverage detected