當前位置: 首頁>>代碼示例>>Python>>正文


Python traceback.walk_tb方法代碼示例

本文整理匯總了Python中traceback.walk_tb方法的典型用法代碼示例。如果您正苦於以下問題:Python traceback.walk_tb方法的具體用法?Python traceback.walk_tb怎麽用?Python traceback.walk_tb使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在traceback的用法示例。


在下文中一共展示了traceback.walk_tb方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: filtered_traceback_format

# 需要導入模塊: import traceback [as 別名]
# 或者: from traceback import walk_tb [as 別名]
def filtered_traceback_format(tb_exception, chain=True):
    if chain:
        if tb_exception.__cause__ is not None:
            yield from filtered_traceback_format(tb_exception.__cause__, chain=chain)
            yield tb._cause_message
        elif (
            tb_exception.__context__ is not None
            and not tb_exception.__suppress_context__
        ):
            yield from filtered_traceback_format(tb_exception.__context__, chain=chain)
            yield tb._context_message
    yield "Traceback (most recent calls WITHOUT Sacred internals):\n"
    current_tb = tb_exception.exc_traceback
    while current_tb is not None:
        if not _is_sacred_frame(current_tb.tb_frame):
            stack = tb.StackSummary.extract(
                tb.walk_tb(current_tb), limit=1, lookup_lines=True, capture_locals=False
            )
            yield from stack.format()
        current_tb = current_tb.tb_next
    yield from tb_exception.format_exception_only()


# noinspection PyUnusedLocal 
開發者ID:IDSIA,項目名稱:sacred,代碼行數:26,代碼來源:utils.py

示例2: test_from_exception

