Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def method(*args, **kw):
calls.append((args, kw))
return "OHAI"
f0 = txaio.as_future(method, 1, 2, 3, key='word')
f1 = txaio.as_future(foo)
f2 = txaio.gather([f0, f1])
def done(arg):
results.append(arg)
def error(fail):
errors.append(fail)
# fail.printTraceback()
txaio.add_callbacks(f2, done, error)
for f in [f0, f1, f2]:
_await(f)
assert len(results) == 1
assert len(errors) == 0
assert results[0] == ['OHAI', 42] or results[0] == [42, 'OHAI']
assert len(calls) == 2
assert calls[0] == ((1, 2, 3), dict(key='word'))
assert calls[1] == (tuple(), dict())
self.onUserError(fail, "While firing on_progress")
if call_request.options and call_request.options.details:
prog_d = txaio.as_future(call_request.options.on_progress,
types.CallResult(*msg.args,
callee=msg.callee,
callee_authid=msg.callee_authid,
callee_authrole=msg.callee_authrole,
forward_for=msg.forward_for,
**msg.kwargs))
else:
prog_d = txaio.as_future(call_request.options.on_progress,
*args,
**kw)
txaio.add_callbacks(prog_d, None, _error)
else:
# process final call result
# drop original request
del self._call_reqs[msg.request]
# user callback that gets fired
on_reply = call_request.on_reply
# above might already have rejected, so we guard ..
if enc_err:
txaio.reject(on_reply, enc_err)
else:
if msg.kwargs or (call_request.options and call_request.options.details):
kwargs = msg.kwargs or {}
def onOpen(self, transport):
"""
Implements :func:`autobahn.wamp.interfaces.ITransportHandler.onOpen`
"""
self._transport = transport
d = self.fire('connect', self, transport)
txaio.add_callbacks(
d, None,
lambda fail: self._swallow_error(fail, "While notifying 'connect'")
)
txaio.add_callbacks(
d,
lambda _: txaio.as_future(self.onConnect),
lambda fail: self._swallow_error(fail, "While calling 'onConnect'")
)
authprovider=self._authprovider,
authextra=msg.authextra,
serializer=self._transport._serializer.SERIALIZER_ID,
resumed=msg.resumed,
resumable=msg.resumable,
resume_token=msg.resume_token,
)
# firing 'join' *before* running onJoin, so that
# the idiom where you "do stuff" in onJoin --
# possibly including self.leave() -- works
# properly. Besides, there's "ready" that fires
# after 'join' and onJoin have all completed...
d = self.fire('join', self, details)
# add a logging errback first, which will ignore any
# errors from fire()
txaio.add_callbacks(
d, None,
lambda e: self._swallow_error(e, "While notifying 'join'")
)
# this should run regardless
txaio.add_callbacks(
d,
lambda _: txaio.as_future(self.onJoin, details),
None
)
# ignore any errors from onJoin (XXX or, should that be fatal?)
txaio.add_callbacks(
d, None,
lambda e: self._swallow_error(e, "While firing onJoin")
)
# this instance is now "ready"...
txaio.add_callbacks(
def notify_connect_error(fail):
chain_f = txaio.create_future()
# hmm, if connectfailure took a _Transport instead of
# (or in addition to?) self it could .failed() the
# transport and we could do away with the is_fatal
# listener?
handler_f = self.fire('connectfailure', self, fail.value)
txaio.add_callbacks(
handler_f,
lambda _: txaio.reject(chain_f, fail),
lambda _: txaio.reject(chain_f, fail)
)
return chain_f
transport_candidate[0] = transport
break
delay = transport.next_delay()
self.log.debug(
'trying transport {transport_idx} using connect delay {transport_delay}',
transport_idx=transport.idx,
transport_delay=delay,
)
self._delay_f = txaio.sleep(delay)
txaio.add_callbacks(self._delay_f, attempt_connect, error)
# issue our first event, then start the reconnect loop
start_f = self.fire('start', loop, self)
txaio.add_callbacks(start_f, transport_check, error)
return self._done_f
transport = next(transport_gen)
if transport.can_reconnect():
transport_candidate[0] = transport
break
delay = transport.next_delay()
self.log.debug(
'trying transport {transport_idx} using connect delay {transport_delay}',
transport_idx=transport.idx,
transport_delay=delay,
)
self._delay_f = txaio.sleep(delay)
txaio.add_callbacks(self._delay_f, attempt_connect, error)
def onOpen(self, transport):
"""
Implements :func:`autobahn.wamp.interfaces.ITransportHandler.onOpen`
"""
self._transport = transport
d = self.fire('connect', self, transport)
txaio.add_callbacks(
d, None,
lambda fail: self._swallow_error(fail, "While notifying 'connect'")
)
txaio.add_callbacks(
d,
lambda _: txaio.as_future(self.onConnect),
lambda fail: self._swallow_error(fail, "While calling 'onConnect'")
)
reactor, transport, create_session, done,
)
def on_error(err):
"""
this may seem redundant after looking at _connect_transport, but
it will handle a case where something goes wrong in
_connect_transport itself -- as the only connect our
caller has is the 'done' future
"""
transport.connect_failures += 1
# something bad has happened, and maybe didn't get caught
# upstream yet
if not txaio.is_called(done):
txaio.reject(done, err)
txaio.add_callbacks(d, None, on_error)
return done
'Cancelling {count} outstanding requests',
count=len(outstanding),
)
for request in outstanding:
self.log.debug(
'cleaning up outstanding {request_type} request {request_id}, '
'firing errback on user handler {request_on_reply}',
request_on_reply=request.on_reply,
request_id=request.request_id,
request_type=request.__class__.__name__,
)
if not txaio.is_called(request.on_reply):
txaio.reject(request.on_reply, exc)
# wait for any async-ness in the error handlers for on_reply
txaio.add_callbacks(d, lambda _: request.on_reply, lambda _: request.on_reply)
return d