#NEWLINE# def _connect( self , certificate , private_key , passphrase = None ) : #NEWLINE# #INDENT# '\n        Establishes an encrypted SSL socket connection to the service.\n        After connecting the socket can be written to or read from.\n        ' #NEWLINE# sock = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) #NEWLINE# cert = OpenSSL . crypto . load_certificate ( OpenSSL . crypto . FILETYPE_PEM , sock ) #NEWLINE# args = [ OpenSSL . crypto . FILETYPE_PEM , private_key ] #NEWLINE# if ( passphrase is not None ) : #NEWLINE# #INDENT# args . append ( str ( passphrase ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# pkey = OpenSSL . crypto . load_privatekey ( * args ) #NEWLINE# #UNINDENT# except OpenSSL . crypto . Error : #NEWLINE# #INDENT# raise InvalidPassPhrase #NEWLINE# #UNINDENT# context = OpenSSL . SSL . Context ( OpenSSL . SSL . TLSv1_METHOD ) #NEWLINE# context . use_certificate ( cert ) #NEWLINE# context . use_privatekey ( pkey ) #NEWLINE# if GEVENT_OPEN_SSL : #NEWLINE# #INDENT# self . connection = gevent_openssl . SSL . Connection ( context , sock ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . connection = OpenSSL . SSL . Connection ( context , sock ) #NEWLINE# #UNINDENT# self . connection . connect ( ( self . hostname , self . PORT ) ) #NEWLINE# self . connection . set_connect_state ( ) #NEWLINE# self . connection . do_handshake ( )