# Path: ranger/gui/context.py
# class Context(object):  # pylint: disable=too-few-public-methods
# 
#     def __init__(self, keys):
#         # set all given keys to True
#         dictionary = self.__dict__
#         for key in keys:
#             dictionary[key] = True
# 
# Path: ranger/core/main.py
# def allow_access_to_confdir(confdir, allow):
#     from errno import EEXIST
# 
#     if allow:
#         try:
#             os.makedirs(confdir)
#         except OSError as err:
#             if err.errno != EEXIST:  # EEXIST means it already exists
#                 print("This configuration directory could not be created:")
#                 print(confdir)
#                 print("To run ranger without the need for configuration")
#                 print("files, use the --clean option.")
#                 raise SystemExit
#         else:
#             LOG.debug("Created config directory '%s'", confdir)
#         if confdir not in sys.path:
#             sys.path[0:0] = [confdir]
#     else:
#         if sys.path[0] == confdir:
#             del sys.path[0]
# 
# Path: ranger/ext/iter_tools.py
# def flatten(lst):
#     """Flatten an iterable.
# 
#     All contained tuples, lists, deques and sets are replaced by their
#     elements and flattened as well.
# 
#     >>> l = [1, 2, [3, [4], [5, 6]], 7]
#     >>> list(flatten(l))
#     [1, 2, 3, 4, 5, 6, 7]
#     >>> list(flatten(()))
#     []
#     """
#     for elem in lst:
#         if isinstance(elem, (tuple, list, set, deque)):
#             for subelem in flatten(elem):
#                 yield subelem
#         else:
#             yield elem


import os.path
import ranger
from curses import color_pair
from io import open
from ranger.gui.color import get_color
from ranger.gui.context import Context
from ranger.core.main import allow_access_to_confdir
from ranger.ext.cached_function import cached_function
from ranger.ext.iter_tools import flatten
    # create ~/.config/ranger/colorschemes/__init__.py if it doesn't exist
    if usecustom:
        if os.path.exists(signal.fm.confpath('colorschemes')):
            initpy = signal.fm.confpath('colorschemes', '__init__.py')
            if not os.path.exists(initpy):
                with open(initpy, "a", encoding="utf-8"):
                    # Just create the file
                    pass

    if usecustom and \
            exists(signal.fm.confpath('colorschemes', scheme_name)):
        scheme_supermodule = 'colorschemes'
    elif exists(signal.fm.relpath('colorschemes', scheme_name)):
        scheme_supermodule = 'ranger.colorschemes'
        usecustom = False
    else:
        scheme_supermodule = None  # found no matching file.

    if scheme_supermodule is None:
        if signal.previous and isinstance(signal.previous, ColorScheme):
            signal.value = signal.previous
        else:
            signal.value = ColorScheme()
        raise ColorSchemeError("Cannot locate colorscheme `%s'" % scheme_name)
    else:
        if usecustom:
            allow_access_to_confdir(ranger.args.confdir, True)
        scheme_module = getattr(
            __import__(scheme_supermodule, globals(), locals(), [scheme_name], 0), scheme_name)
        if usecustom:

# Path: ranger/gui/context.py
# class Context(object):  # pylint: disable=too-few-public-methods
# 
#     def __init__(self, keys):
#         # set all given keys to True
#         dictionary = self.__dict__
#         for key in keys:
#             dictionary[key] = True
# 
# Path: ranger/core/main.py
# def allow_access_to_confdir(confdir, allow):
#     from errno import EEXIST
# 
#     if allow:
#         try:
#             os.makedirs(confdir)
#         except OSError as err:
#             if err.errno != EEXIST:  # EEXIST means it already exists
#                 print("This configuration directory could not be created:")
#                 print(confdir)
#                 print("To run ranger without the need for configuration")
#                 print("files, use the --clean option.")
#                 raise SystemExit
#         else:
#             LOG.debug("Created config directory '%s'", confdir)
#         if confdir not in sys.path:
#             sys.path[0:0] = [confdir]
#     else:
#         if sys.path[0] == confdir:
#             del sys.path[0]
# 
# Path: ranger/ext/iter_tools.py
# def flatten(lst):
#     """Flatten an iterable.
# 
#     All contained tuples, lists, deques and sets are replaced by their
#     elements and flattened as well.
# 
#     >>> l = [1, 2, [3, [4], [5, 6]], 7]
#     >>> list(flatten(l))
#     [1, 2, 3, 4, 5, 6, 7]
#     >>> list(flatten(()))
#     []
#     """
#     for elem in lst:
#         if isinstance(elem, (tuple, list, set, deque)):
#             for subelem in flatten(elem):
#                 yield subelem
#         else:
#             yield elem


# Path: ranger/gui/colorscheme.py
import os.path
import ranger
from curses import color_pair
from io import open
from ranger.gui.color import get_color
from ranger.gui.context import Context
from ranger.core.main import allow_access_to_confdir
from ranger.ext.cached_function import cached_function
from ranger.ext.iter_tools import flatten

    # create ~/.config/ranger/colorschemes/__init__.py if it doesn't exist
    if usecustom:
        if os.path.exists(signal.fm.confpath('colorschemes')):
            initpy = signal.fm.confpath('colorschemes', '__init__.py')
            if not os.path.exists(initpy):
                with open(initpy, "a", encoding="utf-8"):
                    # Just create the file
                    pass

    if usecustom and \
            exists(signal.fm.confpath('colorschemes', scheme_name)):
        scheme_supermodule = 'colorschemes'
    elif exists(signal.fm.relpath('colorschemes', scheme_name)):
        scheme_supermodule = 'ranger.colorschemes'
        usecustom = False
    else:
        scheme_supermodule = None  # found no matching file.

    if scheme_supermodule is None:
        if signal.previous and isinstance(signal.previous, ColorScheme):
            signal.value = signal.previous
        else:
            signal.value = ColorScheme()
        raise ColorSchemeError("Cannot locate colorscheme `%s'" % scheme_name)
    else:
        if usecustom:
            allow_access_to_confdir(ranger.args.confdir, True)
        scheme_module = getattr(
            __import__(scheme_supermodule, globals(), locals(), [scheme_name], 0), scheme_name)
        if usecustom:

            allow_access_to_confdir(ranger.args.confdir, False)