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


Python types.TracebackType方法代码示例

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


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

示例1: test_scope_error_report

# 需要导入模块: import types [as 别名]
# 或者: from types import TracebackType [as 别名]
def test_scope_error_report():
    tracer = Tracer()
    scope = tracer.start_active_span('foo')
    error_message = 'unexpected_situation'

    with mock.patch.object(scope.span, 'log_kv') as log_kv:
        with mock.patch.object(scope.span, 'set_tag') as set_tag:
            try:
                with scope:
                    raise ValueError(error_message)
            except ValueError:
                pass

            assert set_tag.call_count == 1
            assert set_tag.call_args[0] == (tags.ERROR, True)

            assert log_kv.call_count == 1
            log_kv_args = log_kv.call_args[0][0]
            assert log_kv_args.get(logs.EVENT, None) is tags.ERROR
            assert log_kv_args.get(logs.MESSAGE, None) is error_message
            assert log_kv_args.get(logs.ERROR_KIND, None) is ValueError
            assert isinstance(log_kv_args.get(logs.ERROR_OBJECT, None),
                              ValueError)
            assert isinstance(log_kv_args.get(logs.STACK, None),
                              types.TracebackType) 
开发者ID:opentracing,项目名称:opentracing-python,代码行数:27,代码来源:test_scope.py

示例2: test_span_error_report

# 需要导入模块: import types [as 别名]
# 或者: from types import TracebackType [as 别名]
def test_span_error_report():
    tracer = Tracer()
    span = tracer.start_span('foo')
    error_message = 'unexpected_situation'

    with mock.patch.object(span, 'log_kv') as log_kv:
        with mock.patch.object(span, 'set_tag') as set_tag:
            try:
                with span:
                    raise ValueError(error_message)
            except ValueError:
                pass

            assert set_tag.call_count == 1
            assert set_tag.call_args[0] == (tags.ERROR, True)

            assert log_kv.call_count == 1
            log_kv_args = log_kv.call_args[0][0]
            assert log_kv_args.get(logs.EVENT, None) is tags.ERROR
            assert log_kv_args.get(logs.MESSAGE, None) is error_message
            assert log_kv_args.get(logs.ERROR_KIND, None) is ValueError
            assert isinstance(log_kv_args.get(logs.ERROR_OBJECT, None),
                              ValueError)
            assert isinstance(log_kv_args.get(logs.STACK, None),
                              types.TracebackType) 
开发者ID:opentracing,项目名称:opentracing-python,代码行数:27,代码来源:test_noop_span.py

示例3: __exit__

# 需要导入模块: import types [as 别名]
# 或者: from types import TracebackType [as 别名]
def __exit__(
        self,
        exc_type: Optional[Type],
        exc_value: Optional[Exception],
        traceback: Optional[TracebackType],
    ) -> None:
        """
        Frees the resource related to the parsing of the query made by the
        libgraphqlparser library.
        :param exc_type: class of the exception potentially raised
        :param exc_value: instance of the exception potentially raised
        :param traceback: traceback of the exception potentially raised
        :type exc_type: Optional[Type]
        :type exc_value: Optional[Exception]
        :type traceback: Optional[TracebackType]
        """
        self._destroy_cb(self._c_parsed) 
开发者ID:tartiflette,项目名称:tartiflette,代码行数:19,代码来源:parser.py

示例4: _make_excepthook

# 需要导入模块: import types [as 别名]
# 或者: from types import TracebackType [as 别名]
def _make_excepthook(old_excepthook):
    # type: (Excepthook) -> Excepthook
    def sentry_sdk_excepthook(type_, value, traceback):
        # type: (Type[BaseException], BaseException, TracebackType) -> None
        hub = Hub.current
        integration = hub.get_integration(ExcepthookIntegration)

        if integration is not None and _should_send(integration.always_run):
            # If an integration is there, a client has to be there.
            client = hub.client  # type: Any

            with capture_internal_exceptions():
                event, hint = event_from_exception(
                    (type_, value, traceback),
                    client_options=client.options,
                    mechanism={"type": "excepthook", "handled": False},
                )
                hub.capture_event(event, hint=hint)

        return old_excepthook(type_, value, traceback)

    return sentry_sdk_excepthook 
开发者ID:getsentry,项目名称:sentry-python,代码行数:24,代码来源:excepthook.py

