Exemple #1
0
 def __str__(self):
     # Standard Behavior of an exception is to produce a string representation of its arguments
     # when called with str(). In order to maintain compatability with previous versions which
     # passed only the message to the superclass constructor, __str__ method is implemented to
     # provide the same result as was produced in the past.
     message = "\n" + 75 * "-" + "\n"
     message += 'Exception encountered at "In [%s]":\n' % str(
         self.exec_count)
     message += strip_color("\n".join(self.traceback))
     message += "\n"
     return message
Exemple #2
0
    def __init__(self, exec_count, source, ename, evalue, traceback):
        self.exec_count = exec_count
        self.source = source
        self.ename = ename
        self.evalue = evalue
        self.traceback = traceback
        message = "\n" + 75 * "-" + "\n"
        message += 'Exception encountered at "In [%s]":\n' % str(exec_count)
        message += strip_color("\n".join(traceback))
        message += "\n"

        super(PapermillExecutionError, self).__init__(message)
Exemple #3
0
    def pprint(self, short=False):
        """Returns a pretty-printed version of the entry.
        If short is true, only print the title."""
        # Handle indentation
        if self.journal.config["indent_character"]:
            indent = self.journal.config["indent_character"].rstrip() + " "
        else:
            indent = ""

        date_str = colorize(
            self.date.strftime(self.journal.config["timeformat"]),
            self.journal.config["colors"]["date"],
            bold=True,
        )

        if not short and self.journal.config["linewrap"]:
            # Color date / title and bold title
            title = ansiwrap.fill(
                date_str
                + " "
                + highlight_tags_with_background_color(
                    self,
                    self.title,
                    self.journal.config["colors"]["title"],
                    is_title=True,
                ),
                self.journal.config["linewrap"],
            )
            body = highlight_tags_with_background_color(
                self, self.body.rstrip(" \n"), self.journal.config["colors"]["body"]
            )
            body_text = [
                colorize(
                    ansiwrap.fill(
                        line,
                        self.journal.config["linewrap"],
                        initial_indent=indent,
                        subsequent_indent=indent,
                        drop_whitespace=True,
                    ),
                    self.journal.config["colors"]["body"],
                )
                or indent
                for line in body.rstrip(" \n").splitlines()
            ]

            # ansiwrap doesn't handle lines with only the "\n" character and some
            # ANSI escapes properly, so we have this hack here to make sure the
            # beginning of each line has the indent character and it's colored
            # properly. textwrap doesn't have this issue, however, it doesn't wrap
            # the strings properly as it counts ANSI escapes as literal characters.
            # TL;DR: I'm sorry.
            body = "\n".join(
                [
                    colorize(indent, self.journal.config["colors"]["body"]) + line
                    if not ansiwrap.strip_color(line).startswith(indent)
                    else line
                    for line in body_text
                ]
            )
        else:
            title = (
                date_str
                + " "
                + highlight_tags_with_background_color(
                    self,
                    self.title.rstrip("\n"),
                    self.journal.config["colors"]["title"],
                    is_title=True,
                )
            )
            body = highlight_tags_with_background_color(
                self, self.body.rstrip("\n "), self.journal.config["colors"]["body"]
            )

        # Suppress bodies that are just blanks and new lines.
        has_body = len(self.body) > 20 or not all(
            char in (" ", "\n") for char in self.body
        )

        if short:
            return title
        else:
            return "{title}{sep}{body}\n".format(
                title=title, sep="\n" if has_body else "", body=body if has_body else ""
            )