本文整理匯總了Python中os._Environ方法的典型用法代碼示例。如果您正苦於以下問題:Python os._Environ方法的具體用法?Python os._Environ怎麽用?Python os._Environ使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類os
的用法示例。
在下文中一共展示了os._Environ方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _dict_from_env_vars
# 需要導入模塊: import os [as 別名]
# 或者: from os import _Environ [as 別名]
def _dict_from_env_vars(
env_vars: Optional[Union[os._Environ, Dict[str, str]]] = None
):
if env_vars is None:
env_vars = os.environ
config_dict: Dict[str, Dict[str, Union[str, bool, int]]] = {}
for key, value in env_vars.items():
if key.startswith("TASKCAT_"):
key = key[8:].lower()
sub_key = None
key_section = None
for section in ["general", "project", "tests"]:
if key.startswith(section):
sub_key = key[len(section) + 1 :]
key_section = section
if isinstance(sub_key, str) and isinstance(key_section, str):
if value.isnumeric():
value = int(value)
elif value.lower() in ["true", "false"]:
value = value.lower() == "true"
if not config_dict.get(key_section):
config_dict[key_section] = {}
config_dict[key_section][sub_key] = value
return config_dict
示例2: setup_yaml
# 需要導入模塊: import os [as 別名]
# 或者: from os import _Environ [as 別名]
def setup_yaml():
_mapping_tag = yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG
yaml.add_representer(collections.OrderedDict, dict_representer)
yaml.add_representer(os._Environ, dict_representer)
yaml.add_representer(unicode, unicode_representer)
yaml.add_constructor(_mapping_tag, dict_constructor)
示例3: __call__
# 需要導入模塊: import os [as 別名]
# 或者: from os import _Environ [as 別名]
def __call__(self, environ, start_response):
method_info = environ.get(EnvironmentMiddleware.METHOD_INFO)
if not method_info or not method_info.auth_info:
# No authentication configuration for this method
_logger.debug(u"authentication is not configured")
return self._application(environ, start_response)
auth_token = _extract_auth_token(environ)
user_info = None
if not auth_token:
_logger.debug(u"No auth token is attached to the request")
else:
try:
service_name = environ.get(EnvironmentMiddleware.SERVICE_NAME)
user_info = self._authenticator.authenticate(auth_token,
method_info.auth_info,
service_name)
except Exception: # pylint: disable=broad-except
_logger.debug(u"Cannot decode and verify the auth token. The backend "
u"will not be able to retrieve user info", exc_info=True)
environ[self.USER_INFO] = user_info
# pylint: disable=protected-access
if user_info and not isinstance(os.environ, os._Environ):
# Set user info into os.environ only if os.environ is replaced
# with a request-local copy
os.environ[self.USER_INFO] = user_info
response = self._application(environ, start_response)
# Erase user info from os.environ for safety and sanity.
if self.USER_INFO in os.environ:
del os.environ[self.USER_INFO]
return response
示例4: prettystr
# 需要導入模塊: import os [as 別名]
# 或者: from os import _Environ [as 別名]
def prettystr(a):
"""improve how dictionaries get printed"""
if isinstance(a, os._Environ):
a = dict(a)
if isinstance(a, dict):
return f"{yaml.dump(a, default_flow_style=False)}"