App Engine Python SDK version 1.8.1
[gae.git] / python / google / appengine / api / capabilities / capability_stub.py
blobbfd5da1f9d115f5d36497c62bbda489f3eadb9df
1 #!/usr/bin/env python
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 = (
40 'blobstore',
41 'datastore_v3',
42 'images',
43 'mail',
44 'memcache',
45 'taskqueue',
46 'urlfetch',
47 'xmpp',
51 class CapabilityServiceStub(apiproxy_stub.APIProxyStub):
52 """Python only capability service stub."""
54 THREADSAFE = True
56 def __init__(self, service_name='capability_service'):
57 """Constructor.
59 Args:
60 service_name: Service name expected for all calls.
61 """
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.
73 Args:
74 package: Name of package.
75 enabled: True to enable, False to disable.
76 """
78 self._packages[package] = enabled
82 def _Dynamic_IsEnabled(self, request, response):
83 """Implementation of CapabilityService::IsEnabled().
85 Args:
86 request: An IsEnabledRequest.
87 response: An IsEnabledResponse.
88 """
89 default_config = response.add_config()
90 default_config.set_package('')
91 default_config.set_capability('')
93 try:
94 package_enabled = self._packages[request.package()]
95 except KeyError:
96 summary_status = IsEnabledResponse.UNKNOWN
97 config_status = CapabilityConfig.UNKNOWN
98 else:
99 if package_enabled:
100 summary_status = IsEnabledResponse.ENABLED
101 config_status = CapabilityConfig.ENABLED
102 else:
103 summary_status = IsEnabledResponse.DISABLED
104 config_status = CapabilityConfig.DISABLED
105 response.set_summary_status(summary_status)
106 default_config.set_status(config_status)