# 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
    pass


class ColorScheme(object):
    """This is the class that colorschemes must inherit from.

    it defines the get() method, which returns the color tuple
    which fits to the given keys.
    """

    @cached_function
    def get(self, *keys):
        """Returns the (fg, bg, attr) for the given keys.

        Using this function rather than use() will cache all
        colors for faster access.
        """
        context = Context(keys)
        color = self.use(context)
        if len(color) != 3 or not all(isinstance(value, int) for value in color):
            raise ValueError("Bad Value from colorscheme.  Need "
                             "a tuple of (foreground_color, background_color, attribute).")
        return color

    @cached_function
    def get_attr(self, *keys):
        """Returns the curses attribute for the specified keys

        Ready to use for curses.setattr()
        """

# 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

    pass


class ColorScheme(object):
    """This is the class that colorschemes must inherit from.

    it defines the get() method, which returns the color tuple
    which fits to the given keys.
    """

    @cached_function
    def get(self, *keys):
        """Returns the (fg, bg, attr) for the given keys.

        Using this function rather than use() will cache all
        colors for faster access.
        """
        context = Context(keys)
        color = self.use(context)
        if len(color) != 3 or not all(isinstance(value, int) for value in color):
            raise ValueError("Bad Value from colorscheme.  Need "
                             "a tuple of (foreground_color, background_color, attribute).")
        return color

    @cached_function
    def get_attr(self, *keys):
        """Returns the curses attribute for the specified keys

        Ready to use for curses.setattr()
        """

        fg, bg, attr = self.get(*flatten(keys))