Pastebin

Paste #1758: None

< previous paste - next paste>

Pasted by chrivers@eos

Download View as text

import spye
import traceback
import os
import sys
import re

class plugin(spye.plugin):
    """Default output plugin"""

    buffer       = None

    cl_normal    = ''
    cl_strong    = ''
    cl_blink     = ''

    fg_black     = ''
    fg_red       = ''
    fg_green     = ''
    fg_yellow    = ''
    fg_blue      = ''
    fg_magenta   = ''
    fg_cyan      = ''
    fg_white     = ''

    bg_black     = ''
    bg_red       = ''
    bg_green     = ''
    bg_yellow    = ''
    bg_blue      = ''
    bg_magenta   = ''
    bg_cyan      = ''
    bg_white     = ''
    bg_normal    = ''

    prompts        = []
    severity_codes = {
        3: "F",
        2: "E",
        1: "W", 
        0: "*",
        -1: "H",
        -2: "D",
        -3: "M"
        }
    
    def configure(self, **args):
        self.wfile = sys.stdout

    def enter(self):
        pass

    def leave(self):
        pass

    def buffer_start(self):
        self.buffer = ""

    def buffer_end(self, discard = False):
        buffer = self.buffer
        self.buffer = None
        if not discard:
            self.write(self.buffer)
        return self.buffer

    def write(self, msg):
        try:
            if self.buffer == None:
                if type(msg) == unicode:
                    return self.wfile.write(msg.encode('utf-8'))
                else:
                    return self.wfile.write(msg)
            else:
                if type(msg) == unicode:
                    self.buffer += msg.encode('utf-8')
                else:
                    self.buffer += msg
        except UnicodeEncodeError, e:
            print "Invalid unicode data: %s" % e
            print msg

    def flush(self):
        return sys.stdout.flush()

    def prompt_begin(self, s):
        """FOO"""
        self.prompts.append(s)

    def prompt_end(self):
        self.prompts.pop()

    def prompt_size(self, s):
        return len(re.sub("\x1B\[0(.m|1;[34].m)", "", s))

    def prompt_print(self):
        self.write("%s%s" % (self.prompts[-1], self.editor.getline()))

    def prompt_make(self, p):
        blue, white, normal = spye.drv_output.fg_blue, spye.drv_output.fg_white, spye.drv_output.cl_normal

        return "%s[%sI%s]%s %s" % (blue, white, blue, normal, p)

    def output_log(self, sev, debug, msg, *fmt):
        if debug:
            inset = "%s: " % debug
        else:
            inset = ""
        self.write("[%s] %s%s\n" % (self.severity_codes[sev], inset, msg % spye.utf8_encode_list(fmt, (int, float, str))))

    def output_line(self, debug, msg, *fmt):
        self.write("    %s\n" % (msg % spye.utf8_encode_list(fmt, (int, float, str))))

    def output_progress(self, percent, message = "", prefix = "", width = 42):
        pass

    def output_progress_end(self, clear = True):
        pass

    def output_exception(self):
        self.output_traceback(traceback.extract_tb(sys.exc_info()[2]))
        if sys.exc_info()[1].args:
            self.output_log(2, None, "Exception information:")
            for line in str(sys.exc_info()[1]).rstrip().split('\n'):
                self.output_line(None, ">> %s", line)

    def output_backtrace(self):
        self.output_traceback(traceback.extract_stack())

    def output_traceback(self, tb):
        fmtstring = "%-20s %5s  %s"
        self.output_line(None, self.fg_white + fmtstring + self.cl_normal, "Function", "Line", "File")
        for (fname, line, func, text) in tb:
            self.output_line(None, fmtstring, func, line, fname)

        fmtstring = "%-20s %5s  %-20s %s"
        self.output_line(None, self.fg_white + fmtstring + self.cl_normal, "Function", "Line", "Function", "Code")
        for (fname, line, func, text) in tb:
            self.output_line(None, fmtstring, os.path.basename(fname), line, func, text)

New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.