<s> from google . appengine . api import apiproxy_rpc <EOL> from google . appengine . api import apiproxy_stub <EOL> from google . appengine . api import capabilities <EOL> from google . appengine . runtime import apiproxy_errors <EOL> IsEnabledRequest = capabilities . IsEnabledRequest <EOL> IsEnabledResponse = capabilities . IsEnabledResponse <EOL> CapabilityConfig = capabilities . CapabilityConfig <EOL> class CapabilityServiceStub ( apiproxy_stub . APIProxyStub ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , disabled_capabilities , disabled_methods , <EOL> service_name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> super ( CapabilityServiceStub , self ) . __init__ ( service_name ) <EOL> self . disabled_capabilities = disabled_capabilities <EOL> self . disabled_methods = disabled_methods <EOL> def _Dynamic_IsEnabled ( self , request , response ) : <EOL> """<STR_LIT>""" <EOL> package = request . package ( ) <EOL> if ( package , '<STR_LIT:*>' ) in self . disabled_capabilities : <EOL> response . set_summary_status ( IsEnabledRequest . DISABLED ) <EOL> config = response . add_config ( ) <EOL> config . set_package ( package ) <EOL> config . set_capability ( '<STR_LIT:*>' ) <EOL> config . set_status ( CapabilityConfig . DISABLED ) <EOL> else : <EOL> any_disabled = False <EOL> for method in request . call_list ( ) : <EOL> config = response . add_config ( ) <EOL> config . set_package ( package ) <EOL> config . set_capability ( method ) <EOL> if ( package , method ) in self . disabled_methods : <EOL> config . set_status ( IsEnabledResponse . DISABLED ) <EOL> any_disabled = True <EOL> else : <EOL> config . set_status ( IsEnabledResponse . ENABLED ) <EOL> for capability in request . capability_list ( ) : <EOL> config = response . add_config ( ) <EOL> config . set_package ( package ) <EOL> config . set_capability ( capability ) <EOL> if ( package , capability ) in self . disabled_capabilities : <EOL> any_disabled = True <EOL> config . set_status ( IsEnabledResponse . DISABLED ) <EOL> else : <EOL> config . set_status ( IsEnabledResponse . ENABLED ) <EOL> response . set_summary_status ( IsEnabledResponse . DISABLED if any_disabled <EOL> else IsEnabledResponse . ENABLED ) <EOL> class CapabilityStubWrapper ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , wrapped_stub , disabled_capabilities , disabled_methods ) : <EOL> self . wrapped_stub = wrapped_stub <EOL> self . disabled_capabilities = disabled_capabilities <EOL> self . disabled_methods = disabled_methods <EOL> def CreateRPC ( self ) : <EOL> """<STR_LIT>""" <EOL> return apiproxy_rpc . RPC ( stub = self ) <EOL> def MakeSyncCall ( self , service , call , request , response ) : <EOL> if ( ( service , '<STR_LIT:*>' ) in self . disabled_capabilities <EOL> or ( service , call ) in self . disabled_methods ) : <EOL> raise apiproxy_errors . CapabilityDisabledError ( ) <EOL> self . wrapped_stub . MakeSyncCall ( service , call , request , response ) </s>