示例5: log_exception

# 需要导入模块: import types [as 别名]
# 或者: from types import TracebackType [as 别名]
def log_exception(self, exception_info: Tuple[type, BaseException, TracebackType]) -> None:
        """Log a exception to the :attr:`logger`.

        By default this is only invoked for unhandled exceptions.
        """
        if has_request_context():
            request_ = _request_ctx_stack.top.request
            self.logger.error(
                f"Exception on request {request_.method} {request_.path}", exc_info=exception_info
            )
        if has_websocket_context():
            websocket_ = _websocket_ctx_stack.top.websocket
            self.logger.error(f"Exception on websocket {websocket_.path}", exc_info=exception_info) 
开发者ID:pgjones,项目名称:quart,代码行数:15,代码来源:app.py

示例6: __aexit__

# 需要导入模块: import types [as 别名]
# 或者: from types import TracebackType [as 别名]
def __aexit__(self, exc_type: type, exc_value: BaseException, tb: TracebackType) -> None:
        self.preserve_context = False

        while True:
            top = _request_ctx_stack.top

            if top is not None and top.preserved:
                await top.pop(None)
            else:
                break 
开发者ID:pgjones,项目名称:quart,代码行数:12,代码来源:testing.py

示例7: __aexit__

# 需要导入模块: import types [as 别名]
# 或者: from types import TracebackType [as 别名]
def __aexit__(self, exc_type: type, exc_value: BaseException, tb: TracebackType) -> None:
        await self.auto_pop(exc_value) 
开发者ID:pgjones,项目名称:quart,代码行数:4,代码来源:ctx.py

示例8: __aexit__

# 需要导入模块: import types [as 别名]
# 或者: from types import TracebackType [as 别名]
def __aexit__(self, exc_type: type, exc_value: BaseException, tb: TracebackType) -> None:
        pass 
开发者ID:pgjones,项目名称:quart,代码行数:4,代码来源:response.py

示例9: install

# 需要导入模块: import types [as 别名]
# 或者: from types import TracebackType [as 别名]
def install(*exc_classes_or_instances):
    copyreg.pickle(TracebackType, pickle_traceback)

    if sys.version_info.major < 3:
        # Dummy decorator?
        if len(exc_classes_or_instances) == 1:
            exc = exc_classes_or_instances[0]
            if isinstance(exc, type) and issubclass(exc, BaseException):
                return exc
        return

    if not exc_classes_or_instances:
        for exception_cls in _get_subclasses(BaseException):
            copyreg.pickle(exception_cls, pickle_exception)
        return

    for exc in exc_classes_or_instances:
        if isinstance(exc, BaseException):
            while exc is not None:
                copyreg.pickle(type(exc), pickle_exception)
                exc = exc.__cause__
        elif isinstance(exc, type) and issubclass(exc, BaseException):
            copyreg.pickle(exc, pickle_exception)
            # Allow using @install as a decorator for Exception classes
            if len(exc_classes_or_instances) == 1:
                return exc
        else:
            raise TypeError(
                "Expected subclasses or instances of BaseException, got %s"
                % (type(exc))
            ) 
开发者ID:pywren,项目名称:pywren-ibm-cloud,代码行数:33,代码来源:pickling_support.py

示例10: istraceback

# 需要导入模块: import types [as 别名]
# 或者: from types import TracebackType [as 别名]
def istraceback(object):
    """Return true if the object is a traceback.

    Traceback objects provide these attributes:
        tb_frame        frame object at this level
        tb_lasti        index of last attempted instruction in bytecode
        tb_lineno       current line number in Python source code
        tb_next         next inner traceback object (called by this level)"""
    return isinstance(object, types.TracebackType) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:11,代码来源:inspect.py

示例11: __exit__

