# 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
        else:
            new_vars[self._to_env_var(key_path)] = key_path
        return new_vars

    def _to_env_var(self, key_path):
        return "_".join(key_path).upper()

    def _path_get(self, key_path):
        # Gets are from self._config because that's what determines valid env
        # vars and/or values for typecasting.
        obj = self._config
        for key in key_path:
            obj = obj[key]
        return obj

    def _path_set(self, key_path, value):
        # Sets are to self.data since that's what we are presenting to the
        # outer config object and debugging.
        obj = self.data
        for key in key_path[:-1]:
            if key not in obj:
                obj[key] = {}
            obj = obj[key]
        old = self._path_get(key_path)
        new_ = self._cast(old, value)
        obj[key_path[-1]] = new_

    def _cast(self, old, new_):
        if isinstance(old, bool):
            return new_ not in ("0", "")

# 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

        else:
            new_vars[self._to_env_var(key_path)] = key_path
        return new_vars

    def _to_env_var(self, key_path):
        return "_".join(key_path).upper()

    def _path_get(self, key_path):
        # Gets are from self._config because that's what determines valid env
        # vars and/or values for typecasting.
        obj = self._config
        for key in key_path:
            obj = obj[key]
        return obj

    def _path_set(self, key_path, value):
        # Sets are to self.data since that's what we are presenting to the
        # outer config object and debugging.
        obj = self.data
        for key in key_path[:-1]:
            if key not in obj:
                obj[key] = {}
            obj = obj[key]
        old = self._path_get(key_path)
        new_ = self._cast(old, value)
        obj[key_path[-1]] = new_

    def _cast(self, old, new_):
        if isinstance(old, bool):
            return new_ not in ("0", "")

        elif isinstance(old, six.string_types):