#NEWLINE# def process_handshake_header( self , headers ) : #NEWLINE# #INDENT# "\n        Read the upgrade handshake's response headers and\n        validate them against :rfc:`6455`.\n        " #NEWLINE# protocols = [ ] #NEWLINE# extensions = [ ] #NEWLINE# headers = headers . strip ( ) #NEWLINE# for header_line in headers . split ( b'\r\n' ) : #NEWLINE# #INDENT# ( header , value ) = header_line . split ( b':' , 1 ) #NEWLINE# header = header . strip ( ) . lower ( ) #NEWLINE# value = value . strip ( ) . lower ( ) #NEWLINE# if ( ( headers == b'upgrade' ) and ( value != b'websocket' ) ) : #NEWLINE# #INDENT# raise HandshakeError ( ( 'Invalid Upgrade header: %s' % value ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( header == b'connection' ) and ( value != b'upgrade' ) ) : #NEWLINE# #INDENT# raise HandshakeError ( ( 'Invalid Connection header: %s' % value ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( header == b'sec-websocket-accept' ) : #NEWLINE# #INDENT# match = b64encode ( sha1 ( ( self . key + WS_KEY ) ) . digest ( ) ) #NEWLINE# if ( value != match . lower ( ) ) : #NEWLINE# #INDENT# raise HandshakeError ( ( 'Invalid challenge response: %s' % value ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( header == b'sec-websocket-protocol' ) : #NEWLINE# #INDENT# protocols = ',' . join ( value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( header == b'sec-websocket-extensions' ) : #NEWLINE# #INDENT# extensions = ',' . join ( value ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return ( protocols , extensions )