Ejemplo n.º 1
0
    def walk_attributes(self, parent, label, value, id_path, iinfo):
        try:
            keys = dir(value)
        except Exception:
            ui_log.exception(f"Failed to look up attributes on {label}")
            return

        for key in sorted(keys):
            if iinfo.access_level == "public":
                if key.startswith("_"):
                    continue
            elif iinfo.access_level == "private":
                if key.startswith("__") and key.endswith("__"):
                    continue

            try:
                with warnings.catch_warnings():
                    warnings.simplefilter("ignore")
                    attr_value = getattr(value, key)
                if inspect.isroutine(attr_value) and not iinfo.show_methods:
                    continue
            except Exception:
                attr_value = WatchEvalError()

            self.walk_value(parent, ".%s" % key, attr_value,
                            "%s.%s" % (id_path, key))
Ejemplo n.º 2
0
    def walk_value(self, parent, label, value, id_path=None, attr_prefix=None):
        if id_path is None:
            id_path = label

        assert isinstance(id_path, str)
        iinfo = self.frame_var_info.get_inspect_info(id_path, read_only=True)

        if isinstance(value, self.BASIC_TYPES):
            displayed_value = repr(value)
        else:
            try:
                displayed_value = get_stringifier(iinfo)(value)
            except Exception:
                # Unfortunately, anything can happen when calling str() or
                # repr() on a random object.
                displayed_value = type_stringifier(value) \
                                + " (!! %s error !!)" % iinfo.display_type
                ui_log.exception("stringifier failed")

        if iinfo.show_detail:
            marker = iinfo.access_level[:3]
            if iinfo.show_methods:
                marker += "+()"
            displayed_value += " [%s]" % marker

        new_parent_item = self.add_item(parent, label, displayed_value,
                                        id_path, attr_prefix)

        if iinfo.show_detail:
            if isinstance(value, CONTAINER_CLASSES):
                self.walk_container(new_parent_item, label, value, id_path)
            self.walk_attributes(new_parent_item, label, value, id_path, iinfo)
Ejemplo n.º 3
0
def get_stringifier(iinfo):
    """Return a function that turns an object into a Unicode text object."""

    if iinfo.display_type == "type":
        return type_stringifier
    elif iinfo.display_type == "repr":
        return repr
    elif iinfo.display_type == "str":
        return str
    elif iinfo.display_type == "id":
        return id_stringifier
    else:
        try:
            if not custom_stringifier_dict:  # Only execfile once
                from os.path import expanduser
                execfile(expanduser(iinfo.display_type),
                         custom_stringifier_dict)
        except Exception:
            ui_log.exception("Error when importing custom stringifier")
            return error_stringifier
        else:
            if "pudb_stringifier" not in custom_stringifier_dict:
                print(
                    "%s does not contain a function named pudb_stringifier at "
                    "the module level." % iinfo.display_type)
                raw_input("Hit enter:")
                return lambda value: text_type(
                    "ERROR: Invalid custom stringifier file: "
                    "pudb_stringifer not defined.")
            else:
                return (lambda value: text_type(custom_stringifier_dict[
                    "pudb_stringifier"](value)))
Ejemplo n.º 4
0
def type_stringifier(value):
    if HAVE_NUMPY and isinstance(value, numpy.ndarray):
        return text_type("%s(%s) %s") % (type(value).__name__, value.dtype,
                                         value.shape)

    elif HAVE_NUMPY and isinstance(value, numpy.number):
        return text_type("%s (%s)" % (value, value.dtype))

    elif isinstance(value, STR_SAFE_TYPES):
        try:
            return text_type(value)
        except Exception:
            message = "string safe type stringifier failed"
            ui_log.exception(message)
            return "!! %s !!" % message

    elif hasattr(type(value), "safely_stringify_for_pudb"):
        try:
            # (E.g.) Mock objects will pretend to have this
            # and return nonsense.
            result = value.safely_stringify_for_pudb()
        except Exception:
            message = "safely_stringify_for_pudb call failed"
            ui_log.exception(message)
            result = "!! %s !!" % message

        if isinstance(result, string_types):
            return text_type(result)

    elif type(value) in [set, frozenset, list, tuple, dict]:
        return text_type("%s (%s)") % (type(value).__name__, len(value))

    return text_type(type(value).__name__)
