def generate_response(chaldict,uri,username,passwd,method='<STR_LIT:GET>',cnonce=None):
authdict = {} <EOL>qop = dict_fetch(chaldict,'<STR_LIT>')<EOL>domain = dict_fetch(chaldict,'<STR_LIT>')<EOL>nonce = dict_fetch(chaldict,'<STR_LIT>')<EOL>stale = dict_fetch(chaldict,'<STR_LIT>')<EOL>algorithm = dict_fetch(chaldict,'<STR_LIT>','<STR_LIT>')<EOL>realm = dict_fetch(chaldict,'<STR_LIT>','<STR_LIT>')<EOL>opaque = dict_fetch(chaldict,'<STR_LIT>')<EOL>nc = "<STR_LIT>"<EOL>if not cnonce:<EOL><INDENT>cnonce = H(str(random.randint(<NUM_LIT:0>,<NUM_LIT>)))[:<NUM_LIT:16>]<EOL><DEDENT>if algorithm.lower()=='<STR_LIT>':<EOL><INDENT>a1 = A1(username,realm,passwd,nonce,cnonce)<EOL><DEDENT>else:<EOL><INDENT>a1 = A1(username,realm,passwd)<EOL><DEDENT>a2 = A2(method,uri)<EOL>secret = H(a1)<EOL>data = '<STR_LIT>' % (nonce,nc,cnonce,qop,H(a2))<EOL>authdict['<STR_LIT:username>'] = '<STR_LIT>' % username<EOL>authdict['<STR_LIT>'] = '<STR_LIT>' % realm<EOL>authdict['<STR_LIT>'] = '<STR_LIT>' % nonce<EOL>authdict['<STR_LIT>'] = '<STR_LIT>' % uri<EOL>authdict['<STR_LIT>'] = '<STR_LIT>' % KD(secret,data)<EOL>authdict['<STR_LIT>'] = '<STR_LIT>' % qop<EOL>authdict['<STR_LIT>'] = nc<EOL>authdict['<STR_LIT>'] = '<STR_LIT>' % cnonce<EOL>return authdict<EOL>
Generate an authorization response dictionary. chaldict should contain the digest
challenge in dict form. Use fetch_challenge to create a chaldict from a HTTPResponse
object like this: fetch_challenge(res.getheaders()).

returns dict (the authdict)

Note. Use build_authorization_arg() to turn an authdict into the final Authorization
header value.