<s> HANDLERS = ( "<STR_LIT>" , ) <EOL> class AuthenticationMiddleware : <EOL> def process_request ( self , request ) : <EOL> """<STR_LIT>""" <EOL> request . auth_type = None <EOL> http_authorization = request . META . get ( "<STR_LIT>" , None ) <EOL> if not http_authorization : <EOL> return <EOL> auth = http_authorization . split ( ) <EOL> self . auth_type = auth [ <NUM_LIT:0> ] . lower ( ) <EOL> self . auth_value = "<STR_LIT:U+0020>" . join ( auth [ <NUM_LIT:1> : ] ) . strip ( ) <EOL> request . auth_type = self . auth_type <EOL> self . validate_auth_type ( ) <EOL> if not self . handler_name : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . load_handler ( ) <EOL> response = self . handler . validate ( self . auth_value , request ) <EOL> if response is not None : <EOL> return response <EOL> request . access_token = self . handler . access_token ( self . auth_value , request ) <EOL> request . user = self . handler . authenticate ( self . auth_value , request ) <EOL> def load_handler ( self ) : <EOL> """<STR_LIT>""" <EOL> handler_path = self . handler_name . split ( "<STR_LIT:.>" ) <EOL> handler_module = __import__ ( "<STR_LIT:.>" . join ( handler_path [ : - <NUM_LIT:1> ] ) , { } , { } , str ( handler_path [ - <NUM_LIT:1> ] ) ) <EOL> self . handler = getattr ( handler_module , handler_path [ - <NUM_LIT:1> ] ) ( ) <EOL> def validate_auth_type ( self ) : <EOL> """<STR_LIT>""" <EOL> for handler in HANDLERS : <EOL> handler_type = handler . split ( "<STR_LIT:.>" ) [ - <NUM_LIT:2> ] <EOL> if handler_type == self . auth_type : <EOL> self . handler_name = handler <EOL> return <EOL> self . handler_name = None </s>
