本文整理汇总了Python中sys.exc_traceback方法的典型用法代码示例。如果您正苦于以下问题:Python sys.exc_traceback方法的具体用法?Python sys.exc_traceback怎么用?Python sys.exc_traceback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys
的用法示例。
在下文中一共展示了sys.exc_traceback方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: verifyStderr
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_traceback [as 别名]
def verifyStderr(self, method, successRe) :
"""
Call method() while capturing sys.stderr output internally and
call self.fail() if successRe.search() does not match the stderr
output. This is used to test for uncatchable exceptions.
"""
stdErr = sys.stderr
sys.stderr = StringIO()
try:
method()
finally:
temp = sys.stderr
sys.stderr = stdErr
errorOut = temp.getvalue()
if not successRe.search(errorOut) :
self.fail("unexpected stderr output:\n"+errorOut)
if sys.version_info < (3, 0) : # XXX: How to do this in Py3k ???
sys.exc_traceback = sys.last_traceback = None
示例2: test_str2
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_traceback [as 别名]
def test_str2(self):
# verify we can assign to sys.exc_*
sys.exc_traceback = None
sys.exc_value = None
sys.exc_type = None
self.assertEqual(str(Exception()), '')
@skipUnlessIronPython()
def test_array(self):
import System
try:
a = System.Array()
except Exception, e:
self.assertEqual(e.__class__, TypeError)
else:
示例3: traceback_get_exception
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_traceback [as 别名]
def traceback_get_exception(num = -1):
# build error message
exception_string = ''.join(traceback.format_exception_only(sys.exc_type, hasattr(sys, 'exc_value') and sys.exc_value or 'Unknown'))
# extract error location from traceback
if hasattr(sys, 'exc_traceback'):
(filename, line_number, function_name, text) = traceback.extract_tb(sys.exc_traceback)[num]
else:
(filename, line_number, function_name, text) = ('-', '-', '-', '-')
error = {
'message': exception_string,
'location': {
'filename': filename,
'line_number': line_number,
'function_name': function_name,
'text': text,
}
}
return error
示例4: run_campaign
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_traceback [as 别名]
def run_campaign(test_campaign, get_interactive_session, verb=2):
passed=failed=0
if test_campaign.preexec:
test_campaign.preexec_output = get_interactive_session(test_campaign.preexec.strip())[0]
for testset in test_campaign:
for t in testset:
t.output,res = get_interactive_session(t.test.strip())
the_res = False
try:
if res is None or res:
the_res= True
except Exception,msg:
t.output+="UTscapy: Error during result interpretation:\n"
t.output+="".join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback,))
if the_res:
t.res = True
res = "passed"
passed += 1
else:
t.res = False
res = "failed"
failed += 1
t.result = res
if verb > 1:
print >>sys.stderr,"%(result)6s %(crc)s %(name)s" % t
示例5: __init__
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_traceback [as 别名]
def __init__(self, path = None):
self.version = 1
self.fragments = []
self.path = path
if path is not None and os.path.exists(path):
currentresref = Res.CurResFile()
resref = Res.FSpOpenResFile(path, 1)
Res.UseResFile(resref)
try:
try:
data = Res.Get1Resource('cfrg', 0).data
except Res.Error:
raise Res.Error, "no 'cfrg' resource found", sys.exc_traceback
finally:
Res.CloseResFile(resref)
Res.UseResFile(currentresref)
self.parse(data)
if self.version != 1:
raise error, "unknown 'cfrg' resource format"
示例6: _get_assigned_letters
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_traceback [as 别名]
def _get_assigned_letters(self, cr, uid, ids, prop, unknow_none, context=None):
if not len(ids):
return {}
model_name = super(hr_employee, self)._name
res = []
try:
for id in ids:
letter_ids = []
ref_ids = self.pool['letter.ref'].search(cr, uid, [('int_ref', '=', model_name + ',' + str(id))],
context=context)
if ref_ids:
for ref in self.pool['letter.ref'].read(cr, uid, ref_ids, context=context):
letter_ids.append(ref['letter_id'][0])
res.append((id, letter_ids))
except Exception, e:
_logger.error(repr(traceback.extract_tb(sys.exc_traceback)))
示例7: ExecutePythonString
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_traceback [as 别名]
def ExecutePythonString(self, text):
try:
try:
return eval(text, globals(), self.GetLocals())
except SyntaxError:
tb = sys.exc_traceback
if tb.tb_next is None:
exec text in self.GetLocals()
else:
raise
except NameError as e:
tb = sys.exc_traceback
if tb.tb_next and tb.tb_next.tb_next is None:
log("Error: {0}\n", e.args[0])
else:
raise
示例8: test_actors
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_traceback [as 别名]
def test_actors(self):
test_pass = []
test_fail = {}
no_test = []
for actor in self.actors:
aut = self.actors[actor]
if aut == "no_test":
no_test.append(actor)
continue
try:
self.test_actor(actor, aut)
test_pass.append(actor)
except AssertionError as e:
test_fail[actor] = e.message
except Exception as e:
self.illegal_actors[actor] = str(e) + '\n' + ''.join(
traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
return {'pass': test_pass, 'fail': test_fail, 'skipped': no_test,
'errors': self.illegal_actors, 'components': self.components}
示例9: print_exc
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_traceback [as 别名]
def print_exc(limit=None, file=None):
"""Shorthand for 'print_exception(sys.exc_type, sys.exc_value, sys.exc_traceback, limit, file)'.
(In fact, it uses sys.exc_info() to retrieve the same information
in a thread-safe way.)"""
if file is None:
file = sys.stderr
try:
etype, value, tb = sys.exc_info()
print_exception(etype, value, tb, limit, file)
finally:
etype = value = tb = None
示例10: _query
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_traceback [as 别名]
def _query(self, path, before=None, after=None):
url = '%s/lookup/%s' % (self.server, path)
params = {}
if self.limit:
params['limit'] = self.limit
if before and after:
params['time_first_after'] = after
params['time_last_before'] = before
else:
if before:
params['time_first_before'] = before
if after:
params['time_last_after'] = after
if params:
url += '?{0}'.format(urllib.urlencode(params))
req = urllib2.Request(url)
req.add_header('Accept', 'application/json')
req.add_header('X-Api-Key', self.apikey)
try:
http = urllib2.urlopen(req)
while True:
line = http.readline()
if not line:
break
yield json.loads(line)
except (urllib2.HTTPError, urllib2.URLError), e:
raise self.not_good, str(e), sys.exc_traceback
###method used for general term searches##
示例11: _report_exception
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_traceback [as 别名]
def _report_exception(self):
"""Internal function."""
import sys
exc, val, tb = sys.exc_type, sys.exc_value, sys.exc_traceback
root = self._root()
root.report_callback_exception(exc, val, tb)