• Facebook
  • Twitter
  • Reddit
  • StumbleUpon
  • Digg
  • email

All Samples(952)  |  Call(937)  |  Derive(0)  |  Import(15)
Format the exception part of a traceback.

The arguments are the exception type and value such as given by
sys.last_type and sys.last_value. The return value is a list of
strings, each ending in a newline.

Normally, the list contains a single string; however, for
SyntaxError exceptions, it contains 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 list.

        def format_exception_only(etype, value):
    """Format the exception part of a traceback.

    The arguments are the exception type and value such as given by
    sys.last_type and sys.last_value. The return value is a list of
    strings, each ending in a newline.

    Normally, the list contains a single string; however, for
    SyntaxError exceptions, it contains 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 list.

    """

    # An instance should not have a meaningful value parameter, but
    # sometimes does, particularly for string exceptions, such as
    # >>> raise string1, string2  # deprecated
    #
    # Clear these out first because issubtype(string1, SyntaxError)
    # would throw another exception and mask the original problem.
    if (isinstance(etype, BaseException) or
        isinstance(etype, types.InstanceType) or
        etype is None or type(etype) is str):
        return [_format_final_exc_line(etype, value)]

    stype = etype.__name__

    if not issubclass(etype, SyntaxError):
        return [_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.args
    except Exception:
        pass
    else:
        filename = filename or ""
        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.rstrip('\n')[:offset].lstrip()
                # non-space whitespace (likes tabs) must be kept for alignment
                caretspace = ((c.isspace() and c or ' ') for c in caretspace)
                # only three spaces to account for offset1 == pos 0
                lines.append('   %s^\n' % ''.join(caretspace))
        value = msg

    lines.append(_format_final_exc_line(stype, value))
    return lines
        


src/l/e/LEPL-4.3.2/src/lepl/_example/support.py   LEPL(Download)
 
from logging import getLogger
from unittest import TestCase
from traceback import format_exception_only, format_exc
 
from lepl._test.base import assert_str
 
                result = str(example())
            except Exception as e:
                getLogger('lepl._example.support.Example').debug(format_exc())
                result = ''.join(format_exception_only(type(e), e))
            assert_str(target, result)
 

src/p/y/pyobjc-framework-Cocoa-2.3/Examples/AppKit/PythonBrowser/PythonBrowserModel.py   pyobjc-framework-Cocoa(Download)
    def __repr__(self):
        from traceback import format_exception_only
        lines = format_exception_only(*self.exc_info[:2])
        assert len(lines) == 1
        error = lines[0].strip()
        return "*** error *** %s" %error
 

src/i/r/ironruby-HEAD/External.LCA_RESTRICTED/Languages/IronPython/27/Doc/sphinx/ext/ifconfig.py   ironruby(Download)
            res = eval(node['expr'], ns)
        except Exception, err:
            # handle exceptions in a clean fashion
            from traceback import format_exception_only
            msg = ''.join(format_exception_only(err.__class__, err))
            newnode = doctree.reporter.error('Exception occured in '
                                             'ifconfig expression: \n%s' %

src/z/a/zamboni-lib-HEAD/lib/python/sphinx/ext/ifconfig.py   zamboni-lib(Download)
            res = eval(node['expr'], ns)
        except Exception, err:
            # handle exceptions in a clean fashion
            from traceback import format_exception_only
            msg = ''.join(format_exception_only(err.__class__, err))
            newnode = doctree.reporter.error('Exception occured in '
                                             'ifconfig expression: \n%s' %

src/n/o/noc-0.5/contrib/src/Sphinx/sphinx/ext/ifconfig.py   noc(Download)
            res = eval(node['expr'], ns)
        except Exception, err:
            # handle exceptions in a clean fashion
            from traceback import format_exception_only
            msg = ''.join(format_exception_only(err.__class__, err))
            newnode = doctree.reporter.error('Exception occured in '
                                             'ifconfig expression: \n%s' %

src/f/l/Flask-FluidDB-0.1/env/lib/python2.6/site-packages/sphinx/ext/ifconfig.py   Flask-FluidDB(Download)
            res = eval(node['expr'], ns)
        except Exception, err:
            # handle exceptions in a clean fashion
            from traceback import format_exception_only
            msg = ''.join(format_exception_only(err.__class__, err))
            newnode = doctree.reporter.error('Exception occured in '
                                             'ifconfig expression: \n%s' %

src/s/p/Sphinx-1.0.4/sphinx/ext/ifconfig.py   Sphinx(Download)
            res = eval(node['expr'], ns)
        except Exception, err:
            # handle exceptions in a clean fashion
            from traceback import format_exception_only
            msg = ''.join(format_exception_only(err.__class__, err))
            newnode = doctree.reporter.error('Exception occured in '
                                             'ifconfig expression: \n%s' %

src/h/g/hgblog-0.5/sphinx/ext/ifconfig.py   hgblog(Download)
            res = eval(node['expr'], ns)
        except Exception, err:
            # handle exceptions in a clean fashion
            from traceback import format_exception_only
            msg = ''.join(format_exception_only(err.__class__, err))
            newnode = doctree.reporter.error('Exception occured in '
                                             'ifconfig expression: \n%s' %

src/k/i/kid-0.9.6/kid/codewriter.py   kid(Download)
 
import sys, re
from os.path import splitext
from traceback import extract_tb, format_exception_only
 
from kid import __version__, Namespace
from kid.parser import document, START, END, TEXT, XML_DECL, DOCTYPE, LOCATION
            break
    else:
        s = ['Error in code generated from template file %r' % filename]
    s = ''.join(format_exception_only(exc_type, exc_value)[:-1]) + '\n'.join(s)
    if isinstance(exc_type, str):
        exc_type += '\n' + s
    else:

src/n/o/nosetty-0.4/nosetty/nosetty.py   nosetty(Download)
    from pinocchio.output_save import calc_testname
except ImportError:
    calc_testname = None
from traceback import extract_tb, format_exception_only
try:
    import cPickle as pickle
except ImportError:
                    print_('       %s' % line.strip())
                marker -= 1
 
            lines = format_exception_only(etype, value)
            for line in lines[:-1]:
                print_(line, ' ')
            print_(lines[-1], '')

  1 | 2  Next