[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
Source code for google.appengine.api.namespace_manager.namespace_manager
#!/usr/bin/env python## Copyright 2007 Google Inc.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.#"""Control the namespacing system used by various APIs.A namespace may be specified in various API calls exemplifiedby the datastore and memcache interfaces. The default can bespecified using this module."""importosimportreimportwarningsfromgoogle.appengine.apiimportlib_config__all__=['BadValueError','set_namespace','get_namespace','google_apps_namespace','enable_request_namespace','validate_namespace',]_ENV_DEFAULT_NAMESPACE='HTTP_X_APPENGINE_DEFAULT_NAMESPACE'_ENV_CURRENT_NAMESPACE='HTTP_X_APPENGINE_CURRENT_NAMESPACE'_NAMESPACE_MAX_LENGTH=100_NAMESPACE_PATTERN=r'^[0-9A-Za-z._-]{0,%s}$'%_NAMESPACE_MAX_LENGTH_NAMESPACE_RE=re.compile(_NAMESPACE_PATTERN)class_ConfigDefaults(object):defdefault_namespace_for_request():returnNone_config=lib_config.register('namespace_manager_',_ConfigDefaults.__dict__)
[docs]defset_namespace(namespace):"""Set the default namespace for the current HTTP request. Args: namespace: A string naming the new namespace to use. A value of None will unset the default namespace value. """ifnamespaceisNone:os.environ.pop(_ENV_CURRENT_NAMESPACE,None)else:validate_namespace(namespace)os.environ[_ENV_CURRENT_NAMESPACE]=namespace
[docs]defget_namespace():"""Get the current default namespace or ('') namespace if unset."""name=os.environ.get(_ENV_CURRENT_NAMESPACE,None)ifnameisNone:name=_config.default_namespace_for_request()ifnameisnotNone:set_namespace(name)ifnameisNone:name=''returnname
[docs]defenable_request_namespace():"""Set the default namespace to the Google Apps domain referring this request. This method is deprecated, use lib_config instead. Calling this function will set the default namespace to the Google Apps domain that was used to create the url used for this request and only for the current request and only if the current default namespace is unset. """warnings.warn('namespace_manager.enable_request_namespace() is deprecated: ''use lib_config instead.',DeprecationWarning,stacklevel=2)if_ENV_CURRENT_NAMESPACEnotinos.environ:if_ENV_DEFAULT_NAMESPACEinos.environ:os.environ[_ENV_CURRENT_NAMESPACE]=os.environ[_ENV_DEFAULT_NAMESPACE]
[docs]classBadValueError(Exception):"""Raised by ValidateNamespaceString."""
[docs]defvalidate_namespace(value,exception=BadValueError):"""Raises an exception if value is not a valid Namespace string. A namespace must match the regular expression ([0-9A-Za-z._-]{0,100}). Args: value: string, the value to validate. exception: exception type to raise. """ifnotisinstance(value,basestring):raiseexception('value should be a string; received %r (a %s):'%(value,type(value)))ifnot_NAMESPACE_RE.match(value):raiseexception('value "%s" does not match regex "%s"'%(value,_NAMESPACE_PATTERN))
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]