本文整理汇总了Python中sentry.interfaces.stacktrace.Stacktrace.to_python方法的典型用法代码示例。如果您正苦于以下问题:Python Stacktrace.to_python方法的具体用法?Python Stacktrace.to_python怎么用?Python Stacktrace.to_python使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sentry.interfaces.stacktrace.Stacktrace
的用法示例。
在下文中一共展示了Stacktrace.to_python方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_python
# 需要导入模块: from sentry.interfaces.stacktrace import Stacktrace [as 别名]
# 或者: from sentry.interfaces.stacktrace.Stacktrace import to_python [as 别名]
def to_python(cls, data, slim_frames=True, rust_renormalized=RUST_RENORMALIZED_DEFAULT):
if not rust_renormalized:
is_valid, errors = validate_and_default_interface(data, cls.path)
if not is_valid:
raise InterfaceValidationError("Invalid exception")
if not (data.get('type') or data.get('value')):
raise InterfaceValidationError("No 'type' or 'value' present")
if get_path(data, 'stacktrace', 'frames', filter=True):
stacktrace = Stacktrace.to_python(
data['stacktrace'],
slim_frames=slim_frames,
rust_renormalized=rust_renormalized
)
else:
stacktrace = None
if get_path(data, 'raw_stacktrace', 'frames', filter=True):
raw_stacktrace = Stacktrace.to_python(
data['raw_stacktrace'], slim_frames=slim_frames, raw=True,
rust_renormalized=rust_renormalized
)
else:
raw_stacktrace = None
type = data.get('type')
value = data.get('value')
if not rust_renormalized:
if isinstance(value, six.string_types):
if type is None:
m = _type_value_re.match(value)
if m:
type = m.group(1)
value = m.group(2).strip()
elif value is not None:
value = json.dumps(value)
value = trim(value, 4096)
if data.get('mechanism'):
mechanism = Mechanism.to_python(data['mechanism'],
rust_renormalized=rust_renormalized)
else:
mechanism = None
kwargs = {
'type': trim(type, 128),
'value': value,
'module': trim(data.get('module'), 128),
'mechanism': mechanism,
'stacktrace': stacktrace,
'thread_id': trim(data.get('thread_id'), 40),
'raw_stacktrace': raw_stacktrace,
}
return cls(**kwargs)
示例2: to_python
# 需要导入模块: from sentry.interfaces.stacktrace import Stacktrace [as 别名]
# 或者: from sentry.interfaces.stacktrace.Stacktrace import to_python [as 别名]
def to_python(cls, data, has_system_frames=None, slim_frames=True):
if not (data.get('type') or data.get('value')):
raise InterfaceValidationError("No 'type' or 'value' present")
if data.get('stacktrace') and data['stacktrace'].get('frames'):
stacktrace = Stacktrace.to_python(
data['stacktrace'],
has_system_frames=has_system_frames,
slim_frames=slim_frames,
)
else:
stacktrace = None
if data.get('raw_stacktrace') and data['raw_stacktrace'].get('frames'):
raw_stacktrace = Stacktrace.to_python(
data['raw_stacktrace'],
has_system_frames=has_system_frames,
slim_frames=slim_frames,
raw=True
)
else:
raw_stacktrace = None
type = data.get('type')
value = data.get('value')
if not type and ':' in value.split(' ', 1)[0]:
type, value = value.split(':', 1)
# in case of TypeError: foo (no space)
value = value.strip()
if value is not None and not isinstance(value, six.string_types):
value = json.dumps(value)
value = trim(value, 4096)
mechanism = data.get('mechanism')
if mechanism is not None:
if not isinstance(mechanism, dict):
raise InterfaceValidationError('Bad value for mechanism')
mechanism = trim(data.get('mechanism'), 4096)
mechanism.setdefault('type', 'generic')
kwargs = {
'type': trim(type, 128),
'value': value,
'module': trim(data.get('module'), 128),
'mechanism': mechanism,
'stacktrace': stacktrace,
'thread_id': trim(data.get('thread_id'), 40),
'raw_stacktrace': raw_stacktrace,
}
return cls(**kwargs)
示例3: get_stacktrace
# 需要导入模块: from sentry.interfaces.stacktrace import Stacktrace [as 别名]
# 或者: from sentry.interfaces.stacktrace.Stacktrace import to_python [as 别名]
def get_stacktrace(self, data):
try:
stacktrace = Stacktrace.to_python(data['stacktrace'])
except KeyError:
stacktrace = None
return stacktrace
示例4: test_does_not_overwrite_filename
# 需要导入模块: from sentry.interfaces.stacktrace import Stacktrace [as 别名]
# 或者: from sentry.interfaces.stacktrace.Stacktrace import to_python [as 别名]
def test_does_not_overwrite_filename(self):
interface = Stacktrace.to_python(
dict(frames=[{"lineno": 1, "filename": "foo.js", "abs_path": "http://foo.com/foo.js"}])
)
frame = interface.frames[0]
assert frame.filename == "foo.js"
assert frame.abs_path == "http://foo.com/foo.js"
示例5: test_serialize_returns_frames
# 需要导入模块: from sentry.interfaces.stacktrace import Stacktrace [as 别名]
# 或者: from sentry.interfaces.stacktrace.Stacktrace import to_python [as 别名]
def test_serialize_returns_frames(self):
interface = Stacktrace.to_python(dict(frames=[{
'lineno': 1,
'filename': 'foo.py',
}]))
result = interface.to_json()
assert 'frames' in result
示例6: generate_culprit
# 需要导入模块: from sentry.interfaces.stacktrace import Stacktrace [as 别名]
# 或者: from sentry.interfaces.stacktrace.Stacktrace import to_python [as 别名]
def generate_culprit(data, platform=None):
culprit = ''
try:
stacktraces = [
e['stacktrace'] for e in data['sentry.interfaces.Exception']['values']
if e.get('stacktrace')
]
except KeyError:
stacktrace = data.get('sentry.interfaces.Stacktrace')
if stacktrace:
stacktraces = [stacktrace]
else:
stacktraces = None
if not stacktraces:
if 'sentry.interfaces.Http' in data:
culprit = data['sentry.interfaces.Http'].get('url', '')
else:
from sentry.interfaces.stacktrace import Stacktrace
culprit = Stacktrace.to_python(stacktraces[-1]).get_culprit_string(
platform=platform,
)
return truncatechars(culprit, MAX_CULPRIT_LENGTH)
示例7: test_get_stacktrace_with_filename_and_function
# 需要导入模块: from sentry.interfaces.stacktrace import Stacktrace [as 别名]
# 或者: from sentry.interfaces.stacktrace.Stacktrace import to_python [as 别名]
def test_get_stacktrace_with_filename_and_function(self):
event = mock.Mock(spec=Event())
interface = Stacktrace.to_python(
dict(frames=[{"filename": "foo", "function": "biz"}, {"filename": "bar", "function": "baz"}])
)
result = interface.get_stacktrace(event)
self.assertEquals(result, 'Stacktrace (most recent call last):\n\n File "foo", in biz\n File "bar", in baz')
示例8: test_legacy_interface
# 需要导入模块: from sentry.interfaces.stacktrace import Stacktrace [as 别名]
# 或者: from sentry.interfaces.stacktrace.Stacktrace import to_python [as 别名]
def test_legacy_interface(self):
# Simple test to ensure legacy data works correctly with the ``Frame``
# objects
event = self.event
interface = Stacktrace.to_python(event.data['sentry.interfaces.Stacktrace'])
assert len(interface.frames) == 1
assert interface == event.interfaces['sentry.interfaces.Stacktrace']
示例9: test_over_max
# 需要导入模块: from sentry.interfaces.stacktrace import Stacktrace [as 别名]
# 或者: from sentry.interfaces.stacktrace.Stacktrace import to_python [as 别名]
def test_over_max(self):
values = []
for n in xrange(5):
values.append({
'filename': 'frame %d' % n,
'vars': {'foo': 'bar'},
'context_line': 'b',
'pre_context': ['a'],
'post_context': ['c'],
})
interface = Stacktrace.to_python({'frames': values})
slim_frame_data(interface, 4)
assert len(interface.frames) == 5
for value, num in zip(interface.frames[:2], xrange(2)):
assert value.filename == 'frame %d' % num
assert value.vars is not None
assert value.pre_context is not None
assert value.post_context is not None
for value, num in zip(interface.frames[3:], xrange(3, 5)):
assert value.filename == 'frame %d' % num
assert value.vars is not None
assert value.pre_context is not None
assert value.post_context is not None
value = interface.frames[2]
assert value.filename == 'frame 2'
assert not value.vars
assert not value.pre_context
assert not value.post_context
示例10: test_get_stacktrace_with_filename_function_lineno_and_context
# 需要导入模块: from sentry.interfaces.stacktrace import Stacktrace [as 别名]
# 或者: from sentry.interfaces.stacktrace.Stacktrace import to_python [as 别名]
def test_get_stacktrace_with_filename_function_lineno_and_context(self):
event = mock.Mock(spec=Event())
interface = Stacktrace.to_python(
dict(
frames=[
{
'filename': 'foo',
'function': 'biz',
'lineno': 3,
'context_line': ' def foo(r):'
},
{
'filename': 'bar',
'function': 'baz',
'lineno': 5,
'context_line': ' return None'
},
]
)
)
result = interface.get_stacktrace(event)
self.assertEquals(
result,
'Stacktrace (most recent call last):\n\n File "foo", line 3, in biz\n def foo(r):\n File "bar", line 5, in baz\n return None'
)
示例11: test_get_stacktrace_with_module
# 需要导入模块: from sentry.interfaces.stacktrace import Stacktrace [as 别名]
# 或者: from sentry.interfaces.stacktrace.Stacktrace import to_python [as 别名]
def test_get_stacktrace_with_module(self):
event = mock.Mock(spec=Event())
interface = Stacktrace.to_python(dict(frames=[{'module': 'foo'}, {'module': 'bar'}]))
result = interface.get_stacktrace(event)
self.assertEquals(
result, 'Stacktrace (most recent call last):\n\n Module "foo"\n Module "bar"'
)
示例12: to_python
# 需要导入模块: from sentry.interfaces.stacktrace import Stacktrace [as 别名]
# 或者: from sentry.interfaces.stacktrace.Stacktrace import to_python [as 别名]
def to_python(cls, data, has_system_frames=None):
if not (data.get('type') or data.get('value')):
raise InterfaceValidationError("No 'type' or 'value' present")
if data.get('stacktrace') and data['stacktrace'].get('frames'):
stacktrace = Stacktrace.to_python(
data['stacktrace'],
has_system_frames=has_system_frames,
)
else:
stacktrace = None
type = data.get('type')
value = data.get('value')
if not type and ':' in value.split(' ', 1)[0]:
type, value = value.split(':', 1)
# in case of TypeError: foo (no space)
value = value.strip()
if value is not None and not isinstance(value, basestring):
value = json.dumps(value)
value = trim(value, 4096)
kwargs = {
'type': trim(type, 128),
'value': value,
'module': trim(data.get('module'), 128),
'stacktrace': stacktrace,
}
return cls(**kwargs)
示例13: to_python
# 需要导入模块: from sentry.interfaces.stacktrace import Stacktrace [as 别名]
# 或者: from sentry.interfaces.stacktrace.Stacktrace import to_python [as 别名]
def to_python(cls, data, has_system_frames=None, slim_frames=True):
if not (data.get("type") or data.get("value")):
raise InterfaceValidationError("No 'type' or 'value' present")
if data.get("stacktrace") and data["stacktrace"].get("frames"):
stacktrace = Stacktrace.to_python(
data["stacktrace"], has_system_frames=has_system_frames, slim_frames=slim_frames
)
else:
stacktrace = None
if data.get("raw_stacktrace") and data["raw_stacktrace"].get("frames"):
raw_stacktrace = Stacktrace.to_python(
data["raw_stacktrace"], has_system_frames=has_system_frames, slim_frames=slim_frames
)
else:
raw_stacktrace = None
type = data.get("type")
value = data.get("value")
if not type and ":" in value.split(" ", 1)[0]:
type, value = value.split(":", 1)
# in case of TypeError: foo (no space)
value = value.strip()
if value is not None and not isinstance(value, six.string_types):
value = json.dumps(value)
value = trim(value, 4096)
mechanism = data.get("mechanism")
if mechanism is not None:
if not isinstance(mechanism, dict):
raise InterfaceValidationError("Bad value for mechanism")
mechanism = trim(data.get("mechanism"), 4096)
mechanism.setdefault("type", "generic")
kwargs = {
"type": trim(type, 128),
"value": value,
"module": trim(data.get("module"), 128),
"mechanism": mechanism,
"stacktrace": stacktrace,
"thread_id": trim(data.get("thread_id"), 40),
"raw_stacktrace": raw_stacktrace,
}
return cls(**kwargs)
示例14: test_coerces_url_filenames
# 需要导入模块: from sentry.interfaces.stacktrace import Stacktrace [as 别名]
# 或者: from sentry.interfaces.stacktrace.Stacktrace import to_python [as 别名]
def test_coerces_url_filenames(self):
interface = Stacktrace.to_python(dict(frames=[{
'lineno': 1,
'filename': 'http://foo.com/foo.js',
}]))
frame = interface.frames[0]
assert frame.filename == '/foo.js'
assert frame.abs_path == 'http://foo.com/foo.js'
示例15: get_stacktraces
# 需要导入模块: from sentry.interfaces.stacktrace import Stacktrace [as 别名]
# 或者: from sentry.interfaces.stacktrace.Stacktrace import to_python [as 别名]
def get_stacktraces(self, data):
exceptions = get_path(data, 'exception', 'values', filter=True, default=())
stacktraces = [e['stacktrace'] for e in exceptions if e.get('stacktrace')]
if 'stacktrace' in data:
stacktraces.append(data['stacktrace'])
return [(s, Stacktrace.to_python(s)) for s in stacktraces]