#NEWLINE# def _gen_response( self , charset , realm , nonce ) : #NEWLINE# #INDENT# '\n        Generate response-value.\n\n        Creates a response to a challenge according to section 2.1.2.1 of\n        RFC 2831 using the L{charset}, L{realm} and L{nonce} directives\n        from the challenge.\n        ' #NEWLINE# def H( s ) : #NEWLINE# #INDENT# return md5 ( s ) . digest ( ) #NEWLINE# #UNINDENT# def HEX( n ) : #NEWLINE# #INDENT# return binascii . b2a_hex ( n ) #NEWLINE# #UNINDENT# def KD( k , s ) : #NEWLINE# #INDENT# return H ( ( '%s:%s' % ( k , s ) ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# username = self . username . encode ( charset ) #NEWLINE# password = self . password . encode ( charset ) #NEWLINE# #UNINDENT# except UnicodeError : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# nc = ( '%08x' % 1 ) #NEWLINE# cnonce = self . _gen_nonce ( ) #NEWLINE# qop = 'auth' #NEWLINE# a1 = ( '%s:%s:%s' % ( H ( ( '%s:%s:%s' % ( username , realm , password ) ) ) , nonce , cnonce ) ) #NEWLINE# a2 = ( 'AUTHENTICATE:%s' % self . digest_uri ) #NEWLINE# response = HEX ( KD ( HEX ( H ( a1 ) ) , ( '%s:%s:%s:%s:%s' % ( nonce , nc , cnonce , 'auth' , HEX ( H ( a2 ) ) ) ) ) ) #NEWLINE# directives = { #NEWLINE# #INDENT# 'username' : username , #NEWLINE# 'realm' : realm , #NEWLINE# 'nonce' : nonce , #NEWLINE# 'cnonce' : cnonce , #NEWLINE# 'nc' : nc , #NEWLINE# 'qop' : qop , #NEWLINE# 'digest-uri' : self . digest_uri , #NEWLINE# 'response' : response , #NEWLINE# 'charset' : charset , #NEWLINE# #UNINDENT# } #NEWLINE# return self . _unparse ( directives )