3 # Copyright 2007 Google Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
21 """Stub version of the capability service API, everything is always enabled."""
29 from google
.appengine
.api
import apiproxy_stub
30 from google
.appengine
.api
import capabilities
33 IsEnabledRequest
= capabilities
.IsEnabledRequest
34 IsEnabledResponse
= capabilities
.IsEnabledResponse
35 CapabilityConfig
= capabilities
.CapabilityConfig
39 SUPPORTED_CAPABILITIES
= (
51 class CapabilityServiceStub(apiproxy_stub
.APIProxyStub
):
52 """Python only capability service stub."""
56 def __init__(self
, service_name
='capability_service'):
60 service_name: Service name expected for all calls.
62 super(CapabilityServiceStub
, self
).__init
__(service_name
)
65 self
._packages
= dict.fromkeys(SUPPORTED_CAPABILITIES
, True)
67 def SetPackageEnabled(self
, package
, enabled
):
68 """Set all features of a given package to enabled.
70 This method is thread-unsafe, so should only be called during set-up, before
71 multiple API server threads start.
74 package: Name of package.
75 enabled: True to enable, False to disable.
78 self
._packages
[package
] = enabled
82 def _Dynamic_IsEnabled(self
, request
, response
):
83 """Implementation of CapabilityService::IsEnabled().
86 request: An IsEnabledRequest.
87 response: An IsEnabledResponse.
89 default_config
= response
.add_config()
90 default_config
.set_package('')
91 default_config
.set_capability('')
94 package_enabled
= self
._packages
[request
.package()]
96 summary_status
= IsEnabledResponse
.UNKNOWN
97 config_status
= CapabilityConfig
.UNKNOWN
100 summary_status
= IsEnabledResponse
.ENABLED
101 config_status
= CapabilityConfig
.ENABLED
103 summary_status
= IsEnabledResponse
.DISABLED
104 config_status
= CapabilityConfig
.DISABLED
105 response
.set_summary_status(summary_status
)
106 default_config
.set_status(config_status
)