Example #1
0
 def _real_connect(self, addr, connect_ex):
     if self.server_side:
         raise ValueError("can't connect in server-side mode")
     # Here we assume that the socket is client-side, and not
     # connected at the time of the call.  We connect it, then wrap it.
     if self._connected:
         raise ValueError("attempt to connect already-connected SSLSocket!")
     self._sslobj = self._context._wrap_socket(self._sock, False,
                                               self.server_hostname)
     if self._session is not None:  # 3.6+
         self._sslobj = _SSLObject_factory(self._sslobj,
                                           owner=self,
                                           session=self._session)
     try:
         if connect_ex:
             rc = socket.connect_ex(self, addr)
         else:
             rc = None
             socket.connect(self, addr)
         if not rc:
             if self.do_handshake_on_connect:
                 self.do_handshake()
             self._connected = True
         return rc
     except socket_error:
         self._sslobj = None
         raise
Example #2
0
 def _real_connect(self, addr, connect_ex):
     if self.server_side:
         raise ValueError("can't connect in server-side mode")
     # Here we assume that the socket is client-side, and not
     # connected at the time of the call.  We connect it, then wrap it.
     if self._connected:
         raise ValueError("attempt to connect already-connected SSLSocket!")
     self._sslobj = self.context._wrap_socket(self, False, self.server_hostname)
     try:
         if connect_ex:
             rc = socket.connect_ex(self, addr)
         else:
             rc = None
             socket.connect(self, addr)
         if not rc:
             if self.do_handshake_on_connect:
                 self.do_handshake()
             self._connected = True
         return rc
     except socket_error:
         self._sslobj = None
         raise