# Path: invoke/util.py
# LOG_FORMAT = "%(name)s.%(module)s.%(funcName)s: %(message)s"
# def enable_logging():
# def task_name_sort_key(name):
# def cd(where):
# def has_fileno(stream):
# def isatty(stream):
# def encode_output(string, encoding):
# def helpline(obj):
#     def __init__(self, **kwargs):
#     def run(self):
#     def exception(self):
#     def is_dead(self):
#     def __repr__(self):
# class ExceptionHandlingThread(threading.Thread):
# 
# Path: invoke/exceptions.py
# class UncastableEnvVar(Exception):
#     """
#     Raised on attempted env var loads whose default values are too rich.
# 
#     E.g. trying to stuff ``MY_VAR="foo"`` into ``{'my_var': ['uh', 'oh']}``
#     doesn't make any sense until/if we implement some sort of transform option.
# 
#     .. versionadded:: 1.0
#     """
# 
#     pass
# 
# class AmbiguousEnvVar(Exception):
#     """
#     Raised when loading env var config keys has an ambiguous target.
# 
#     .. versionadded:: 1.0
#     """
# 
#     pass
# 
# Path: invoke/util.py
# LOG_FORMAT = "%(name)s.%(module)s.%(funcName)s: %(message)s"
# def enable_logging():
# def task_name_sort_key(name):
# def cd(where):
# def has_fileno(stream):
# def isatty(stream):
# def encode_output(string, encoding):
# def helpline(obj):
#     def __init__(self, **kwargs):
#     def run(self):
#     def exception(self):
#     def is_dead(self):
#     def __repr__(self):
# class ExceptionHandlingThread(threading.Thread):


import os
from .util import six
from .exceptions import UncastableEnvVar, AmbiguousEnvVar
from .util import debug
"""





class Environment(object):
    def __init__(self, config, prefix):
        self._config = config
        self._prefix = prefix
        self.data = {}  # Accumulator

    def load(self):
        """
        Return a nested dict containing values from `os.environ`.

        Specifically, values whose keys map to already-known configuration
        settings, allowing us to perform basic typecasting.

        See :ref:`env-vars` for details.
        """
        # Obtain allowed env var -> existing value map
        env_vars = self._crawl(key_path=[], env_vars={})
        m = "Scanning for env vars according to prefix: {!r}, mapping: {!r}"
        debug(m.format(self._prefix, env_vars))
        # Check for actual env var (honoring prefix) and try to set
        for env_var, key_path in six.iteritems(env_vars):
            real_var = (self._prefix or "") + env_var
            if real_var in os.environ:
                self._path_set(key_path, os.environ[real_var])

# Path: invoke/util.py
# LOG_FORMAT = "%(name)s.%(module)s.%(funcName)s: %(message)s"
# def enable_logging():
# def task_name_sort_key(name):
# def cd(where):
# def has_fileno(stream):
# def isatty(stream):
# def encode_output(string, encoding):
# def helpline(obj):
#     def __init__(self, **kwargs):
#     def run(self):
#     def exception(self):
#     def is_dead(self):
#     def __repr__(self):
# class ExceptionHandlingThread(threading.Thread):
# 
# Path: invoke/exceptions.py
# class UncastableEnvVar(Exception):
#     """
#     Raised on attempted env var loads whose default values are too rich.
# 
#     E.g. trying to stuff ``MY_VAR="foo"`` into ``{'my_var': ['uh', 'oh']}``
#     doesn't make any sense until/if we implement some sort of transform option.
# 
#     .. versionadded:: 1.0
#     """
# 
#     pass
# 
# class AmbiguousEnvVar(Exception):
#     """
#     Raised when loading env var config keys has an ambiguous target.
# 
#     .. versionadded:: 1.0
#     """
# 
#     pass
# 
# Path: invoke/util.py
# LOG_FORMAT = "%(name)s.%(module)s.%(funcName)s: %(message)s"
# def enable_logging():
# def task_name_sort_key(name):
# def cd(where):
# def has_fileno(stream):
# def isatty(stream):
# def encode_output(string, encoding):
# def helpline(obj):
#     def __init__(self, **kwargs):
#     def run(self):
#     def exception(self):
#     def is_dead(self):
#     def __repr__(self):
# class ExceptionHandlingThread(threading.Thread):


# Path: invoke/env.py
import os
from .util import six
from .exceptions import UncastableEnvVar, AmbiguousEnvVar
from .util import debug

"""





class Environment(object):
    def __init__(self, config, prefix):
        self._config = config
        self._prefix = prefix
        self.data = {}  # Accumulator

    def load(self):
        """
        Return a nested dict containing values from `os.environ`.

        Specifically, values whose keys map to already-known configuration
        settings, allowing us to perform basic typecasting.

        See :ref:`env-vars` for details.
        """
        # Obtain allowed env var -> existing value map
        env_vars = self._crawl(key_path=[], env_vars={})
        m = "Scanning for env vars according to prefix: {!r}, mapping: {!r}"
        debug(m.format(self._prefix, env_vars))
        # Check for actual env var (honoring prefix) and try to set
        for env_var, key_path in six.iteritems(env_vars):
            real_var = (self._prefix or "") + env_var
            if real_var in os.environ:
                self._path_set(key_path, os.environ[real_var])

        debug("Obtained env var config: {!r}".format(self.data))