Python os._Environ() Examples
The following are 4
code examples of os._Environ().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: _config.py From taskcat with Apache License 2.0 | 6 votes |
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
Example #2
Source File: util.py From forge with Apache License 2.0 | 5 votes |
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)
Example #3
Source File: wsgi.py From endpoints-management-python with Apache License 2.0 | 5 votes |
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
Example #4
Source File: utils.py From popper with MIT License | 5 votes |
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)}"