<s> """<STR_LIT>""" <EOL> import logging <EOL> import os <EOL> import urllib <EOL> import urlparse <EOL> from google . appengine . api import apiproxy_stub <EOL> from google . appengine . api import user_service_pb <EOL> if os . environ . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> from google . appengine . runtime import apiproxy_errors <EOL> else : <EOL> from google . appengine . runtime import apiproxy_errors <EOL> _DEFAULT_LOGIN_URL = '<STR_LIT>' <EOL> _DEFAULT_LOGOUT_URL = '<STR_LIT>' <EOL> _DEFAULT_AUTH_DOMAIN = '<STR_LIT>' <EOL> _OAUTH_CONSUMER_KEY = '<STR_LIT>' <EOL> _OAUTH_EMAIL = '<STR_LIT>' <EOL> _OAUTH_USER_ID = '<STR_LIT:0>' <EOL> _OAUTH_AUTH_DOMAIN = _DEFAULT_AUTH_DOMAIN <EOL> _OAUTH_CLIENT_ID = '<STR_LIT>' <EOL> _OPENID_DEPRECATION_WARNING = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> class UserServiceStub ( apiproxy_stub . APIProxyStub ) : <EOL> """<STR_LIT>""" <EOL> _ACCEPTS_REQUEST_ID = True <EOL> THREADSAFE = True <EOL> def __init__ ( self , <EOL> login_url = _DEFAULT_LOGIN_URL , <EOL> logout_url = _DEFAULT_LOGOUT_URL , <EOL> service_name = '<STR_LIT:user>' , <EOL> auth_domain = _DEFAULT_AUTH_DOMAIN , <EOL> request_data = None ) : <EOL> """<STR_LIT>""" <EOL> super ( UserServiceStub , self ) . __init__ ( service_name , <EOL> request_data = request_data ) <EOL> self . _login_url = login_url <EOL> self . _logout_url = logout_url <EOL> self . __scopes = None <EOL> self . SetOAuthUser ( is_admin = ( os . environ . get ( '<STR_LIT>' , '<STR_LIT:0>' ) == '<STR_LIT:1>' ) ) <EOL> os . environ [ '<STR_LIT>' ] = auth_domain <EOL> def SetOAuthUser ( self , <EOL> email = _OAUTH_EMAIL , <EOL> domain = _OAUTH_AUTH_DOMAIN , <EOL> user_id = _OAUTH_USER_ID , <EOL> is_admin = False , <EOL> scopes = None , <EOL> client_id = _OAUTH_CLIENT_ID ) : <EOL> """<STR_LIT>""" <EOL> self . __email = email <EOL> self . __domain = domain <EOL> self . __user_id = user_id <EOL> self . __is_admin = is_admin <EOL> self . __scopes = scopes <EOL> self . __client_id = client_id <EOL> def _Dynamic_CreateLoginURL ( self , request , response , request_id ) : <EOL> """<STR_LIT>""" <EOL> if request . has_federated_identity ( ) : <EOL> logging . warning ( _OPENID_DEPRECATION_WARNING ) <EOL> response . set_login_url ( <EOL> self . _login_url % <EOL> urllib . quote ( self . _AddHostToContinueURL ( request . destination_url ( ) , <EOL> request_id ) ) ) <EOL> def _Dynamic_CreateLogoutURL ( self , request , response , request_id ) : <EOL> """<STR_LIT>""" <EOL> response . set_logout_url ( <EOL> self . _logout_url % <EOL> urllib . quote ( self . _AddHostToContinueURL ( request . destination_url ( ) , <EOL> request_id ) ) ) <EOL> def _Dynamic_GetOAuthUser ( self , request , response , request_id ) : <EOL> """<STR_LIT>""" <EOL> if self . __email is None : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> user_service_pb . UserServiceError . OAUTH_INVALID_REQUEST ) <EOL> else : <EOL> if self . __scopes is None : <EOL> authorized_scopes = set ( ) <EOL> else : <EOL> authorized_scopes = set ( request . scopes_list ( ) ) . intersection ( <EOL> self . __scopes ) <EOL> if not authorized_scopes : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> user_service_pb . UserServiceError . OAUTH_INVALID_TOKEN ) <EOL> response . set_email ( self . __email ) <EOL> response . set_user_id ( self . __user_id ) <EOL> response . set_auth_domain ( self . __domain ) <EOL> response . set_is_admin ( self . __is_admin ) <EOL> response . set_client_id ( self . __client_id ) <EOL> if request . request_writer_permission ( ) : <EOL> response . set_is_project_writer ( self . __is_admin ) <EOL> for scope in authorized_scopes : <EOL> response . add_scopes ( scope ) <EOL> def _Dynamic_CheckOAuthSignature ( self , unused_request , response , request_id ) : <EOL> """<STR_LIT>""" <EOL> response . set_oauth_consumer_key ( _OAUTH_CONSUMER_KEY ) <EOL> def _AddHostToContinueURL ( self , continue_url , request_id ) : <EOL> """<STR_LIT>""" <EOL> ( protocol , host , path , parameters , query , fragment ) = urlparse . urlparse ( continue_url ) <EOL> if host and protocol : <EOL> return continue_url <EOL> try : <EOL> protocol , host , _ , _ , _ , _ = urlparse . urlparse ( <EOL> self . request_data . get_request_url ( request_id ) ) <EOL> except KeyError : <EOL> pass <EOL> if path == '<STR_LIT>' : <EOL> path = '<STR_LIT:/>' <EOL> return urlparse . urlunparse ( <EOL> ( protocol , host , path , parameters , query , fragment ) ) </s>
