本文整理汇总了Python中twisted.python.failure.Failure类的典型用法代码示例。如果您正苦于以下问题:Python Failure类的具体用法?Python Failure怎么用?Python Failure使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Failure类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _start_stop_common
def _start_stop_common(self, label, action):
result = {}
try:
function = getattr(self.model, action)
d = defer.maybeDeferred(function, label)
wfd = defer.waitForDeferred(d)
yield wfd
result = wfd.getResult()
#take this time to update the instance
if isinstance(result, dict):
thisInst = self.model.getInstance(label)
thisInst.updateInfo(result)
except:
failure = Failure()
if failure.check(DroneCommandFailed):
result = failure.value.resultContext
else:
#log the error, allowing for debugging
self.debugReport()
#be nice and return something to the end user
template = "%s: %s" % (getException(failure), failure.getErrorMessage())
context = {'error':failure,'code':-2}
result = self.resultContext(template, None, **context)
#finally wrap the failure into a known type
result = Failure(DroneCommandFailed(result))
#AppInstances need a moment to be updated
d = defer.Deferred()
reactor.callLater(1.0, d.callback, None)
wfd = defer.waitForDeferred(d)
yield wfd
wfd.getResult()
yield result
开发者ID:cbrinley,项目名称:droned,代码行数:32,代码来源:appmgr.py
示例2: doToEachHomeNotAtVersion
def doToEachHomeNotAtVersion(store, homeSchema, version, doIt, logStr, filterOwnerUID=None, processExternal=False):
"""
Do something to each home whose version column indicates it is older
than the specified version. Do this in batches as there may be a lot of work to do. Also,
allow the GUID to be filtered to support a parallel mode of operation.
"""
txn = store.newTransaction("updateDataVersion")
where = homeSchema.DATAVERSION < version
if filterOwnerUID:
where = where.And(homeSchema.OWNER_UID.StartsWith(filterOwnerUID))
total = (yield Select(
[Count(homeSchema.RESOURCE_ID), ],
From=homeSchema,
Where=where,
).on(txn))[0][0]
yield txn.commit()
count = 0
while True:
logUpgradeStatus(logStr, count, total)
# Get the next home with an old version
txn = store.newTransaction("updateDataVersion")
try:
rows = yield Select(
[homeSchema.RESOURCE_ID, homeSchema.OWNER_UID, homeSchema.STATUS, ],
From=homeSchema,
Where=where,
OrderBy=homeSchema.OWNER_UID,
Limit=1,
).on(txn)
if len(rows) == 0:
yield txn.commit()
logUpgradeStatus("End {}".format(logStr), count, total)
returnValue(None)
# Apply to the home if not external
homeResourceID, _ignore_owner_uid, homeStatus = rows[0]
if homeStatus != _HOME_STATUS_EXTERNAL or processExternal:
yield doIt(txn, homeResourceID)
# Update the home to the current version
yield Update(
{homeSchema.DATAVERSION: version},
Where=homeSchema.RESOURCE_ID == homeResourceID,
).on(txn)
yield txn.commit()
except RuntimeError, e:
f = Failure()
logUpgradeError(
logStr,
"Failed to upgrade {} to {}: {}".format(homeSchema, version, e)
)
yield txn.abort()
f.raiseException()
count += 1
开发者ID:eventable,项目名称:CalendarServer,代码行数:60,代码来源:util.py
示例3: __call__
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
开发者ID:cbrinley,项目名称:droned,代码行数:31,代码来源:action.py
示例4: moveCalendarTimezoneProperties
def moveCalendarTimezoneProperties(sqlStore):
"""
Need to move all the CalDAV:calendar-timezone properties in the
RESOURCE_PROPERTY table to the new CALENDAR_BIND table columns, extracting
the new value from the XML property.
"""
cb = schema.CALENDAR_BIND
rp = schema.RESOURCE_PROPERTY
try:
calendars_for_id = {}
while True:
sqlTxn = sqlStore.newTransaction()
rows = (yield rowsForProperty(sqlTxn, caldavxml.CalendarTimeZone, with_uid=True, batch=BATCH_SIZE))
if len(rows) == 0:
yield sqlTxn.commit()
break
delete_ids = []
for calendar_rid, value, viewer in rows:
delete_ids.append(calendar_rid)
if calendar_rid not in calendars_for_id:
ids = yield Select(
[cb.CALENDAR_HOME_RESOURCE_ID, cb.BIND_MODE, ],
From=cb,
Where=cb.CALENDAR_RESOURCE_ID == calendar_rid,
).on(sqlTxn)
calendars_for_id[calendar_rid] = ids
if viewer:
calendarHome = (yield sqlTxn.calendarHomeWithUID(viewer))
else:
calendarHome = None
for row in calendars_for_id[calendar_rid]:
home_id, bind_mode = row
if bind_mode == _BIND_MODE_OWN:
calendarHome = (yield sqlTxn.calendarHomeWithResourceID(home_id))
break
if calendarHome is not None:
prop = WebDAVDocument.fromString(value).root_element
calendar = (yield calendarHome.childWithID(calendar_rid))
if calendar is not None:
yield calendar.setTimezone(prop.calendar())
# Always delete the rows so that batch processing works correctly
yield Delete(
From=rp,
Where=(rp.RESOURCE_ID.In(Parameter("ids", len(delete_ids)))).And
(rp.NAME == PropertyName.fromElement(caldavxml.CalendarTimeZone).toString()),
).on(sqlTxn, ids=delete_ids)
yield sqlTxn.commit()
yield cleanPropertyStore()
except RuntimeError:
f = Failure()
yield sqlTxn.abort()
f.raiseException()
开发者ID:anemitz,项目名称:calendarserver,代码行数:60,代码来源:calendar_upgrade_from_4_to_5.py
示例5: err
def err(message="", **context):
failure = Failure()
if message:
message += '\n'
message += failure.getTraceback()
log(message, **context)
return failure
开发者ID:OrbitzWorldwide,项目名称:droned,代码行数:7,代码来源:logging.py
示例6: decorator
def decorator(*args, **kwargs):
try: return func(*args, **kwargs)
except:
failure = Failure()
msg = getException(failure)
msg += ': ' + failure.getErrorMessage()
return NoResource(msg)
开发者ID:DroneD,项目名称:droned,代码行数:7,代码来源:remote_config.py
示例7: http_POST
def http_POST(self, request):
"""
The server-to-server POST method.
"""
# Need a transaction to work with
txn = transactionFromRequest(request, self._newStore)
# This is a server-to-server scheduling operation.
scheduler = IScheduleScheduler(txn, None, podding=self._podding)
originator = self.loadOriginatorFromRequestHeaders(request)
recipients = self.loadRecipientsFromRequestHeaders(request)
body = (yield allDataFromStream(request.stream))
# Do the POST processing treating this as a non-local schedule
try:
result = (yield scheduler.doSchedulingViaPOST(request.remoteAddr, request.headers, body, originator, recipients))
except Exception:
ex = Failure()
yield txn.abort()
ex.raiseException()
else:
yield txn.commit()
response = result.response()
if not self._podding:
response.headers.addRawHeader(ISCHEDULE_CAPABILITIES, str(config.Scheduling.iSchedule.SerialNumber))
returnValue(response)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:28,代码来源:resource.py
示例8: test_writeFailure
def test_writeFailure(self, logger):
"""
L{writeFailure} writes a L{Failure} to the log.
"""
if Failure is None:
raise SkipTest("Twisted unavailable")
try:
raise RuntimeError("because")
except:
failure = Failure()
expectedTraceback = failure.getBriefTraceback()
writeFailure(failure, logger)
message = logger.messages[0]
assertContainsFields(
self,
message,
{
"message_type": "eliot:traceback",
"exception": RuntimeError,
"reason": failure.value,
"traceback": expectedTraceback,
},
)
logger.flushTracebacks(RuntimeError)
开发者ID:ClusterHQ,项目名称:eliot,代码行数:25,代码来源:test_traceback.py
示例9: process_response
def process_response(self, response):
'''Passes response (Response or Failure object) received from
Downloader thought pipeline middlewares.
Return value is either Request, Response or Failure object.
'''
# we can be sure that response.request is set from the downloader
request = response.request
for name, enabled_setting, pr, pf in self._process_response:
# skip disabled mw through meta
if not request.meta.get(enabled_setting, True):
continue
method = pr if isinstance(response, Response) else pf
try:
response = method(response)
except:
response = Failure()
assert response is None or isinstance(response, (Request, Response, Failure)), \
'Middleware %s.process_request must return None, Response, Request or Failure, got %s' % \
(method.im_self.__class__.__name__, type(response))
if response is None:
method_name = 'process_response()' if method is pr else 'process_failure()'
failure = Failure(DropRequest(
'`%s` pipeline middleware dropped the request in `%s` method' %
(name, method_name)))
failure.request = request
return failure
if not isinstance(response, (Response, Failure)):
return response
# make sure, request attribute is always set
response.request = request
return response
开发者ID:Mimino666,项目名称:crawlmi,代码行数:34,代码来源:pipeline_manager.py
示例10: log
def log(self, category, eventDict):
"""
Log an event.
@param category: A short string identifying the type of log event.
The receiving log server may use this to collect all messages of the
same category in their own log files.
@type category: C{bytes}
@param eventDict: The event dictionary. As this is serialized to JSON
(see L{serialize}), for complex values, you may want to render them
to a string before adding them to the event dictionary.
@type eventDict: C{dict}
"""
self.augment(eventDict)
data = self.serialize(category, eventDict)
try:
self.socket.send(data)
except:
failure = Failure()
why = "Failed to send udplog message"
data = self.serializeFailure(category, eventDict, len(data),
failure, why)
try:
self.socket.send(data)
except Exception:
import sys
text = why + '\n' + failure.getBriefTraceback()
print >> sys.stderr, text
开发者ID:mochi,项目名称:udplog,代码行数:30,代码来源:udplog.py
示例11: newfunc
def newfunc(*args, **kwargs):
result = None
attempt = 0
# setup the caller object
iKwargs = {"debug": debug, "fd": fd, "verbose": verbose, "defaults": defaults, "trap": trap}
caller = _InspectorGadget(func, **iKwargs)
while attempt <= maximum:
try: # initial caller setup
result = caller(*args, **kwargs)
if isinstance(result, defer.Deferred):
return _deferred(result, caller)
break # reset data
except SystemExit:
result = Failure()
break
except KeyboardInterrupt:
result = Failure()
break
except:
attempt += 1
if attempt > maximum:
result = Failure()
break
time.sleep(delay)
caller.write(">>> Retry attempt %d" % attempt)
if isinstance(result, Failure):
result.raiseException()
return result
开发者ID:cbrinley,项目名称:droned,代码行数:28,代码来源:decorators.py
示例12: migrateOneHome
def migrateOneHome(self, fileTxn, homeType, fileHome):
"""
Migrate an individual calendar or addressbook home.
"""
migrateFunc, destFunc = homeTypeLookup.get(homeType)
uid = normalizeUUIDOrNot(fileHome.uid())
self.log.warn("Starting migration transaction %s UID %r" %
(homeType, uid))
sqlTxn = self.sqlStore.newTransaction()
homeGetter = destFunc(sqlTxn)
sqlHome = yield homeGetter(uid, create=False)
if sqlHome is not None and not self.merge:
self.log.warn(
"%s home %r already existed not migrating" % (
homeType, uid))
yield sqlTxn.abort()
returnValue(None)
try:
if sqlHome is None:
sqlHome = yield homeGetter(uid, create=True)
yield migrateFunc(fileHome, sqlHome, merge=self.merge)
except:
f = Failure()
yield sqlTxn.abort()
f.raiseException()
else:
yield sqlTxn.commit()
# Remove file home after migration. FIXME: instead, this should be a
# public remove...HomeWithUID() API for de-provisioning. (If we had
# this, this would simply be a store-to-store migrator rather than a
# filesystem-to-database upgrade.)
fileHome._path.remove()
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:32,代码来源:migrate.py
示例13: _do_get_connection
def _do_get_connection(account, conductor, ready, retries_left, backoff):
this_ready = defer.Deferred()
factory = ImapClientFactory(account, conductor, this_ready)
factory.connect()
try:
conn = yield this_ready
# yay - report we are good and tell the real callback we have it.
account.reportStatus(brat.EVERYTHING, brat.GOOD)
ready.callback(conn)
except Exception, exc:
fail = Failure()
logger.debug("first chance connection error handling: %s\n%s", fail.getErrorMessage(), fail.getBriefTraceback())
retries_left -= 1
if retries_left <= 0:
ready.errback(fail)
else:
status = failure_to_status(fail)
account.reportStatus(**status)
acct_id = account.details.get("id", "")
logger.warning(
"Failed to connect to account %r, will retry after %s secs: %s",
acct_id,
backoff,
fail.getErrorMessage(),
)
next_backoff = min(backoff * 2, MAX_BACKOFF) # magic number
conductor.reactor.callLater(
backoff, _do_get_connection, account, conductor, ready, retries_left, next_backoff
)
开发者ID:anuarcs,项目名称:raindrop,代码行数:29,代码来源:imap.py
示例14: dispatch
def dispatch(self, *a, **k):
for handler in self._listeners:
try:
handler(*a, **k)
except Exception, e:
f = Failure(e)
f.printTraceback()
log.err(e)
开发者ID:csv,项目名称:beatlounge,代码行数:8,代码来源:base.py
示例15: handle
def handle(self, message, address):
try:
(v,) = message.arguments
self.dispatch(self._transform(float(v)))
except Exception, e:
f = Failure(e)
f.printTraceback()
log.msg('[FloatDispatcher.handle] error', e)
开发者ID:csv,项目名称:beatlounge,代码行数:8,代码来源:base.py
示例16: test_should_return_None_when_exception_raised
def test_should_return_None_when_exception_raised(self, _):
failure = Failure(RuntimeError())
failure.lb_ip = '192.168.0.1'
responses = [(True, {'name': 'devytc97', 'state': 'up', 'session': 'monitor-enabled'}),
(False, failure)]
self.assertEquals(None, check_status_responses(responses))
开发者ID:andante-project,项目名称:yadtshell-plugins,代码行数:8,代码来源:f5_rest_tests.py
示例17: test_process_done
def test_process_done(self):
error = Failure(exc_value=Exception())
error.type = ProcessDone
error.value = Mock(exitCode=1, message="foobar")
jobtype = JobType(fake_assignment())
self.assertEqual(
jobtype.format_error(error),
"Process has finished with no apparent errors."
)
开发者ID:pyfarm,项目名称:pyfarm-agent,代码行数:10,代码来源:test_core_jobtype.py
示例18: parseError
def parseError(self, err, query, instMap):
err = Failure(err)
err.value = 'Received %s from query: %s'%(err.value, query)
log.error(err.getErrorMessage())
results = {}
for instances in instMap.values():
for tables in instances.values():
for table, props in tables:
results[table] = [err,]
return results
开发者ID:alecsandrb,项目名称:Community-Zenpacks,代码行数:10,代码来源:WMIClient.py
示例19: oops
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()
开发者ID:D3f0,项目名称:txscada,代码行数:11,代码来源:jobs.py
示例20: __transcodingError
def __transcodingError(self, failure=None, task=None):
self._fireStatusChanged(TranscoderStatusEnum.error)
if not failure:
failure = Failure()
self.onJobError(failure.getErrorMessage())
log.notifyFailure(self, failure,
"Transocding error%s",
(task and " during %s" % task) or "",
cleanTraceback=True)
self.setMood(moods.sad)
return failure
开发者ID:osiloke,项目名称:Flumotion-Transcoder,代码行数:11,代码来源:filetranscoder.py
注:本文中的twisted.python.failure.Failure类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论