Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def call(self, e, *a, **kw):
defer = Deferred()
if not e in self.events:
return defer
EventDetails = {'e' : e, 'a' : a, 'kw' : kw}
return maybeDeferred(self.callback, self.events[e], EventDetails)
def resume (self):
if self.state is not State.PAUSED:
raise NotPaused
self.state = State.RUNNING
d = defer.maybeDeferred(self._resume)
try:
onResume, self._onResume = self._onResume, None
onResume()
except (AttributeError, TypeError):
pass
return d
if self.running:
service.Service.stopService(self)
self._on_event('stopping')
# if we're currently trying to reconnect, stop trying
if self._currently_reconnecting:
self._currently_reconnecting.cancel()
# if we're currently trying to connect, stop trying
if self._currently_connecting:
self._currently_connecting.cancel()
# if we have a client, try to close it, as it might be functional
if self._current_client:
defer.maybeDeferred(self._current_client.close).addErrback(lambda _: None)
self._current_client = None
self.on_disconnected(failure.Failure(DisconnectException('stopping service')))
action = start_action(
action_type=u"flocker:provision:libcloud:create_nodes",
instance_count=len(names),
distribution=distribution,
size=size,
metadata=metadata,
)
with action.context():
results = []
for name in names:
Message.log(
message_type=u"flocker:provision:libcloud:creating_node",
node_name=name,
)
d = maybeDeferred(
self._driver.create_node,
name=name,
image=get_image(self._driver, image_name),
size=get_size(self._driver, size),
ex_keyname=self._keyname,
ex_metadata=metadata,
**create_node_arguments
)
d = DeferredContext(d)
d.addCallbacks(
lambda node: self._wait_until_running(reactor, node),
errback=handle_create_error,
errbackArgs=(name,),
)
d.addCallback(make_node)
results.append(d.result)
@param i: The number of the message to operate on. This is a base-ten
string representation starting at 1.
@return: A Deferred which fires with a two-tuple of an integer and a
file-like object.
"""
try:
msg = int(i) - 1
if msg < 0:
raise ValueError()
except ValueError:
self.failResponse("Bad message number argument")
return defer.succeed(None)
sizeDeferred = defer.maybeDeferred(self.mbox.listMessages, msg)
def cbMessageSize(size):
if not size:
return defer.fail(_POP3MessageDeleted())
fileDeferred = defer.maybeDeferred(self.mbox.getMessage, msg)
fileDeferred.addCallback(lambda fObj: (size, fObj))
return fileDeferred
def ebMessageSomething(err):
errcls = err.check(_POP3MessageDeleted, ValueError, IndexError)
if errcls is _POP3MessageDeleted:
self.failResponse("message deleted")
elif errcls in (ValueError, IndexError):
if errcls is IndexError:
# XXX TODO See above comment regarding IndexError.
warnings.warn(
"twisted.mail.pop3.IMailbox.listMessages may not "
def connectionMade(self):
defer.maybeDeferred(self.stdinCallback, self.transport).addCallback(
self._finishedWriting).addErrback(self.resultDeferred.errback)
def stopService(self):
L = []
if self.port is not None:
L.append(defer.maybeDeferred(self.port.stopListening))
self.port = None
return defer.DeferredList(L)
def show_service(self, arguments, request_path, user):
d = defer.maybeDeferred(self.azbroker.check, None, user,
"show", request_path)
d = d.addCallback(self.dbbroker.show_service, session=True,
user=user, **arguments)
return d
def reconfigServiceWithBuildbotConfig(self, new_config):
# this is easy - kick out all of the old managers, and add the
# new ones.
# pylint: disable=cell-var-from-loop
for mgr in list(self):
yield defer.maybeDeferred(mgr.disownServiceParent)
for mgr in new_config.user_managers:
yield mgr.setServiceParent(self)
# reconfig any newly-added change sources, as well as existing
yield super().reconfigServiceWithBuildbotConfig(new_config)
def show_location_type(self, arguments, request_path, user):
d = defer.maybeDeferred(self.azbroker.check, None, user,
"show", request_path)
d = d.addCallback(self.dbbroker.show_location_type, session=True,
user=user, **arguments)
return d