Example #1
0
def format_exception_only(etype, value):
    """This function is special version for IronPython
    """
    import types
    import traceback

    if (isinstance(etype, types.InstanceType) or
        etype is None or isinstance(etype, basestring)):
        return [traceback._format_final_exc_line(etype, value)]

    stype = etype.__name__

    if not issubclass(etype, SyntaxError):
        return [traceback._format_final_exc_line(stype, value)]

    # It was a syntax error; show exactly where the problem was found.
    lines = []
    try:
        msg, (filename, lineno, offset, badline) = value
    except Exception:
        pass
    else:
        filename = filename or "<string>"
        lines.append('  File "%s", line %d\n' % (filename, lineno))
        if badline is not None:
            lines.append('    %s\n' % badline.strip())
            if offset is not None:
                caretspace = badline[:offset].lstrip()
                caretspace = ((c.isspace() and c or ' ') for c in caretspace)
                lines.append('   %s^\n' % ''.join(caretspace))
            value = msg

    lines.append(traceback._format_final_exc_line(stype, value))
    return lines
Example #2
0
def format_exception_only(etype, value):
    """This function is special version for IronPython
    """
    import types
    import traceback

    if isinstance(etype, types.InstanceType) or etype is None or isinstance(etype, basestring):
        return [traceback._format_final_exc_line(etype, value)]

    stype = etype.__name__

    if not issubclass(etype, SyntaxError):
        return [traceback._format_final_exc_line(stype, value)]

    # It was a syntax error; show exactly where the problem was found.
    lines = []
    try:
        msg, (filename, lineno, offset, badline) = value
    except Exception:
        pass
    else:
        filename = filename or "<string>"
        lines.append('  File "%s", line %d\n' % (filename, lineno))
        if badline is not None:
            lines.append("    %s\n" % badline.strip())
            if offset is not None:
                caretspace = badline[:offset].lstrip()
                caretspace = ((c.isspace() and c or " ") for c in caretspace)
                lines.append("   %s^\n" % "".join(caretspace))
            value = msg

    lines.append(traceback._format_final_exc_line(stype, value))
    return lines
Example #3
0
def traceback_exception_format_exception_only(self):
    """Format the exception part of the traceback.
    The return value is a generator of strings, each ending in a newline.
    Normally, the generator emits a single string; however, for
    SyntaxError exceptions, it emits several lines that (when
    printed) display detailed information about where the syntax
    error occurred.
    The message indicating which exception occurred is always the last
    string in the output.
    """
    if self.exc_type is None:
        yield traceback._format_final_exc_line(None, self._str)
        return

    stype = self.exc_type.__qualname__
    smod = self.exc_type.__module__
    if smod not in ("__main__", "builtins"):
        if not isinstance(smod, str):
            smod = "<unknown>"
        stype = smod + "." + stype

    if not issubclass(self.exc_type, SyntaxError):
        yield _format_final_exc_line(stype, self._str)
    elif traceback_exception_format_syntax_error is not None:
        yield from traceback_exception_format_syntax_error(self, stype)
    else:
        yield from traceback_exception_original_format_exception_only(self)

    if isinstance(self.__notes__, collections.abc.Sequence):
        for note in self.__notes__:
            note = _safe_string(note, "note")
            yield from [line + "\n" for line in note.split("\n")]
    elif self.__notes__ is not None:
        yield _safe_string(self.__notes__, "__notes__", func=repr)
Example #4
0
    async def load(self, name: str = ''):
        'Attempt to load the specified extension'
        if not name:
            await self.bot.say('You must specify an extension to load')
            return

        plain_name = name.replace('.', '')
        if plain_name.startswith('ext'):
            plain_name = plain_name[3:]
        lib_name = 'ext.{}'.format(plain_name)

        if lib_name in self.bot.extensions:
            await self.bot.say(
                '`{}` extension is already loaded'.format(plain_name))
            return

        try:
            self.bot.load_extension(lib_name)
            self.logger.info('Successfully loaded extension: %s', plain_name)
            await self.bot.say(
                'Successfully loaded extension: `{}`'.format(plain_name))
            loaded_extensions = self.bot.config['loaded_extensions']
            loaded_extensions.append(plain_name)
            self.bot.config['loaded_extensions'] = loaded_extensions
        except Exception as exc:
            if isinstance(exc, ModuleNotFoundError) and getattr(
                    exc, "name") == lib_name:
                await self.bot.say('Extension not found: `{}`'.format(name))
                return

            error_str = _format_final_exc_line(type(exc).__qualname__,
                                               exc).strip()
            self.logger.exception('Failed to load extension: %s', plain_name)
            await self.bot.say('Failed to load extension: `{}` - `{}`'.format(
                plain_name, error_str))
            if lib_name in sys.modules:
                del sys.modules[lib_name]
Example #5
0
            sys.exit(APP_SUCCESS if v == APP_DONE else APP_FAIL)
        app = vistrails.gui.application.get_vistrails_application()()
    except SystemExit, e:
        app = vistrails.gui.application.get_vistrails_application()
        if app:
            app.finishSession()
        reportusage.submit_usage_report(result='init exit %s' %
                                               getattr(e, 'code', '(unknown)'))
        sys.exit(e)
    except Exception, e:
        app = vistrails.gui.application.get_vistrails_application()
        if app:
            app.finishSession()
        import traceback
        print >>sys.stderr, "Uncaught exception on initialization: %s" % (
                traceback._format_final_exc_line(type(e).__name__, e).strip())
        traceback.print_exc(None, sys.stderr)
        reportusage.submit_usage_report(result='init %s' % type(e).__name__)
        sys.exit(255)

    try:
        if not app.temp_configuration.batch:
            v = app.exec_()
        vistrails.gui.application.stop_application()
    except BaseException, e:
        reportusage.submit_usage_report(result=type(e).__name__)
        raise
    reportusage.submit_usage_report(result='success %s' % v)
    sys.exit(v)

if __name__ == '__main__':
Example #6
0
 def update_event(self, inp=-1):
     self.set_output_val(
         0, traceback._format_final_exc_line(self.input(0), self.input(1)))
Example #7
0
def format_exception(e):
    """Formats an exception as a single-line (no traceback).

    Use this instead of str() which might drop the exception type.
    """
    return traceback._format_final_exc_line(type(e).__name__, e)
Example #8
0
def format_exception(e):
    """Formats an exception as a single-line (no traceback).

    Use this instead of str() which might drop the exception type.
    """
    return traceback._format_final_exc_line(type(e).__name__, e)
Example #9
0
def _format_exc(exc, message=None):
    if message is None:
        message = exc
    exc_str = traceback._format_final_exc_line(exc.__class__.__name__, message)
    return exc_str.rstrip()
Example #10
0
def _format_exc(exc, message=None):
    if message is None:
        message = exc
    exc_str = traceback._format_final_exc_line(exc.__class__.__name__, message)
    return exc_str.rstrip()