Ejemplo n.º 5
0
def get_stringifier(iinfo: InspectInfo) -> Callable:
    """
    :return: a function that turns an object into a Unicode text object.
    """
    try:
        return STRINGIFIERS[iinfo.display_type]
    except KeyError:
        try:
            if not custom_stringifier_dict:  # Only execfile once
                from os.path import expanduser
                custom_stringifier_fname = expanduser(iinfo.display_type)
                with open(custom_stringifier_fname) as inf:
                    exec(compile(inf.read(), custom_stringifier_fname, "exec"),
                         custom_stringifier_dict, custom_stringifier_dict)
        except Exception:
            ui_log.exception("Error when importing custom stringifier")
            return error_stringifier
        else:
            if "pudb_stringifier" not in custom_stringifier_dict:
                ui_log.error(
                    f"{iinfo.display_type} does not contain a function "
                    "named pudb_stringifier at the module level.")
                return lambda value: str(
                    "ERROR: Invalid custom stringifier file: "
                    "pudb_stringifer not defined.")
            else:
                return (lambda value: str(custom_stringifier_dict[
                    "pudb_stringifier"](value)))
Ejemplo n.º 6
0
def default_stringifier(value):
    if isinstance(value, BASIC_TYPES):
        return repr(value)

    if HAVE_NUMPY and isinstance(value, numpy.ndarray):
        return "%s(%s) %s" % (type(value).__name__, value.dtype, value.shape)

    elif HAVE_NUMPY and isinstance(value, numpy.number):
        return str(f"{value} ({value.dtype})")

    elif isinstance(value, STR_SAFE_TYPES):
        try:
            return str(value)
        except Exception:
            message = "string safe type stringifier failed"
            ui_log.exception(message)
            return "!! %s !!" % message

    elif hasattr(type(value), "safely_stringify_for_pudb"):
        try:
            # (E.g.) Mock objects will pretend to have this
            # and return nonsense.
            result = value.safely_stringify_for_pudb()
        except Exception:
            message = "safely_stringify_for_pudb call failed"
            ui_log.exception(message)
            result = "!! %s !!" % message

        if isinstance(result, str):
            return str(result)

    elif isinstance(value, Sized):
        return f"{type(value).__name__} ({len(value)})"

    return str(type(value).__name__)
