MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / connect

Method connect

lib/speed.py:469–515  ·  view source on GitHub ↗

Connect to a host on a given (SSL) port.

(self)

Source from the content-addressed store, hash-verified

467 self.source_address = source_address
468
469 def connect(self):
470 "Connect to a host on a given (SSL) port."
471 try:
472 self.sock = socket.create_connection(
473 (self.host, self.port),
474 self.timeout,
475 self.source_address
476 )
477 except (AttributeError, TypeError):
478 self.sock = create_connection(
479 (self.host, self.port),
480 self.timeout,
481 self.source_address
482 )
483
484 if self._tunnel_host:
485 self._tunnel()
486
487 if ssl:
488 try:
489 kwargs = {}
490 if hasattr(ssl, 'SSLContext'):
491 if self._tunnel_host:
492 kwargs['server_hostname'] = self._tunnel_host
493 else:
494 kwargs['server_hostname'] = self.host
495 self.sock = self._context.wrap_socket(self.sock, **kwargs)
496 except AttributeError:
497 self.sock = ssl.wrap_socket(self.sock)
498 try:
499 self.sock.server_hostname = self.host
500 except AttributeError:
501 pass
502 elif FakeSocket:
503 # Python 2.4/2.5 support
504 try:
505 self.sock = FakeSocket(self.sock, socket.ssl(self.sock))
506 except AttributeError:
507 raise SpeedtestException(
508 'This version of Python does not support HTTPS/SSL '
509 'functionality'
510 )
511 else:
512 raise SpeedtestException(
513 'This version of Python does not support HTTPS/SSL '
514 'functionality'
515 )
516
517
518def _build_connection(connection, source_address, timeout, context=None):

Callers

nothing calls this directly

Calls 2

create_connectionFunction · 0.85
SpeedtestExceptionClass · 0.85

Tested by

no test coverage detected