Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
error = u"wamp.error.runtime_error"
encoded_payload = None
if self._payload_codec:
encoded_payload = self._payload_codec.encode(False, error, args, kwargs)
if encoded_payload:
msg = message.Error(request_type,
request,
error,
payload=encoded_payload.payload,
enc_algo=encoded_payload.enc_algo,
enc_key=encoded_payload.enc_key,
enc_serializer=encoded_payload.enc_serializer)
else:
msg = message.Error(request_type,
request,
error,
args,
kwargs)
return msg
def _cancel_both_sides():
"""
The timeout was reacted; send an ERROR to the caller and INTERRUPT
to the callee
"""
if _can_cancel(invoke_request.caller, 'caller'):
self._router.send(
invoke_request.caller,
message.Error(
message.Call.MESSAGE_TYPE,
call.request,
ApplicationError.CANCELED,
[u"timeout reached"],
),
)
if _can_cancel(invoke_request.callee, 'callee'):
self._router.send(
invoke_request.callee,
message.Interrupt(
invoke_request.id,
message.Cancel.KILLNOWAIT, # or KILL ?
)
)
self._remove_invoke_request(invoke_request)
invoke_request.timeout_call = self._cancel_timers.call_later(timeout, _cancel_both_sides)
def processRegister(self, session, register):
"""
Implements :func:`autobahn.wamp.interfaces.IDealer.processRegister`
"""
assert(session in self._session_to_registrations)
## check procedure URI
##
if (not self._option_uri_strict and not _URI_PAT_LOOSE_NON_EMPTY.match(register.procedure)) or \
( self._option_uri_strict and not _URI_PAT_STRICT_NON_EMPTY.match(register.procedure)):
reply = message.Error(message.Register.MESSAGE_TYPE, register.request, ApplicationError.INVALID_URI, ["register for invalid procedure URI '{0}'".format(register.procedure)])
session._transport.send(reply)
else:
if not register.procedure in self._procs_to_regs:
## authorize action
##
d = self._as_future(self._router.authorize, session, register.procedure, IRouter.ACTION_REGISTER)
def on_authorize_success(authorized):
if authorized:
registration_id = util.id()
self._procs_to_regs[register.procedure] = (registration_id, session, register.discloseCaller)
self._regs_to_procs[registration_id] = register.procedure
callee_authrole = None
# we've maybe cancelled this invocation
if invocation_request.canceled:
# see if we're waiting to send the error back to the
# other side (see note about race-condition in Yield)
if invocation_request.error_msg:
reply = invocation_request.error_msg
invocation_request.error_msg = None
else:
if error.payload is None:
# validate normal args/kwargs payload
try:
self._router.validate('call_error', invocation_request.call.procedure, error.args, error.kwargs)
except Exception as e:
reply = message.Error(message.Call.MESSAGE_TYPE,
invocation_request.call.request,
ApplicationError.INVALID_ARGUMENT,
["call error from procedure '{0}' with invalid application payload: {1}".format(invocation_request.call.procedure, e)],
callee=callee,
callee_authid=callee_authid,
callee_authrole=callee_authrole,
forward_for=forward_for)
else:
reply = message.Error(message.Call.MESSAGE_TYPE,
invocation_request.call.request,
error.error,
args=error.args,
kwargs=error.kwargs,
callee=callee,
callee_authid=callee_authid,
callee_authrole=callee_authrole,
if not subscribers:
del self._subscription_to_sessions[unsubscribe.subscription]
_, subscribers = self._topic_to_sessions[topic]
subscribers.discard(session)
if not subscribers:
del self._topic_to_sessions[topic]
self._session_to_subscriptions[session].discard(unsubscribe.subscription)
reply = message.Unsubscribed(unsubscribe.request)
else:
reply = message.Error(message.Unsubscribe.MESSAGE_TYPE, unsubscribe.request, ApplicationError.NO_SUCH_SUBSCRIPTION)
session._transport.send(reply)
elif registration.extra.invoke == message.Register.INVOKE_LAST:
callee = registration.observers[len(registration.observers) - 1]
else:
# should not arrive here
raise Exception("logic error")
# check maximum concurrency of the (single) endpoint
callee_extra = registration.observers_extra.get(callee, None)
if callee_extra:
if callee_extra.concurrency and callee_extra.concurrency_current >= callee_extra.concurrency:
if is_queued_call or (self._call_store and self._call_store.maybe_queue_call(session, call, registration, authorization)):
return False
else:
reply = message.Error(
message.Call.MESSAGE_TYPE,
call.request,
'crossbar.error.max_concurrency_reached',
['maximum concurrency {} of callee/endpoint reached (on non-shared/single registration)'.format(callee_extra.concurrency)]
)
reply.correlation_id = call.correlation_id
reply.correlation_uri = call.procedure
reply.correlation_is_anchor = False
reply.correlation_is_last = True
self._router.send(session, reply)
return False
else:
callee_extra.concurrency_current += 1
elif registration.extra.invoke == message.Register.INVOKE_ROUNDROBIN:
def on_authorize_success(authorized):
if not authorized:
reply = message.Error(message.Subscribe.MESSAGE_TYPE, subscribe.request, ApplicationError.NOT_AUTHORIZED, ["session is not authorized to subscribe to topic '{0}'".format(subscribe.topic)])
else:
if not subscribe.topic in self._topic_to_sessions:
subscription = util.id()
self._topic_to_sessions[subscribe.topic] = (subscription, set())
subscription, subscribers = self._topic_to_sessions[subscribe.topic]
if not session in subscribers:
subscribers.add(session)
if not subscription in self._subscription_to_sessions:
self._subscription_to_sessions[subscription] = (subscribe.topic, set())
_, subscribers = self._subscription_to_sessions[subscription]
if self._router.is_traced:
reply.correlation_uri = registration.uri
reply.correlation_is_last = not has_follow_up_messages
else:
# registration exists on this dealer, but the session that wanted to unregister wasn't registered
#
reply = message.Error(message.Unregister.MESSAGE_TYPE, unregister.request, ApplicationError.NO_SUCH_REGISTRATION)
if self._router.is_traced:
reply.correlation_uri = reply.error
reply.correlation_is_last = True
else:
# registration doesn't even exist on this broker
#
reply = message.Error(message.Unregister.MESSAGE_TYPE, unregister.request, ApplicationError.NO_SUCH_REGISTRATION)
if self._router.is_traced:
reply.correlation_uri = reply.error
reply.correlation_is_last = True
if self._router.is_traced:
self._router._factory._worker._maybe_trace_rx_msg(session, unregister)
reply.correlation_id = unregister.correlation_id
reply.correlation_is_anchor = False
self._router.send(session, reply)
elif msg.request in self._unregister_reqs:
# get and pop outstanding subscribe request
request = self._unregister_reqs.pop(msg.request)
# if the registration still exists, mark as inactive and remove ..
if request.registration_id in self._registrations:
self._registrations[request.registration_id].active = False
del self._registrations[request.registration_id]
# resolve deferred/future for unregistering successfully
txaio.resolve(request.on_reply)
else:
raise ProtocolError("UNREGISTERED received for non-pending request ID {0}".format(msg.request))
elif isinstance(msg, message.Error):
# remove outstanding request and get the reply deferred/future
on_reply = None
# ERROR reply to CALL
if msg.request_type == message.Call.MESSAGE_TYPE and msg.request in self._call_reqs:
on_reply = self._call_reqs.pop(msg.request).on_reply
# ERROR reply to PUBLISH
elif msg.request_type == message.Publish.MESSAGE_TYPE and msg.request in self._publish_reqs:
on_reply = self._publish_reqs.pop(msg.request).on_reply
# ERROR reply to SUBSCRIBE
elif msg.request_type == message.Subscribe.MESSAGE_TYPE and msg.request in self._subscribe_reqs:
on_reply = self._subscribe_reqs.pop(msg.request).on_reply