def parse_authorization_header(value):
 if (not value):
  return
 try:
  (auth_type, auth_info) = value.split(None, 1)
  auth_type = auth_type.lower()
 except ValueError:
  return
 if (auth_type == 'basic'):
  try:
   (username, password) = auth_info.decode('base64').split(':', 1)
  except Exception as e:
   return
  return Authorization('basic', {'username': username, 'password': password})
 elif (auth_type == 'digest'):
  auth_map = parse_dict_header(auth_info)
  for key in ('username', 'realm', 'nonce', 'uri', 'response'):
   if (not (key in auth_map)):
    return
  if ('qop' in auth_map):
   if ((not auth_map.get('nc')) or (not auth_map.get('cnonce'))):
    return
  return Authorization('digest', auth_map)

def parse_authorization_header ( value ) : if ( not value ) : return try : ( auth_type , auth_info ) = value . split ( None , 1 ) auth_type = auth_type . lower ( ) except ValueError : return if ( auth_type == 'basic' ) : try : ( username , password ) = auth_info . decode ( 'base64' ) . split ( ':' , 1 ) except Exception as e : return return Authorization ( 'basic' , { 'username' : username , 'password' : password } ) elif ( auth_type == 'digest' ) : auth_map = parse_dict_header ( auth_info ) for key in ( 'username' , 'realm' , 'nonce' , 'uri' , 'response' ) : if ( not ( key in auth_map ) ) : return if ( 'qop' in auth_map ) : if ( ( not auth_map . get ( 'nc' ) ) or ( not auth_map . get ( 'cnonce' ) ) ) : return return Authorization ( 'digest' , auth_map )
parse an oauth authorization header into a list of 2-tuples .