Ejemplo n.º 7
0
def get_palette(may_use_fancy_formats: bool, theme: str = "classic") -> list:
    """
    Load the requested theme and return a list containing all palette entries
    needed to highlight the debugger UI, including syntax highlighting.
    """
    inheritance_overrides = {}

    if may_use_fancy_formats:

        def add_setting(color, setting):
            return f"{color}, {setting}"
    else:

        def add_setting(color, setting):
            return color

    def link(child: str, parent: str):
        inheritance_overrides[child] = parent

    # {{{ themes

    if theme == "classic":
        # {{{ classic theme
        link("current breakpoint", "current frame name")
        link("focused current breakpoint", "focused current frame name")

        palette_dict = {
            # {{{ base styles
            "background": ("black", "light gray"),
            "selectable": ("black", "dark cyan"),
            "focused selectable": ("black", "light cyan"),
            "highlighted": ("dark blue", "yellow"),
            "hotkey": (add_setting("black", "underline"), "light gray"),
            # }}}
            # {{{ general ui
            "header": ("dark blue", "light gray"),
            "dialog title": (add_setting("white", "bold"), "dark blue"),
            "warning": (add_setting("white", "bold"), "dark red"),
            # }}}
            # {{{ source view
            "source": ("yellow", "dark blue"),
            "current source": ("dark blue", "dark green"),
            "breakpoint source": (add_setting("yellow", "bold"), "dark red"),
            "line number": ("light gray", "dark blue"),
            "breakpoint marker": (add_setting("dark red",
                                              "bold"), "dark blue"),
            # }}}
            # {{{ sidebar
            "sidebar two": ("dark blue", "dark cyan"),
            "sidebar three": ("dark gray", "dark cyan"),
            "focused sidebar two": ("dark blue", "light cyan"),
            "focused sidebar three": ("dark gray", "light cyan"),
            # }}}
            # {{{ variables view
            "return label": ("white", "dark blue"),
            "focused return label": ("light gray", "dark blue"),
            # }}}
            # {{{ stack
            "current frame name": (add_setting("white", "bold"), "dark cyan"),
            "focused current frame name": (add_setting("black",
                                                       "bold"), "light cyan"),
            # }}}
            # {{{ shell
            "command line output": ("light cyan", "dark blue"),
            "command line prompt": (add_setting("white", "bold"), "dark blue"),
            "command line error": (add_setting("light green",
                                               "bold"), "dark blue"),
            "command line clear button": (add_setting("white",
                                                      "bold"), "dark blue"),
            "command line focused button": ("dark blue", "dark cyan"),
            # }}}
            # {{{ Code syntax
            "keyword": (add_setting("white", "bold"), "dark blue"),
            "function": ("light cyan", "dark blue"),
            "literal": (add_setting("light green", "bold"), "dark blue"),
            "punctuation": ("light gray", "dark blue"),
            "comment": ("dark cyan", "dark blue"),
            # }}}
        }
        # }}}
    elif theme == "vim":
        # {{{ vim theme
        link("current breakpoint", "current frame name")
        link("focused current breakpoint", "focused current frame name")

        palette_dict = {
            # {{{ base styles
            "background": ("black", "light gray"),
            "selectable": ("black", "dark cyan"),
            "focused selectable": ("black", "light cyan"),
            "hotkey": (add_setting("black", "bold, underline"), "light gray"),
            "highlighted": ("black", "yellow"),
            # }}}
            # {{{ general ui
            "header": (add_setting("black", "bold"), "light gray"),
            "group head": ("dark blue", "light gray"),
            "dialog title": (add_setting("white", "bold"), "dark blue"),
            "input": ("black", "dark cyan"),
            "focused input": ("black", "light cyan"),
            "warning": (add_setting("dark red", "bold"), "white"),
            "header warning": (add_setting("dark red", "bold"), "light gray"),
            # }}}
            # {{{ source view
            "source": ("black", "white"),
            "current source": ("black", "dark cyan"),
            "breakpoint source": ("dark red", "light gray"),
            "line number": ("dark gray", "white"),
            "current line marker": ("dark red", "white"),
            "breakpoint marker": ("dark red", "white"),
            # }}}
            # {{{ sidebar
            "sidebar one": ("black", "dark cyan"),
            "sidebar two": ("dark blue", "dark cyan"),
            "sidebar three": ("dark gray", "dark cyan"),
            "focused sidebar one": ("black", "light cyan"),
            "focused sidebar two": ("dark blue", "light cyan"),
            "focused sidebar three": ("dark gray", "light cyan"),
            # }}}
            # {{{ variables view
            "highlighted var label": ("dark blue", "yellow"),
            "return label": ("white", "dark blue"),
            "focused return label": ("light gray", "dark blue"),
            # }}}
            # {{{ stack
            "current frame name": (add_setting("white", "bold"), "dark cyan"),
            "focused current frame name": (add_setting("black",
                                                       "bold"), "light cyan"),
            # }}}
            # {{{ shell
            "command line output": (add_setting("dark gray", "bold"), "white"),
            # }}}
            # {{{ Code syntax
            "keyword2": ("dark magenta", "white"),
            "namespace": ("dark magenta", "white"),
            "literal": ("dark red", "white"),
            "exception": ("dark red", "white"),
            "comment": ("dark gray", "white"),
            "function": ("dark blue", "white"),
            "pseudo": ("dark gray", "white"),
            "builtin": ("light blue", "white"),
            # }}}
        }
        # }}}
    elif theme == "dark vim":
        # {{{ dark vim

        link("current breakpoint", "current frame name")
        link("focused current breakpoint", "focused current frame name")
        palette_dict = {
            # {{{ base styles
            "background": ("black", "light gray"),
            "selectable": ("white", "dark gray"),
            "focused selectable": (add_setting("white", "bold"), "light blue"),
            "highlighted": ("black", "dark green"),
            "hotkey": (add_setting("dark blue", "underline"), "light gray"),
            # }}}
            # {{{ general ui
            "header": ("dark blue", "light gray"),
            "dialog title": (add_setting("white", "bold"), "black"),
            "warning": (add_setting("light red", "bold"), "black"),
            "header warning": (add_setting("light red", "bold"), "light gray"),
            # }}}
            # {{{ source view
            "source": ("white", "black"),
            "current source": (add_setting("white", "bold"), "dark gray"),
            "line number": (add_setting("dark gray", "bold"), "black"),
            "breakpoint marker": (add_setting("light red", "bold"), "black"),
            "breakpoint source": (add_setting("white", "bold"), "dark red"),
            # }}}
            # {{{ sidebar
            "sidebar two": ("yellow", "dark gray"),
            "focused sidebar two": ("light cyan", "light blue"),
            "sidebar three": ("light gray", "dark gray"),
            "focused sidebar three": ("yellow", "light blue"),
            # }}}
            # {{{ stack
            "current frame name": (add_setting("white", "bold"), "dark gray"),
            # }}}
            # {{{ shell
            "command line output": (add_setting("yellow", "bold"), "black"),
            # }}}
            # {{{ Code syntax
            "keyword": ("yellow", "black"),
            "literal": ("light magenta", "black"),
            "function": (add_setting("light cyan", "bold"), "black"),
            "punctuation": ("yellow", "black"),
            "comment": ("dark cyan", "black"),
            "exception": ("light red", "black"),
            "builtin": ("light green", "black"),
            "pseudo": ("dark green", "black"),
            # }}}
        }
        # }}}
    elif theme == "midnight":
        # {{{ midnight

        # Based on XCode's midnight theme
        # Looks best in a console with green text against black background
        link("current breakpoint", "current frame name")
        link("focused current breakpoint", "focused current frame name")
        palette_dict = {
            # {{{ base styles
            "background": ("black", "light gray"),
            "selectable": ("light gray", "black"),
            "focused selectable": ("black", "light green"),
            "hotkey": (add_setting("black", "underline"), "light gray"),
            "highlighted": ("black", "brown"),
            # }}}
            # {{{ general ui
            "focused sidebar": (add_setting("black", "bold"), "light gray"),
            "group head": (add_setting("black", "bold"), "light gray"),
            "warning": (add_setting("light red", "bold"), "black"),
            "header warning": (add_setting("light red", "bold"), "light gray"),
            "dialog title": ("black", "dark green"),
            "fixed value": ("white", "dark gray"),
            # }}}
            # {{{ source view
            "current source": ("black", "dark cyan"),
            "breakpoint source": ("white", "dark gray"),
            "line number": (add_setting("dark gray", "bold"), "black"),
            "breakpoint marker": (add_setting("light red", "bold"), "black"),
            "current line marker": ("dark cyan", "black"),
            # }}}
            # {{{ sidebar
            "sidebar two": ("dark green", "black"),
            "sidebar three": ("yellow", "black"),
            "focused sidebar three": ("dark gray", "light green"),
            # }}}
            # {{{ variables view
            "return label": ("black", "dark green"),
            "focused return label": ("black", "dark green"),
            # }}}
            # {{{ stack
            "current frame name": (add_setting("light gray", "bold"), "black"),
            # }}}
            # {{{ shell
            "command line prompt": (add_setting("white", "bold"), "black"),
            "command line output": ("yellow", "black"),
            "command line input": (add_setting("white", "bold"), "black"),
            # }}}
            # {{{ Code syntax
            "keyword": ("dark magenta", "black"),
            "keyword2": (add_setting("light magenta", "bold"), "black"),
            "pseudo": ("dark magenta", "black"),
            "function": (add_setting("light cyan", "bold"), "black"),
            "builtin": ("dark cyan", "black"),
            "literal": (add_setting("light blue", "bold"), "black"),
            "string": ("light red", "black"),
            "exception": (add_setting("light red", "bold"), "black"),
            "comment": ("dark green", "black"),
            # }}}
        }

        # }}}
    elif theme == "solarized":
        # {{{ solarized
        palette_dict = {
            # {{{ base styles
            "background": ("light green", "light gray"),
            "selectable": ("light green", "white"),
            "focused selectable": ("white", "dark blue"),
            "highlighted": ("white", "dark cyan"),
            "hotkey": (add_setting("black", "underline"), "light gray"),
            # }}}
            # {{{ general ui
            "dialog title": (add_setting("white", "bold"), "dark cyan"),
            "warning": (add_setting("light red", "bold"), "white"),
            "header warning": (add_setting("light red", "bold"), "light gray"),
            "focused sidebar": ("dark red", "light gray"),
            "group head": (add_setting("yellow", "bold"), "light gray"),
            # }}}
            # {{{ source view
            "source": ("yellow", "white"),
            "breakpoint source": ("light red", "light gray"),
            "current source": ("light gray", "light blue"),
            "line number": ("light blue", "white"),
            "current line marker": (add_setting("light blue",
                                                "bold"), "white"),
            "breakpoint marker": (add_setting("light red", "bold"), "white"),
            # }}}
            # {{{ sidebar
            "sidebar two": ("dark blue", "white"),
            "sidebar three": ("light cyan", "white"),
            "focused sidebar three": ("light gray", "dark blue"),
            # }}}
            # {{{ variables view
            "return label": ("white", "yellow"),
            "focused return label": ("white", "yellow"),
            # }}}
            # {{{ stack
            "current frame name": (add_setting("light green",
                                               "bold"), "white"),
            "focused current frame name": (add_setting("white",
                                                       "bold"), "dark blue"),
            # }}}
            # {{{ shell
            "command line output": ("light green", "white"),
            # }}}
            # {{{ Code syntax
            "namespace": ("dark red", "white"),
            "exception": ("light red", "white"),
            "keyword": ("brown", "white"),
            "keyword2": ("dark magenta", "white"),
            "function": ("dark green", "white"),
            "literal": ("dark cyan", "white"),
            "builtin": ("dark blue", "white"),
            "comment": ("light cyan", "white"),
            "pseudo": ("light cyan", "white"),
            # }}}
        }

    # }}}
    elif theme == "agr-256":
        # {{{ agr-256

        # Give the colors some comprehensible names
        black = "h235"
        blacker = "h233"
        dark_cyan = "h24"
        dark_gray = "h241"
        dark_green = "h22"
        dark_red = "h88"
        dark_teal = "h23"
        light_blue = "h111"
        light_cyan = "h80"
        light_gray = "h252"
        light_green = "h113"
        light_red = "h160"
        medium_gray = "h246"
        salmon = "h223"
        orange = "h173"
        white = "h255"
        yellow = "h192"

        link("focused breakpoint", "focused selectable")
        link("current breakpoint", "current frame name")
        link("focused current breakpoint", "focused current frame name")
        palette_dict = {
            # {{{ base styles
            "background": (black, light_gray),
            "selectable": (white, blacker),
            "focused selectable": (yellow, dark_cyan),
            "hotkey": (add_setting(black, "underline"), light_gray),
            "highlighted": (white, dark_green),
            # }}}
            # {{{ general ui
            "focused sidebar": (dark_cyan, light_gray),
            "group head": (add_setting(dark_cyan, "bold"), light_gray),
            "dialog title": (add_setting(light_gray, "bold"), black),
            "warning": (add_setting(white, "bold"), dark_red),
            "fixed value": (add_setting(white, "bold"), dark_gray),
            "button": (add_setting(white, "bold"), black),
            "focused button": (add_setting(yellow, "bold"), dark_cyan),
            # }}}
            # {{{ source view
            "line number": (dark_gray, black),
            "current line marker": (add_setting(yellow, "bold"), black),
            "breakpoint marker": (add_setting(light_red, "bold"), black),
            "source": (white, black),
            "breakpoint source": (add_setting(white, "bold"), dark_red),
            "current source": (add_setting(light_gray, "bold"), dark_teal),
            # }}}
            # {{{ sidebar
            "sidebar two": (light_blue, blacker),
            "focused sidebar two": (light_gray, dark_cyan),
            "sidebar three": (medium_gray, blacker),
            "focused sidebar three": (salmon, dark_cyan),
            # }}}
            # {{{ variables view
            "highlighted var label": (light_gray, dark_green),
            "return label": (light_green, blacker),
            "focused return label": (add_setting(light_gray,
                                                 "bold"), dark_cyan),
            # }}}
            # {{{ stack
            "current frame name": (yellow, blacker),
            "focused current frame name": (add_setting(yellow,
                                                       "bold"), dark_cyan),
            # }}}
            # {{{ shell
            "command line prompt": (add_setting(yellow, "bold"), black),
            "command line output": (light_cyan, black),
            "command line error": (light_red, black),
            # }}}
            # {{{ Code syntax
            "comment": (medium_gray, black),
            "exception": (orange, black),
            "function": (yellow, black),
            "keyword": (light_blue, black),
            "literal": (orange, black),
            "operator": (yellow, black),
            "pseudo": (medium_gray, black),
            "punctuation": (salmon, black),
            "string": (light_green, black),
            # }}}
        }
        # }}}
    elif theme == "monokai":
        # {{{ monokai
        link("current breakpoint", "current frame name")
        link("focused current breakpoint", "focused current frame name")
        palette_dict = {
            # {{{ base styles
            "background": ("black", "light gray"),
            "selectable": ("white", "black"),
            "focused selectable": ("white", "dark gray"),
            "highlighted": ("black", "dark green"),
            "hotkey": (add_setting("black", "underline"), "light gray"),
            # }}}
            # {{{ general ui
            "input": ("white", "black"),
            "button": (add_setting("white", "bold"), "black"),
            "focused button": (add_setting("white", "bold"), "dark gray"),
            "focused sidebar": ("dark blue", "light gray"),
            "warning": (add_setting("white", "bold"), "dark red"),
            "group head": (add_setting("black", "bold"), "light gray"),
            "dialog title": (add_setting("white", "bold"), "black"),
            # }}}
            # {{{ source view
            "current source": ("black", "dark cyan"),
            "breakpoint source": (add_setting("white", "bold"), "dark red"),
            "line number": ("dark gray", "black"),
            "current line marker": (add_setting("dark cyan", "bold"), "black"),
            "breakpoint marker": (add_setting("dark red", "bold"), "black"),
            # }}}
            # {{{ sidebar
            "sidebar two": ("light cyan", "black"),
            "focused sidebar two": ("light cyan", "dark gray"),
            "sidebar three": ("light magenta", "black"),
            "focused sidebar three": ("light magenta", "dark gray"),
            # }}}
            # {{{ variables view
            "return label": ("light green", "black"),
            "focused return label": ("light green", "dark gray"),
            # }}}
            # {{{ stack
            "current frame name": ("light green", "black"),
            "focused current frame name": ("light green", "dark gray"),
            # }}}
            # {{{ shell
            "command line prompt": (add_setting("yellow", "bold"), "black"),
            "command line output": ("light cyan", "black"),
            "command line error": ("yellow", "black"),
            "focused command line output": ("light cyan", "dark gray"),
            "focused command line error": (add_setting("yellow",
                                                       "bold"), "dark gray"),
            # }}}
            # {{{ Code syntax
            "literal": ("light magenta", "black"),
            "builtin": ("light cyan", "black"),
            "exception": ("light cyan", "black"),
            "keyword2": ("light cyan", "black"),
            "function": ("light green", "black"),
            "class": (add_setting("light green", "underline"), "black"),
            "keyword": ("light red", "black"),
            "operator": ("light red", "black"),
            "comment": ("dark gray", "black"),
            "docstring": ("dark gray", "black"),
            "argument": ("brown", "black"),
            "pseudo": ("brown", "black"),
            "string": ("yellow", "black"),
            # }}}
        }

        # }}}
    elif theme == "monokai-256":
        # {{{ monokai-256

        # Give the colors some comprehensible names
        black = "h236"
        blacker = "h234"
        dark_gray = "h240"
        dark_green = "h28"
        dark_red = "h124"
        dark_teal = "h30"
        dark_magenta = "h141"
        light_blue = "h111"
        light_cyan = "h51"
        light_gray = "h252"
        light_green = "h155"
        light_red = "h160"
        light_magenta = "h198"
        medium_gray = "h243"
        orange = "h208"
        white = "h255"
        yellow = "h228"
        link("current breakpoint", "current frame name")
        link("focused current breakpoint", "focused current frame name")
        palette_dict = {

            # {{{ base styles
            "background": (black, light_gray),
            "selectable": (white, blacker),
            "focused selectable": (white, dark_gray),
            "highlighted": (white, dark_green),
            "hotkey": (add_setting(black, "underline"), light_gray),
            # }}}
            # {{{ general ui
            "input": (white, black),
            "button": (add_setting(white, "bold"), black),
            "focused button": (add_setting(white, "bold"), dark_gray),
            "focused sidebar": (dark_teal, light_gray),
            "warning": (add_setting(white, "bold"), dark_red),
            "group head": (add_setting(black, "bold"), light_gray),
            "dialog title": (add_setting(white, "bold"), blacker),
            # }}}
            # {{{ source view
            "source": (white, black),
            "current source": (add_setting(light_gray, "bold"), dark_teal),
            "breakpoint source": (add_setting(white, "bold"), dark_red),
            "line number": (dark_gray, black),
            "current line marker": (add_setting(light_cyan, "bold"), black),
            "breakpoint marker": (add_setting(light_red, "bold"), black),
            # }}}
            # {{{ sidebar
            "sidebar two": (light_cyan, blacker),
            "focused sidebar two": (light_cyan, dark_gray),
            "sidebar three": (dark_magenta, blacker),
            "focused sidebar three": (dark_magenta, dark_gray),
            # }}}
            # {{{ variables view
            "highlighted var label": (light_gray, dark_green),
            "return label": (light_green, blacker),
            "focused return label": (light_green, dark_gray),
            # }}}
            # {{{ stack
            "current frame name": (light_green, blacker),
            "focused current frame name": (light_green, dark_gray),
            # }}}
            # {{{ shell
            "command line prompt": (add_setting(yellow, "bold"), black),
            "command line output": (light_cyan, black),
            "command line error": (orange, black),
            "focused command line output": (light_cyan, dark_gray),
            "focused command line error": (add_setting(orange,
                                                       "bold"), dark_gray),
            # }}}
            # {{{ Code syntax
            "literal": (dark_magenta, black),
            "builtin": (light_cyan, black),
            "exception": (light_cyan, black),
            "keyword2": (light_cyan, black),
            "function": (light_green, black),
            "class": (add_setting(light_green, "underline"), black),
            "keyword": (light_magenta, black),
            "operator": (light_magenta, black),
            "comment": (medium_gray, black),
            "docstring": (medium_gray, black),
            "argument": (orange, black),
            "pseudo": (orange, black),
            "string": (yellow, black),
            # }}}
        }
        # }}}
    elif theme == "mono":
        # {{{ mono
        palette_dict = {
            "background": ("standout", ),
            "selectable": (),
            "focused selectable": ("underline", ),
            "highlighted": ("bold", ),
            "hotkey": ("underline, standout", ),
        }
        # }}}
    else:
        # {{{ custom
        try:
            # {{{ base styles
            palette_dict = {
                "background": ("black", "light gray"),
                "hotkey": (add_setting("black", "underline"), "light gray"),
                "selectable": ("black", "dark cyan"),
                "focused selectable": ("black", "dark green"),
                "input": (add_setting("yellow", "bold"), "dark blue"),
                "warning": (add_setting("white", "bold"), "dark red"),
                "highlighted": ("white", "dark cyan"),
                "source": ("white", "dark blue"),
            }
            # }}}

            symbols = {
                "palette": palette_dict,
                "add_setting": add_setting,
                "link": link,
            }

            from os.path import expanduser, expandvars
            fname = expanduser(expandvars(theme))
            with open(fname) as inf:
                exec(compile(inf.read(), fname, "exec"), symbols)
        except FileNotFoundError:
            ui_log.error(
                "Unable to locate custom theme file {!r}".format(theme))
            return None
        except Exception:
            ui_log.exception("Error when importing theme:")
            return None
        # }}}

    # }}}

    # Apply style inheritance
    for style_name in set(INHERITANCE_MAP.keys()).union(BASE_STYLES.keys()):
        get_style(palette_dict, style_name, inheritance_overrides)

    palette_list = [
        astuple(entry) for entry in palette_dict.values()
        if isinstance(entry, PaletteEntry)
    ]

    return palette_list