# 需要导入模块: import types [as 别名]
# 或者: from types import TracebackType [as 别名]
def __exit__(
        self,
        exc_type: Optional[BaseExceptionType],
        exc_value: Optional[BaseException],
        traceback: Optional[TracebackType],
    ) -> Any:
        if not self.partially_staged:
            return

        if exc_type is not None:
            # an error has occurred
            # restore working tree and index as it was before formatting
            self.restore_working_tree()
            _read_tree(self.index)
        else:
            # save formatting changes
            formatted_tree = _write_tree()

            self.restore_working_tree()

            # restore index
            # formatted_tree will be the same as index if no changes are applied
            _read_tree(formatted_tree)

            if formatted_tree != self.index:
                # create diff between index and formatted_tree
                patch = _get_tree_diff(self.index, formatted_tree)
                try:
                    # apply diff to working tree
                    _apply_diff(patch)
                except GitError as e:
                    print(
                        'Found conflicts between plugin and local changes. '
                        'Plugin changes will be ignored for conflicted hunks.',
                        e,
                    )

                    rootpath = get_project_root_path()
                    for path in rootpath.glob('*.rej'):
                        path.unlink() 
开发者ID:greenbone,项目名称:autohooks,代码行数:42,代码来源:git.py

示例12: is_internal_attribute

# 需要导入模块: import types [as 别名]
# 或者: from types import TracebackType [as 别名]
def is_internal_attribute(obj, attr):
    """Test if the attribute given is an internal python attribute.  For
    example this function returns `True` for the `func_code` attribute of
    python objects.  This is useful if the environment method
    :meth:`~SandboxedEnvironment.is_safe_attribute` is overridden.

    >>> from jinja2.sandbox import is_internal_attribute
    >>> is_internal_attribute(str, "mro")
    True
    >>> is_internal_attribute(str, "upper")
    False
    """
    if isinstance(obj, types.FunctionType):
        if attr in UNSAFE_FUNCTION_ATTRIBUTES:
            return True
    elif isinstance(obj, types.MethodType):
        if attr in UNSAFE_FUNCTION_ATTRIBUTES or \
           attr in UNSAFE_METHOD_ATTRIBUTES:
            return True
    elif isinstance(obj, type):
        if attr == 'mro':
            return True
    elif isinstance(obj, (types.CodeType, types.TracebackType, types.FrameType)):
        return True
    elif isinstance(obj, types.GeneratorType):
        if attr in UNSAFE_GENERATOR_ATTRIBUTES:
            return True
    elif hasattr(types, 'CoroutineType') and isinstance(obj, types.CoroutineType):
        if attr in UNSAFE_COROUTINE_ATTRIBUTES:
            return True
    elif hasattr(types, 'AsyncGeneratorType') and isinstance(obj, types.AsyncGeneratorType):
        if attr in UNSAFE_ASYNC_GENERATOR_ATTRIBUTES:
            return True
    return attr.startswith('__') 
开发者ID:remg427,项目名称:misp42splunk,代码行数:36,代码来源:sandbox.py

示例13: make_frame_proxy

# 需要导入模块: import types [as 别名]
# 或者: from types import TracebackType [as 别名]
def make_frame_proxy(frame):
    proxy = TracebackFrameProxy(frame)
    if tproxy is None:
        return proxy
    def operation_handler(operation, *args, **kwargs):
        if operation in ('__getattribute__', '__getattr__'):
            return getattr(proxy, args[0])
        elif operation == '__setattr__':
            proxy.__setattr__(*args, **kwargs)
        else:
            return getattr(proxy, operation)(*args, **kwargs)
    return tproxy(TracebackType, operation_handler) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:14,代码来源:debug.py

示例14: standard_exc_info

# 需要导入模块: import types [as 别名]
# 或者: from types import TracebackType [as 别名]
def standard_exc_info(self):
        """Standard python exc_info for re-raising"""
        tb = self.frames[0]
        # the frame will be an actual traceback (or transparent proxy) if
        # we are on pypy or a python implementation with support for tproxy
        if type(tb) is not TracebackType:
            tb = tb.tb
        return self.exc_type, self.exc_value, tb 
开发者ID:remg427,项目名称:misp42splunk,代码行数:10,代码来源:debug.py

示例15: __exit__

# 需要导入模块: import types [as 别名]
# 或者: from types import TracebackType [as 别名]
def __exit__(self,
                 _exc_type: 'typing.Optional[typing.Type[BaseException]]',
                 _exc_val: typing.Optional[BaseException],
                 _exc_tb: typing.Optional[types.TracebackType]) -> None:
        assert self._started is not None
        finished = datetime.datetime.now()
        delta = (finished - self._started).total_seconds()
        self._logger.debug("{} took {} seconds.".format(
            self._action.capitalize(), delta)) 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:11,代码来源:debug.py


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