<s> '''<STR_LIT>''' <EOL> import base64 <EOL> def basic_auth ( auth_func , after_login_func = lambda * args , ** kwargs : None , <EOL> realm = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> def basic_auth_decorator ( handler_class ) : <EOL> '''<STR_LIT>''' <EOL> def wrap_execute ( handler_execute ) : <EOL> '''<STR_LIT>''' <EOL> def require_basic_auth ( handler , kwargs ) : <EOL> '''<STR_LIT>''' <EOL> def create_auth_header ( ) : <EOL> '''<STR_LIT>''' <EOL> handler . set_status ( <NUM_LIT> ) <EOL> handler . set_header ( '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( realm ) ) <EOL> handler . _transforms = [ ] <EOL> handler . finish ( ) <EOL> auth_header = handler . request . headers . get ( '<STR_LIT>' ) <EOL> if auth_header is None or not auth_header . startswith ( '<STR_LIT>' ) : <EOL> create_auth_header ( ) <EOL> return <EOL> auth_decoded = base64 . decodestring ( auth_header [ <NUM_LIT:6> : ] ) <EOL> user , pwd = auth_decoded . split ( '<STR_LIT::>' , <NUM_LIT:2> ) <EOL> if auth_func ( user , pwd ) : <EOL> after_login_func ( handler , kwargs , user , pwd ) <EOL> else : <EOL> create_auth_header ( ) <EOL> def _execute ( self , transforms , * args , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> require_basic_auth ( self , kwargs ) <EOL> return handler_execute ( self , transforms , * args , ** kwargs ) <EOL> return _execute <EOL> handler_class . _execute = wrap_execute ( handler_class . _execute ) <EOL> return handler_class <EOL> return basic_auth_decorator </s>
