当前位置: 首页>>代码示例>>Python>>正文


Python sys.last_type方法代码示例

本文整理汇总了Python中sys.last_type方法的典型用法代码示例。如果您正苦于以下问题:Python sys.last_type方法的具体用法?Python sys.last_type怎么用?Python sys.last_type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sys的用法示例。


在下文中一共展示了sys.last_type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_with_api

# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_type [as 别名]
def run_with_api(self, code):
        """Run code with didyoumean after enabling didyoumean hook."""
        prev_hook = sys.excepthook
        self.assertEqual(prev_hook, sys.excepthook)
        didyoumean_enablehook()
        self.assertNotEqual(prev_hook, sys.excepthook)
        try:
            no_exception(code)
        except:
            last_type, last_value, last_traceback = sys.exc_info()
            with suppress_stderr():
                sys.excepthook(last_type, last_value, last_traceback)
            raise
        finally:
            self.assertNotEqual(prev_hook, sys.excepthook)
            didyoumean_disablehook()
            self.assertEqual(prev_hook, sys.excepthook) 
开发者ID:SylvainDe,项目名称:DidYouMean-Python,代码行数:19,代码来源:didyoumean_api_tests.py

示例2: showtraceback

# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_type [as 别名]
def showtraceback(self):
        """Display the exception that just occurred.

        We remove the first stack item because it is our own code.

        The output is written by self.write(), below.

        """
        try:
            type, value, tb = sys.exc_info()
            sys.last_type = type
            sys.last_value = value
            sys.last_traceback = tb
            tblist = traceback.extract_tb(tb)
            del tblist[:1]
            list = traceback.format_list(tblist)
            if list:
                list.insert(0, "Traceback (most recent call last):\n")
            list[len(list):] = traceback.format_exception_only(type, value)
        finally:
            tblist = tb = None
        map(self.write, list) 
开发者ID:glmcdona,项目名称:meddle,代码行数:24,代码来源:code.py

示例3: test_base_exception

# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_type [as 别名]
def test_base_exception(self):
        # Test that exceptions derived from BaseException are formatted right
        e = KeyboardInterrupt()
        lst = traceback.format_exception_only(e.__class__, e)
        self.assertEqual(lst, ['KeyboardInterrupt\n'])

    # String exceptions are deprecated, but legal.  The quirky form with
    # separate "type" and "value" tends to break things, because
    #     not isinstance(value, type)
    # and a string cannot be the first argument to issubclass.
    #
    # Note that sys.last_type and sys.last_value do not get set if an
    # exception is caught, so we sort of cheat and just emulate them.
    #
    # test_string_exception1 is equivalent to
    #
    # >>> raise "String Exception"
    #
    # test_string_exception2 is equivalent to
    #
    # >>> raise "String Exception", "String Value"
    # 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_traceback.py

示例4: print_exception

# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_type [as 别名]
def print_exception():
    import linecache
    linecache.checkcache()
    flush_stdout()
    efile = sys.stderr
    typ, val, tb = excinfo = sys.exc_info()
    sys.last_type, sys.last_value, sys.last_traceback = excinfo
    tbe = traceback.extract_tb(tb)
    print>>efile, '\nTraceback (most recent call last):'
    exclude = ("run.py", "rpc.py", "threading.py", "Queue.py",
               "RemoteDebugger.py", "bdb.py")
    cleanup_traceback(tbe, exclude)
    traceback.print_list(tbe, file=efile)
    lines = traceback.format_exception_only(typ, val)
    for line in lines:
        print>>efile, line, 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:18,代码来源:run.py

示例5: _stack_viewer

# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_type [as 别名]
def _stack_viewer(parent):
    root = tk.Tk()
    root.title("Test StackViewer")
    width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
    root.geometry("+%d+%d"%(x, y + 150))
    flist = PyShellFileList(root)
    try: # to obtain a traceback object
        intentional_name_error
    except NameError:
        exc_type, exc_value, exc_tb = sys.exc_info()

    # inject stack trace to sys
    sys.last_type = exc_type
    sys.last_value = exc_value
    sys.last_traceback = exc_tb

    StackBrowser(root, flist=flist, top=root, tb=exc_tb)

    # restore sys to original state
    del sys.last_type
    del sys.last_value
    del sys.last_traceback 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:24,代码来源:StackViewer.py

示例6: showtraceback

# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_type [as 别名]
def showtraceback(self, *args, **kwargs):
        """Display the exception that just occurred.

        We remove the first stack item because it is our own code.

        The output is written by self.write(), below.

        """
        try:
            type, value, tb = sys.exc_info()
            sys.last_type = type
            sys.last_value = value
            sys.last_traceback = tb
            tblist = traceback.extract_tb(tb)
            del tblist[:1]
            list = traceback.format_list(tblist)
            if list:
                list.insert(0, "Traceback (most recent call last):\n")
            list[len(list):] = traceback.format_exception_only(type, value)
        finally:
            tblist = tb = None
        map(self.write, list) 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:24,代码来源:pydevconsole_code_for_ironpython.py

示例7: showsyntaxerror

# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_type [as 别名]
def showsyntaxerror(self, filename=None):
        """Display the syntax error that just occurred."""
        # Override for avoid using sys.excepthook PY-12600
        type, value, tb = sys.exc_info()
        sys.last_type = type
        sys.last_value = value
        sys.last_traceback = tb
        if filename and type is SyntaxError:
            # Work hard to stuff the correct filename in the exception
            try:
                msg, (dummy_filename, lineno, offset, line) = value.args
            except ValueError:
                # Not the format we expect; leave it alone
                pass
            else:
                # Stuff in the right filename
                value = SyntaxError(msg, (filename, lineno, offset, line))
                sys.last_value = value
        list = traceback.format_exception_only(type, value)
        sys.stderr.write(''.join(list)) 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:22,代码来源:pydevconsole.py

示例8: showtraceback

# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_type [as 别名]
def showtraceback(self, *args, **kwargs):
        """Display the exception that just occurred."""
        # Override for avoid using sys.excepthook PY-12600
        try:
            type, value, tb = sys.exc_info()
            sys.last_type = type
            sys.last_value = value
            sys.last_traceback = tb
            tblist = traceback.extract_tb(tb)
            del tblist[:1]
            lines = traceback.format_list(tblist)
            if lines:
                lines.insert(0, "Traceback (most recent call last):\n")
            lines.extend(traceback.format_exception_only(type, value))
        finally:
            tblist = tb = None
        sys.stderr.write(''.join(lines)) 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:19,代码来源:pydevconsole.py

示例9: pytest_runtest_call

# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_type [as 别名]
def pytest_runtest_call(item: Item) -> None:
    _update_current_test_var(item, "call")
    try:
        del sys.last_type
        del sys.last_value
        del sys.last_traceback
    except AttributeError:
        pass
    try:
        item.runtest()
    except Exception as e:
        # Store trace info to allow postmortem debugging
        sys.last_type = type(e)
        sys.last_value = e
        assert e.__traceback__ is not None
        # Skip *this* frame
        sys.last_traceback = e.__traceback__.tb_next
        raise e 
开发者ID:pytest-dev,项目名称:pytest,代码行数:20,代码来源:runner.py

示例10: format_exception_only

# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_type [as 别名]
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.

    """
    return list(TracebackException(etype, value, None).format_exception_only())


# -- not offical API but folk probably use these two functions. 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:traceback.py

示例11: showtraceback

# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_type [as 别名]
def showtraceback(self):
        """Display the exception that just occurred.

        We remove the first stack item because it is our own code.

        The output is written by self.write(), below.

        """
        sys.last_type, sys.last_value, last_tb = ei = sys.exc_info()
        sys.last_traceback = last_tb
        try:
            lines = traceback.format_exception(ei[0], ei[1], last_tb.tb_next)
            if sys.excepthook is sys.__excepthook__:
                self.write(''.join(lines))
            else:
                # If someone has set sys.excepthook, we let that take precedence
                # over self.write
                sys.excepthook(ei[0], ei[1], last_tb)
        finally:
            last_tb = ei = None 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:code.py

示例12: format_exception_only

# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_type [as 别名]
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.

    """
    return list(TracebackException(etype, value, None).format_exception_only())


# -- not official API but folk probably use these two functions. 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:22,代码来源:traceback.py

示例13: format_exception_only

# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_type [as 别名]
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.

    """
    return list(_format_exception_only_iter(etype, value)) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:19,代码来源:traceback.py

示例14: format

# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_type [as 别名]
def format(self, record):
        base = '[{} {} {}] '.format(record.levelname[0],
                                    time.strftime('%H:%M:%S'),
                                    record.name)
        if isinstance(record.msg, Exception):
            # Get excepion info and skip first frames
            type_, value, tb = sys.exc_info()
            for _ in range(getattr(value, 'skip_tb', 0)):
                tb = tb.tb_next
            # Enable post mortem debugging
            sys.last_type = type_
            sys.last_value = value
            sys.last_traceback = tb
            # Compose message
            cname = type_.__name__
            out = ''.join(traceback.format_list(traceback.extract_tb(tb)))
            del tb  # we don't want to hold too much references to this
            return base + cname + ': ' + str(value) + '\n' + out.rstrip()
        else:
            out = base + str(record.msg % record.args)
            if self.prepend_caller:
                part1, part2 = out.split(':', 1)
                out = part1 + ' ' + record.funcName + '():' + part2
            return out 
开发者ID:flexxui,项目名称:flexx,代码行数:26,代码来源:logging.py

示例15: didyoumean_postmortem

# 需要导入模块: import sys [as 别名]
# 或者: from sys import last_type [as 别名]
def didyoumean_postmortem():
    """Post postem function to add suggestions to last exception thrown.

    Add suggestions to last exception thrown (in interactive mode) and
    return it (which should print it).
    """
    if hasattr(sys, 'last_type'):
        typ, val, trace = sys.last_type, sys.last_value, sys.last_traceback
        add_suggestions_to_exception(typ, val, trace)
        return val
    return None 
开发者ID:SylvainDe,项目名称:DidYouMean-Python,代码行数:13,代码来源:didyoumean_api.py


注:本文中的sys.last_type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。