#NEWLINE# def connect( self ) : #NEWLINE# #INDENT# '\n        Connects this websocket and starts the upgrade handshake\n        with the remote endpoint.\n        ' #NEWLINE# if ( self . scheme == 'wss' ) : #NEWLINE# #INDENT# self . sock = ssl . wrap_socket ( self . sock , ** self . ssl_options ) #NEWLINE# self . _is_secure = True #NEWLINE# #UNINDENT# self . sock . connect ( self . bind_addr ) #NEWLINE# self . _write ( self . handshake_request ) #NEWLINE# response = b'' #NEWLINE# doubleCLRF = b'\r\n\r\n' #NEWLINE# while True : #NEWLINE# #INDENT# bytes = self . sock . recv ( 128 ) #NEWLINE# if ( not bytes ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# response += bytes #NEWLINE# if ( doubleCLRF in response ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# if ( not response ) : #NEWLINE# #INDENT# self . close_connection ( ) #NEWLINE# raise HandshakeError ( 'Invalid response' ) #NEWLINE# #UNINDENT# ( headers , _ , body ) = response . partition ( doubleCLRF ) #NEWLINE# ( response_line , _ , headers ) = headers . partition ( b'\r\n' ) #NEWLINE# try : #NEWLINE# #INDENT# self . process_response_line ( response_line ) #NEWLINE# ( self . protocols , self . extensions ) = self . process_handshake_header ( headers ) #NEWLINE# #UNINDENT# except HandshakeError : #NEWLINE# #INDENT# self . close_connection ( ) #NEWLINE# raise #NEWLINE# #UNINDENT# self . handshake_ok ( ) #NEWLINE# if body : #NEWLINE# #INDENT# self . process ( body )