当前位置: 首页>>代码示例>>Python>>正文


Python os._Environ方法代码示例

本文整理汇总了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 
开发者ID:aws-quickstart,项目名称:taskcat,代码行数:26,代码来源:_config.py

示例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) 
开发者ID:datawire,项目名称:forge,代码行数:8,代码来源:util.py

示例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 
开发者ID:cloudendpoints,项目名称:endpoints-management-python,代码行数:38,代码来源:wsgi.py

示例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)}" 
开发者ID:getpopper,项目名称:popper,代码行数:8,代码来源:utils.py


注:本文中的os._Environ方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。