Ejemplo n.º 8
0
    def walk_value(self, parent, label, value, id_path=None, attr_prefix=None):
        if id_path is None:
            id_path = label

        iinfo = self.frame_var_info.get_inspect_info(id_path, read_only=True)

        if isinstance(value, integer_types + (float, complex)):
            self.add_item(parent, label, repr(value), id_path, attr_prefix)
        elif isinstance(value, string_types):
            self.add_item(parent, label, repr(value), id_path, attr_prefix)
        elif value is None:
            self.add_item(parent, label, repr(value), id_path, attr_prefix)
        else:
            try:
                displayed_value = get_stringifier(iinfo)(value)
            except Exception:
                # Unfortunately, anything can happen when calling str() or
                # repr() on a random object.
                displayed_value = type_stringifier(value) \
                                + " (!! %s error !!)" % iinfo.display_type
                ui_log.exception("stringifier failed")

            if iinfo.show_detail:
                if iinfo.access_level == "public":
                    marker = "pub"
                elif iinfo.access_level == "private":
                    marker = "pri"
                else:
                    marker = "all"
                if iinfo.show_methods:
                    marker += "+()"
                displayed_value += " [%s]" % marker

            new_parent_item = self.add_item(parent, label, displayed_value,
                                            id_path, attr_prefix)

            if not iinfo.show_detail:
                return

            # set ---------------------------------------------------------
            if isinstance(value, (set, frozenset)):
                for i, entry in enumerate(value):
                    if i % 10 == 0 and i:
                        cont_id_path = "%s.cont-%d" % (id_path, i)
                        if not self.frame_var_info.get_inspect_info(
                                cont_id_path, read_only=True).show_detail:
                            self.add_item(new_parent_item, "...", None,
                                          cont_id_path)
                            break

                    self.walk_value(new_parent_item, None, entry,
                                    "%s[%d]" % (id_path, i))
                if not value:
                    self.add_item(new_parent_item, "<empty>", None)
                return

            # containers --------------------------------------------------
            key_it = None

            try:
                key_it = value.keys()
            except AttributeError:
                # keys or iterkeys doesn't exist, not worth mentioning!
                pass
            except Exception:
                ui_log.exception("Failed to obtain key iterator")

            if key_it is None:
                try:
                    len_value = len(value)
                except (AttributeError, TypeError):
                    # no __len__ defined on the value, not worth mentioning!
                    pass
                except Exception:
                    ui_log.exception("Failed to determine container length")
                else:
                    try:
                        value[0]
                    except (LookupError, TypeError):
                        key_it = []
                    except Exception:
                        ui_log.exception("Item is not iterable")
                    else:
                        key_it = xrange(len_value)

            if key_it is not None:
                cnt = 0
                for key in key_it:
                    if cnt % 10 == 0 and cnt:
                        cont_id_path = "%s.cont-%d" % (id_path, cnt)
                        if not self.frame_var_info.get_inspect_info(
                                cont_id_path, read_only=True).show_detail:
                            self.add_item(new_parent_item, "...", None,
                                          cont_id_path)
                            break

                    try:
                        next_value = value[key]
                    except (LookupError, TypeError):
                        ui_log.exception("Failed to iterate an item that "
                                         "appeared to be iterable.")
                        break

                    self.walk_value(new_parent_item, repr(key), next_value,
                                    "%s[%r]" % (id_path, key))
                    cnt += 1
                if not cnt:
                    self.add_item(new_parent_item, "<empty>", None)
                return

            # class types -------------------------------------------------
            key_its = []

            try:
                key_its.append(dir(value))
            except Exception:
                ui_log.exception("Failed to look up attributes")

            keys = [key for ki in key_its for key in ki]
            keys.sort()

            cnt_omitted_private = cnt_omitted_methods = 0

            for key in keys:
                if iinfo.access_level == "public":
                    if key.startswith("_"):
                        cnt_omitted_private += 1
                        continue
                elif iinfo.access_level == "private":
                    if key.startswith("__") and key.endswith("__"):
                        cnt_omitted_private += 1
                        continue

                try:
                    attr_value = getattr(value, key)
                    if inspect.isroutine(
                            attr_value) and not iinfo.show_methods:
                        cnt_omitted_methods += 1
                        continue
                except Exception:
                    attr_value = WatchEvalError()

                self.walk_value(new_parent_item, ".%s" % key, attr_value,
                                "%s.%s" % (id_path, key))

            if not keys:
                if cnt_omitted_private:
                    label = "<omitted private attributes>"
                elif cnt_omitted_methods:
                    label = "<omitted methods>"
                else:
                    label = "<empty>"
                self.add_item(new_parent_item, label, None)

            if not key_its:
                self.add_item(new_parent_item, "<?>", None)