def _parse_www_authenticate(headers, headername='www-authenticate'):
 retval = {}
 if headers.has_key(headername):
  try:
   authenticate = headers[headername].strip()
   www_auth = ((USE_WWW_AUTH_STRICT_PARSING and WWW_AUTH_STRICT) or WWW_AUTH_RELAXED)
   while authenticate:
    if (headername == 'authentication-info'):
     (auth_scheme, the_rest) = ('digest', authenticate)
    else:
     (auth_scheme, the_rest) = authenticate.split(' ', 1)
    match = www_auth.search(the_rest)
    auth_params = {}
    while match:
     if (match and (len(match.groups()) == 3)):
      (key, value, the_rest) = match.groups()
      auth_params[key.lower()] = UNQUOTE_PAIRS.sub('\\1', value)
     match = www_auth.search(the_rest)
    retval[auth_scheme.lower()] = auth_params
    authenticate = the_rest.strip()
  except ValueError:
   raise MalformedHeader('WWW-Authenticate')
 return retval

def _parse_www_authenticate ( headers , headername = 'www-authenticate' ) : retval = { } if headers . has_key ( headername ) : try : authenticate = headers [ headername ] . strip ( ) www_auth = ( ( USE_WWW_AUTH_STRICT_PARSING and WWW_AUTH_STRICT ) or WWW_AUTH_RELAXED ) while authenticate : if ( headername == 'authentication-info' ) : ( auth_scheme , the_rest ) = ( 'digest' , authenticate ) else : ( auth_scheme , the_rest ) = authenticate . split ( ' ' , 1 ) match = www_auth . search ( the_rest ) auth_params = { } while match : if ( match and ( len ( match . groups ( ) ) == 3 ) ) : ( key , value , the_rest ) = match . groups ( ) auth_params [ key . lower ( ) ] = UNQUOTE_PAIRS . sub ( '\\1' , value ) match = www_auth . search ( the_rest ) retval [ auth_scheme . lower ( ) ] = auth_params authenticate = the_rest . strip ( ) except ValueError : raise MalformedHeader ( 'WWW-Authenticate' ) return retval
returns a dictionary of dictionaries .