本文整理匯總了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)
示例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)
示例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)
示例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
示例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)
示例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
示例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)
示例8: __aexit__
# 需要導入模塊: import types [as 別名]
# 或者: from types import TracebackType [as 別名]
def __aexit__(self, exc_type: type, exc_value: BaseException, tb: TracebackType) -> None:
pass
示例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))
)
示例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)
示例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()
示例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('__')
示例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)
示例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
示例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))