# 需要導入模塊: import traceback [as 別名]
# 或者: from traceback import walk_tb [as 別名]
def test_from_exception(self):
        # Check all the parameters are accepted.
        def foo():
            1/0
        try:
            foo()
        except Exception as e:
            exc_info = sys.exc_info()
            self.expected_stack = traceback.StackSummary.extract(
                traceback.walk_tb(exc_info[2]), limit=1, lookup_lines=False,
                capture_locals=True)
            self.exc = traceback.TracebackException.from_exception(
                e, limit=1, lookup_lines=False, capture_locals=True)
        expected_stack = self.expected_stack
        exc = self.exc
        self.assertEqual(None, exc.__cause__)
        self.assertEqual(None, exc.__context__)
        self.assertEqual(False, exc.__suppress_context__)
        self.assertEqual(expected_stack, exc.stack)
        self.assertEqual(exc_info[0], exc.exc_type)
        self.assertEqual(str(exc_info[1]), str(exc)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:23,代碼來源:test_traceback.py

示例3: test_cause

# 需要導入模塊: import traceback [as 別名]
# 或者: from traceback import walk_tb [as 別名]
def test_cause(self):
        try:
            try:
                1/0
            finally:
                exc_info_context = sys.exc_info()
                exc_context = traceback.TracebackException(*exc_info_context)
                cause = Exception("cause")
                raise Exception("uh oh") from cause
        except Exception:
            exc_info = sys.exc_info()
            exc = traceback.TracebackException(*exc_info)
            expected_stack = traceback.StackSummary.extract(
                traceback.walk_tb(exc_info[2]))
        exc_cause = traceback.TracebackException(Exception, cause, None)
        self.assertEqual(exc_cause, exc.__cause__)
        self.assertEqual(exc_context, exc.__context__)
        self.assertEqual(True, exc.__suppress_context__)
        self.assertEqual(expected_stack, exc.stack)
        self.assertEqual(exc_info[0], exc.exc_type)
        self.assertEqual(str(exc_info[1]), str(exc)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:23,代碼來源:test_traceback.py

示例4: test_context

# 需要導入模塊: import traceback [as 別名]
# 或者: from traceback import walk_tb [as 別名]
def test_context(self):
        try:
            try:
                1/0
            finally:
                exc_info_context = sys.exc_info()
                exc_context = traceback.TracebackException(*exc_info_context)
                raise Exception("uh oh")
        except Exception:
            exc_info = sys.exc_info()
            exc = traceback.TracebackException(*exc_info)
            expected_stack = traceback.StackSummary.extract(
                traceback.walk_tb(exc_info[2]))
        self.assertEqual(None, exc.__cause__)
        self.assertEqual(exc_context, exc.__context__)
        self.assertEqual(False, exc.__suppress_context__)
        self.assertEqual(expected_stack, exc.stack)
        self.assertEqual(exc_info[0], exc.exc_type)
        self.assertEqual(str(exc_info[1]), str(exc)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:21,代碼來源:test_traceback.py

示例5: format_exc

# 需要導入模塊: import traceback [as 別名]
# 或者: from traceback import walk_tb [as 別名]
def format_exc(interested=None, source_path=None, with_normal=True):
    if sys.exc_info() == (None, None, None):
        return "NoTraceback"
    
    source_path = source_path or os.getcwd()
    
    _traceback = ""
    
    for frame, lineno in walk_tb(sys.exc_info()[2]):
        abs_path = frame.f_code.co_filename
        if ".." not in os.path.relpath(abs_path, source_path):
            _traceback += frame_operations.frame_format(
                frame, interested=interested, frame_lineno=lineno
            ) + "\n"
    
    if with_normal:
        _traceback = "{}\n{}".format(traceback.format_exc(), _traceback)
    
    return _traceback 
開發者ID:neargle,項目名稱:ver-observer,代碼行數:21,代碼來源:traceback2.py

示例6: get_data_from_traceback

# 需要導入模塊: import traceback [as 別名]
# 或者: from traceback import walk_tb [as 別名]
def get_data_from_traceback(self, tb):
        session = None
        global_data_in_all_frames = list()
        local_data_in_all_frames = list()

        for frame, line_number in traceback.walk_tb(tb):
            global_data_in_all_frames.append(str(frame.f_globals))
            local_data_in_all_frames.append(str(frame.f_locals))

            # Save the most recent PacuSession called "session", working backwards.
            if session is None:
                session = frame.f_locals.get('session', None)
                if not isinstance(session, PacuSession):
                    session = None

        return session, global_data_in_all_frames, local_data_in_all_frames 
開發者ID:RhinoSecurityLabs,項目名稱:pacu,代碼行數:18,代碼來源:pacu.py

示例7: test_traceback

# 需要導入模塊: import traceback [as 別名]
# 或者: from traceback import walk_tb [as 別名]
def test_traceback():
    try:
        assert_that('foo').is_equal_to('bar')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <foo> to be equal to <bar>, but was not.')
        assert_that(ex).is_type_of(AssertionError)

        # extract all stack frames from the traceback
        _, _, tb = sys.exc_info()
        assert_that(tb).is_not_none()

        # walk_tb added in 3.5
        if sys.version_info[0] == 3 and sys.version_info[1] >= 5:
            frames = [(f.f_code.co_filename, f.f_code.co_name, lineno) for f, lineno in traceback.walk_tb(tb)]

            assert_that(frames).is_length(3)

            assert_that(frames[0][0]).ends_with('test_traceback.py')
            assert_that(frames[0][1]).is_equal_to('test_traceback')
            assert_that(frames[0][2]).is_equal_to(36)

            assert_that(frames[1][0]).ends_with('base.py')
            assert_that(frames[1][1]).is_equal_to('is_equal_to')
            assert_that(frames[1][2]).is_greater_than(40)

            assert_that(frames[2][0]).ends_with('assertpy.py')
            assert_that(frames[2][1]).is_equal_to('error')
            assert_that(frames[2][2]).is_greater_than(100) 
開發者ID:assertpy,項目名稱:assertpy,代碼行數:31,代碼來源:test_traceback.py

示例8: test_walk_tb

# 需要導入模塊: import traceback [as 別名]
# 或者: from traceback import walk_tb [as 別名]
def test_walk_tb(self):
        try:
            1/0
        except Exception:
            _, _, tb = sys.exc_info()
        s = list(traceback.walk_tb(tb))
        self.assertEqual(len(s), 1) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:9,代碼來源:test_traceback.py

示例9: test_smoke

# 需要導入模塊: import traceback [as 別名]
# 或者: from traceback import walk_tb [as 別名]
def test_smoke(self):
        try:
            1/0
        except Exception:
            exc_info = sys.exc_info()
            exc = traceback.TracebackException(*exc_info)
            expected_stack = traceback.StackSummary.extract(
                traceback.walk_tb(exc_info[2]))
        self.assertEqual(None, exc.__cause__)
        self.assertEqual(None, exc.__context__)
        self.assertEqual(False, exc.__suppress_context__)
        self.assertEqual(expected_stack, exc.stack)
        self.assertEqual(exc_info[0], exc.exc_type)
        self.assertEqual(str(exc_info[1]), str(exc)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:16,代碼來源:test_traceback.py

示例10: walk_tb

# 需要導入模塊: import traceback [as 別名]
# 或者: from traceback import walk_tb [as 別名]
def walk_tb(tb):
        while tb is not None:
            yield tb.tb_frame, tb.tb_lineno
            tb = tb.tb_next 
開發者ID:neargle,項目名稱:ver-observer,代碼行數:6,代碼來源:traceback2.py


注:本文中的traceback.walk_tb方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。