<s> """<STR_LIT>""" <EOL> import os <EOL> from google . appengine . api import apiproxy_stub_map <EOL> from google . appengine . api import user_service_pb <EOL> from google . appengine . runtime import apiproxy_errors <EOL> class Error ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class UserNotFoundError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class RedirectTooLongError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class NotAllowedError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class User ( object ) : <EOL> """<STR_LIT>""" <EOL> __user_id = None <EOL> def __init__ ( self , email = None , _auth_domain = None , _user_id = None ) : <EOL> """<STR_LIT>""" <EOL> if _auth_domain is None : <EOL> _auth_domain = os . environ . get ( '<STR_LIT>' ) <EOL> else : <EOL> assert email is not None <EOL> assert _auth_domain <EOL> if email is None : <EOL> assert '<STR_LIT>' in os . environ <EOL> email = os . environ [ '<STR_LIT>' ] <EOL> if _user_id is None and '<STR_LIT>' in os . environ : <EOL> _user_id = os . environ [ '<STR_LIT>' ] <EOL> if not email : <EOL> raise UserNotFoundError <EOL> self . __email = email <EOL> self . __auth_domain = _auth_domain <EOL> self . __user_id = _user_id or None <EOL> def nickname ( self ) : <EOL> """<STR_LIT>""" <EOL> if ( self . __email and self . __auth_domain and <EOL> self . __email . endswith ( '<STR_LIT:@>' + self . __auth_domain ) ) : <EOL> suffix_len = len ( self . __auth_domain ) + <NUM_LIT:1> <EOL> return self . __email [ : - suffix_len ] <EOL> else : <EOL> return self . __email <EOL> def email ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __email <EOL> def user_id ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __user_id <EOL> def auth_domain ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __auth_domain <EOL> def __unicode__ ( self ) : <EOL> return unicode ( self . nickname ( ) ) <EOL> def __str__ ( self ) : <EOL> return str ( self . nickname ( ) ) <EOL> def __repr__ ( self ) : <EOL> if self . __user_id : <EOL> return "<STR_LIT>" % ( self . email ( ) , <EOL> self . user_id ( ) ) <EOL> else : <EOL> return "<STR_LIT>" % self . email ( ) <EOL> def __hash__ ( self ) : <EOL> return hash ( ( self . __email , self . __auth_domain ) ) <EOL> def __cmp__ ( self , other ) : <EOL> if not isinstance ( other , User ) : <EOL> return NotImplemented <EOL> return cmp ( ( self . __email , self . __auth_domain ) , <EOL> ( other . __email , other . __auth_domain ) ) <EOL> def create_login_url ( dest_url , _auth_domain = None ) : <EOL> """<STR_LIT>""" <EOL> req = user_service_pb . CreateLoginURLRequest ( ) <EOL> resp = user_service_pb . CreateLoginURLResponse ( ) <EOL> req . set_destination_url ( dest_url ) <EOL> if _auth_domain : <EOL> req . set_auth_domain ( _auth_domain ) <EOL> try : <EOL> apiproxy_stub_map . MakeSyncCall ( '<STR_LIT:user>' , '<STR_LIT>' , req , resp ) <EOL> except apiproxy_errors . ApplicationError , e : <EOL> if ( e . application_error == <EOL> user_service_pb . UserServiceError . REDIRECT_URL_TOO_LONG ) : <EOL> raise RedirectTooLongError <EOL> elif ( e . application_error == <EOL> user_service_pb . UserServiceError . NOT_ALLOWED ) : <EOL> raise NotAllowedError <EOL> else : <EOL> raise e <EOL> return resp . login_url ( ) <EOL> CreateLoginURL = create_login_url <EOL> def create_logout_url ( dest_url , _auth_domain = None ) : <EOL> """<STR_LIT>""" <EOL> req = user_service_pb . CreateLogoutURLRequest ( ) <EOL> resp = user_service_pb . CreateLogoutURLResponse ( ) <EOL> req . set_destination_url ( dest_url ) <EOL> if _auth_domain : <EOL> req . set_auth_domain ( _auth_domain ) <EOL> try : <EOL> apiproxy_stub_map . MakeSyncCall ( '<STR_LIT:user>' , '<STR_LIT>' , req , resp ) <EOL> except apiproxy_errors . ApplicationError , e : <EOL> if ( e . application_error == <EOL> user_service_pb . UserServiceError . REDIRECT_URL_TOO_LONG ) : <EOL> raise RedirectTooLongError <EOL> else : <EOL> raise e <EOL> return resp . logout_url ( ) <EOL> CreateLogoutURL = create_logout_url <EOL> def get_current_user ( ) : <EOL> try : <EOL> return User ( ) <EOL> except UserNotFoundError : <EOL> return None <EOL> GetCurrentUser = get_current_user <EOL> def is_current_user_admin ( ) : <EOL> """<STR_LIT>""" <EOL> return ( os . environ . get ( '<STR_LIT>' , '<STR_LIT:0>' ) ) == '<STR_LIT:1>' <EOL> IsCurrentUserAdmin = is_current_user_admin </s>
