本文整理汇总了Python中twisted.python.failure.Failure.getTraceback方法的典型用法代码示例。如果您正苦于以下问题:Python Failure.getTraceback方法的具体用法?Python Failure.getTraceback怎么用?Python Failure.getTraceback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.failure.Failure
的用法示例。
在下文中一共展示了Failure.getTraceback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handleDeferreds
# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import getTraceback [as 别名]
def handleDeferreds(labels):
"""Remember last yield is the return value, don't use return"""
results = {}
descriptions = []
ret = {}
code = 0
for l in labels:
try:
d = defer.maybeDeferred(func, l, *args[1:], **kwargs)
wfd = defer.waitForDeferred(d)
yield wfd
ret = wfd.getResult()
except:
failure = Failure()
des = "%s: %s" % \
(getException(failure),failure.getErrorMessage())
if failure.check(DroneCommandFailed):
result[l] = failure.value.resultContext
if 'description' not in result[l]:
result[l]['description'] = des
result[l]['stacktrace'] = failure.getTraceback()
result[l]['error'] = True
if 'code' not in result[l]:
result[l]['code'] = 1
else:
ret = {
'description': des,
'code': 1,
'error': True,
'stacktrace': failure.getTraceback()
}
if not ret: #NoneType detection
ret = {'description' : str(ret), 'code' : 0}
if 'code' in ret:
code += abs(ret['code'])
results[l] = ret
try:
descriptions.append(results[l]['description'])
except:
self.debugReport()
results['code'] = code
try:
results['description'] = '\n'.join(descriptions)
except:
results['description'] = None
if len(labels) == 0:
Label = labels[0]
else:
Label = None
ret = self.resultContext('%(description)s',label=Label,**results)
yield ret
示例2: __call__
# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import getTraceback [as 别名]
def __call__(self, argstr):
args = argstr.split()
resultContext = None
if not args: #return command usage
methods = {}
for name,args,doc in self.exposedMethodInfo:
methods[name] = {'args' : args, 'doc' : doc}
resultContext = dict(description=self.__doc__, methods=methods)
yield resultContext
else:
method = args.pop(0)
try:
wfd = defer.waitForDeferred(
self.invoke(method,args)
)
yield wfd
resultContext = wfd.getResult()
except:
failure = Failure()
if failure.check(DroneCommandFailed):
resultContext = failure.value.resultContext
else:
#be nice and return something to the end user
template = "[%(application)s] "
template += "%s: %s" % (getException(failure), failure.getErrorMessage())
context = {'error': True, 'code': -2, 'stacktrace': failure.getTraceback()}
resultContext = self.resultContext(template, None,
**context
)
yield resultContext
示例3: err
# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import getTraceback [as 别名]
def err(message="", **context):
failure = Failure()
if message:
message += '\n'
message += failure.getTraceback()
log(message, **context)
return failure
示例4: oops
# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import getTraceback [as 别名]
def oops(self, *arg):
"""
Returns a C{False} status code for a remote call along with a string
traceback of the exception raised. You can supply your own exception or
L{Failure} instance. If you don't, the current exception will be used.
"""
if arg and isinstance(arg[0], Failure):
failureObject = arg[0]
else:
failureObject = Failure(*arg)
return False, failureObject.getTraceback()
示例5: test_message_why_iserror
# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import getTraceback [as 别名]
def test_message_why_iserror(self):
"""
When message, why and isError is given, then message takes precedence
and why and isError is ignored to construct message
"""
failure = Failure(ValueError())
self.wrapper({'message': ('mine', 'yours'), 'isError': True,
'why': 'reason', 'failure': failure})
self.assertEqual(
self._formatted_event(),
{'message': ('mineyours',), 'level': LogLevel.ERROR,
'traceback': failure.getTraceback(),
'exception_type': 'ValueError'})
示例6: __init__
# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import getTraceback [as 别名]
def __init__(self, *args, **kwargs):
self.data = kwargs.pop('data', None)
self.cause = kwargs.pop('cause', None)
default_code = self.default_error_code
default_name = self.default_error_name or self.__class__.__name__
self.error_code = kwargs.pop('code', default_code)
self.error_name = kwargs.pop('name', default_name)
if args and isinstance(args[0], unicode):
# Exception don't like passing them unicode strings
# as a message. Here we do our best to encode it
try:
encoded = args[0].encode('utf8')
except:
encoded = args[0].encode('ascii', 'replace')
args = (encoded, ) + args[1:]
Exception.__init__(self, *args, **kwargs)
self.cause_details = None
self.cause_traceback = None
try:
from twisted.python.failure import Failure
except ImportError:
Failure = None
if self.cause:
if isinstance(self.cause, Exception):
self.cause_details = get_exception_message(self.cause)
elif Failure and isinstance(self.cause, Failure):
self.cause_details = get_failure_message(self.cause)
else:
self.cause_details = "Unknown"
if Failure and isinstance(self.cause, Failure):
f = self.cause
self.cause = f.value
try:
self.cause_traceback = f.getTraceback()
except:
# Ignore failure.NoCurrentExceptionError
pass
elif Failure:
try:
f = Failure()
if f.value == self.cause:
self.cause_traceback = f.getTraceback()
except:
# Ignore failure.NoCurrentExceptionError
pass
示例7: invoke
# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import getTraceback [as 别名]
def invoke(self, name, args):
"""Invoke Exposed Methods
@param name (str) - name of method to invoke
@param args (tuple) - arguments to pass to invoked method
@return (defer.Deferred)
"""
if name not in self.exposedMethods:
return defer.fail(DroneCommandFailed(self.resultContext(
"[%(application)s] Unknown method '%(method)s'", method=name,
error='unknown method'))
)
try:
#our own form of maybeDeferred
d = self.exposedMethods[name](*args)
if isinstance(d, defer.Deferred):
action = Action(' '.join([str(i) for i in \
(self.action, name) + tuple(args)]), d)
return action.deferred
elif isinstance(d, DroneCommandFailed):
return defer.fail(d)
elif isinstance(d, dict):
return defer.succeed(d)
elif isinstance(d, type(None)):
#this just feels dirty
return defer.succeed(d)
elif isinstance(d, Failure):
d.raiseException() #sigh
#probably from a triggerred Event callback
elif type(d) == types.InstanceType:
return defer.succeed(None)
return defer.fail(FormatError("Result is not formatted correctly you " + \
"must return self.resultContext or DroneCommandFailed." + \
"\nResult: <%s>" % (str(d),)))
except:
failure = Failure()
if failure.check(DroneCommandFailed):
template = "[%(application)s] %(description)s"
context = failure.value.resultContext
if not 'description' in context:
context['description'] = failure.getErrorMessage()
else:
template = "[%(application)s] " + "%s: %s" % (getException(failure),
failure.getErrorMessage())
context = {'error': True, 'code':-2, 'stacktrace': failure.getTraceback()}
return defer.fail(DroneCommandFailed(self.resultContext(template,
None, **context))
)
示例8: resultContext
# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import getTraceback [as 别名]
def resultContext(self, template, instance=None, **context):
"""Creates a dict containg relevant contextual information about a
result. You can override this method and tailor it to your liking.
We typically use this to pass verbose structured data to a master
DroneD controller (not provided with DroneD core) so that it may
quickly make decisions based on the result of it's previous command
and control activities.
IF you set 'error' in the **context this will raise a server error
at the remote end. This can be good or bad depending on your outlook
on exceptions. Consider this your only warning.
return dict
"""
if 'application' not in context:
context['application'] = self.action
failure = context.pop('error', False)
if isinstance(failure, Failure):
if 'description' not in context:
context['description'] = '[%s] %s: %s' % \
(self.action, getException(failure), failure.getErrorMessage())
if 'code' not in context:
context['code'] = -2
context['error'] = True
context['stacktrace'] = failure.getTraceback()
self.log('Result context during exception\n%(stacktrace)s' % context)
return context #failed so bad we need to shortcut out
else:
context['error'] = bool(failure)
if instance: #this was made for AppManager's
if hasattr(instance, 'version'):
context['version'] = instance.version
if hasattr(instance, 'label'):
context['label'] = instance.label
if hasattr(instance, 'running'):
context['running'] = instance.running
try: #fail-safe in case someone is a bonehead
context['description'] = template % context
except:
failure = Failure()
context['description'] = '[%s] %s: %s' % \
(self.action, getException(failure), failure.getErrorMessage())
context['stacktrace'] = failure.getTraceback()
if 'code' not in context:
context['code'] = -2
#be nice to blaster api and the remote client
context.update({'code' : context.get('code',0) })
return context
示例9: restart
# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import getTraceback [as 别名]
def restart(self):
"""convenient restart method for an Application Instance"""
result = None
try:
if self.running:
d = self.stop()
wfd = defer.waitForDeferred(d)
yield wfd
wfd.getResult()
d = self.start()
wfd = defer.waitForDeferred(d)
yield wfd
result = wfd.getResult()
except:
result = Failure()
log('Unhandled exception\n' + result.getTraceback())
yield result
示例10: droneblast
# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import getTraceback [as 别名]
def droneblast(conversation, command):
server = conversation.context.get('server')
response = None
d = None
try:
if not isinstance(server, Server):
conversation.say('On what <b>server</b>?')
raise AssertionError('incomplete converation context')
options = {}
if 'timeout' in conversation.context:
options['timeout'] = conversation.context['timeout']
try:
conversation.say("Running droned command...")
d = server.manager.run(command, **options)
deferreds = conversation.context.get('deferreds', [])
deferreds.append(d)
conversation.context.update({'deferreds': deferreds})
wfd = defer.waitForDeferred(d)
yield wfd
result = wfd.getResult()
except:
failure = Failure()
if failure.check(DroneCommandFailed):
rc = failure.value.resultContext
conversation.say(rc.get('description') or str(rc), useHTML=False)
else:
conversation.say(failure.getTraceback(), useHTML=False)
else:
if isinstance(result, dict):
output = result.values()[0].get('description', str(result))
else:
output = str(result)
deferreds = conversation.context.get('deferreds', [])
try: deferreds.remove(d)
except: pass
conversation.context.update({'deferreds': deferreds})
conversation.say("Command completed\n%s" % output, useHTML=False)
except AssertionError: pass
except:
result = Failure()
yield result
示例11: _finishFinished
# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import getTraceback [as 别名]
def _finishFinished(self, results):
# internal function to indicate that this step is done; this is separated
# from finished() so that subclasses can override finished()
if self.progress:
self.progress.finish()
try:
hidden = self._maybeEvaluate(self.hideStepIf, results, self)
except Exception:
why = Failure()
self.addHTMLLog("err.html", formatFailure(why))
self.addCompleteLog("err.text", why.getTraceback())
results = EXCEPTION
hidden = False
self.step_status.stepFinished(results)
self.step_status.setHidden(hidden)
self.releaseLocks()
self.deferred.callback(results)
示例12: send_outbound
# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import getTraceback [as 别名]
def send_outbound(self, phone):
queue_key = self.r_key(self.redis_outbound_queue)
sent_messages = []
while self.r_server.llen(queue_key):
json_data = self.r_server.lpop(queue_key)
message = TransportUserMessage.from_json(json_data)
log.msg('Sending SMS to %s' % (message['to_addr'],))
# keep track of which Gammu messages were sent out for
# what Vumi message
gammu_messages = {}
try:
for gammu_message in self.construct_gammu_messages(message):
overrides = {
'Number': message['to_addr'],
# Send using the Phone's known SMSC
'SMSC': {
'Location': 1
},
# this will create submit message with request
# for delivery report
'Type': 'Status_Report',
}
gammu_message.update(overrides)
# keep the message reference for delivery reports
send_sms_response = yield deferToThread(phone.SendSMS,
gammu_message)
gammu_messages[send_sms_response] = gammu_message
# multiparts result in multiple acks
yield self.publish_ack(
user_message_id=message['message_id'],
sent_message_id=send_sms_response)
# collect for audit trail
sent_messages.append((message, gammu_messages))
except gammu.GSMError, e:
failure = Failure(e)
self.send_failure(message, failure.value,
failure.getTraceback())
示例13: get_exception_traceback
# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import getTraceback [as 别名]
def get_exception_traceback(exception=None, cleanup=False):
#FIXME: Only work if the exception was raised in the current context
f = Failure(exception)
if exception and (f.value != exception):
return "Not Traceback information available"
io = StringIO.StringIO()
tb = f.getTraceback()
if cleanup:
tb = clean_traceback(tb)
print >> io, tb
if isinstance(f.value, FeatError):
if f.value.causeTraceback:
print >> io, "\n\nCAUSED BY:\n\n"
tb = f.value.causeTraceback
if cleanup:
tb = clean_traceback(tb)
print >> io, tb
return io.getvalue()
示例14: __init__
# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import getTraceback [as 别名]
def __init__(self, *args, **kwargs):
self.data = kwargs.pop('data', None)
self.cause = kwargs.pop('cause', None)
default_code = self.default_error_code
default_name = self.default_error_name or self.__class__.__name__
self.error_code = kwargs.pop('code', default_code)
self.error_name = kwargs.pop('name', default_name)
Exception.__init__(self, *args, **kwargs)
self.cause_details = None
self.cause_traceback = None
if self.cause:
if isinstance(self.cause, Exception):
self.cause_details = get_exception_message(self.cause)
elif isinstance(self.cause, Failure):
self.causeDetails = get_failure_message(self.cause)
else:
self.causeDetails = "Unknown"
if isinstance(self.cause, Failure):
f = self.cause
self.cause = f.value
try:
self.cause_traceback = f.getTraceback()
except:
# Ignore failure.NoCurrentExceptionError
pass
else:
try:
f = Failure()
if f.value == self.cause:
self.cause_traceback = f.getTraceback()
except:
# Ignore failure.NoCurrentExceptionError
pass
示例15: msgBufResponse
# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import getTraceback [as 别名]
def msgBufResponse(self, result):
"""Format results, encode, and respond"""
response, contentType = result
try:
return {
'response' : urllib.quote(blaster.Serialize().execute(
contentType, drone.formatResults(response))),
'type' : contentType,
'code' : 200
}
except:
failure = Failure()
Msg = {
'code' : 1,
'description' : failure.getErrorMessage(),
'stacktrace': failure.getTraceback(),
'error' : True
}
return {
'response' : urllib.quote(blaster.Serialize().execute(
contentType, Msg)),
'type' : 'text/plain',
'code' : 500
}