本文整理汇总了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)}"