def extract_http_basic_credentials(request):
 authorization = request.headers.get('Authorization')
 if (not authorization):
  return None
 try:
  (authmeth, auth) = authorization.split(' ', 1)
 except ValueError:
  return None
 if (authmeth.lower() != 'basic'):
  return None
 try:
  authbytes = b64decode(auth.strip())
 except (TypeError, binascii.Error):
  return None
 try:
  auth = authbytes.decode('utf-8')
 except UnicodeDecodeError:
  auth = authbytes.decode('latin-1')
 try:
  (username, password) = auth.split(':', 1)
 except ValueError:
  return None
 return HTTPBasicCredentials(username, password)

def extract_http_basic_credentials ( request ) : authorization = request . headers . get ( 'Authorization' ) if ( not authorization ) : return None try : ( authmeth , auth ) = authorization . split ( ' ' , 1 ) except ValueError : return None if ( authmeth . lower ( ) != 'basic' ) : return None try : authbytes = b64decode ( auth . strip ( ) ) except ( TypeError , binascii . Error ) : return None try : auth = authbytes . decode ( 'utf-8' ) except UnicodeDecodeError : auth = authbytes . decode ( 'latin-1' ) try : ( username , password ) = auth . split ( ':' , 1 ) except ValueError : return None return HTTPBasicCredentials ( username , password )
a helper function for extraction of http basic credentials from a given :term:request .