def _get_user_via_basic_auth(auth_header):
 try:
  creds = binascii.a2b_base64(auth_header[len('Basic '):]).split(':', 1)
 except binascii.Error:
  raise Response(400, 'Malformed "Authorization" header')
 if (len(creds) != 2):
  raise Response(401)
 (userid, api_key) = creds
 if ((len(userid) == 36) and ('-' in userid)):
  user = _get_user_via_api_key(userid)
 else:
  try:
   userid = int(userid)
  except ValueError:
   raise Response(401)
  user = User.from_id(userid)
  if (user.ANON or (not constant_time_compare(user.participant.api_key, api_key))):
   raise Response(401)
 return user

def _get_user_via_basic_auth ( auth_header ) : try : creds = binascii . a2b_base64 ( auth_header [ len ( 'Basic ' ) : ] ) . split ( ':' , 1 ) except binascii . Error : raise Response ( 400 , 'Malformed "Authorization" header' ) if ( len ( creds ) != 2 ) : raise Response ( 401 ) ( userid , api_key ) = creds if ( ( len ( userid ) == 36 ) and ( '-' in userid ) ) : user = _get_user_via_api_key ( userid ) else : try : userid = int ( userid ) except ValueError : raise Response ( 401 ) user = User . from_id ( userid ) if ( user . ANON or ( not constant_time_compare ( user . participant . api_key , api_key ) ) ) : raise Response ( 401 ) return user
given a basic auth header .