Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _success(_):
# Acknowledged Events -- only if we got the details header and
# the broker advertised it
if msg.x_acknowledged_delivery and self._router_roles["broker"].x_acknowledged_event_delivery:
if self._transport:
response = message.EventReceived(msg.publication)
self._transport.send(response)
else:
self.log.warn("successfully processed event with acknowledged delivery, but could not send ACK, since the transport was lost in the meantime")
def processPublish(self, session, publish):
"""
Implements :func:`autobahn.wamp.interfaces.IBroker.processPublish`
"""
#assert(session in self._session_to_subscriptions)
## check topic URI
##
if (not self._option_uri_strict and not _URI_PAT_LOOSE_NON_EMPTY.match(publish.topic)) or \
( self._option_uri_strict and not _URI_PAT_STRICT_NON_EMPTY.match(publish.topic)):
if publish.acknowledge:
reply = message.Error(message.Publish.MESSAGE_TYPE, publish.request, ApplicationError.INVALID_URI, ["publish with invalid topic URI '{0}'".format(publish.topic)])
session._transport.send(reply)
return
if publish.topic in self._topic_to_sessions or publish.acknowledge:
## validate payload
##
try:
self._router.validate('event', publish.topic, publish.args, publish.kwargs)
except Exception as e:
reply = message.Error(message.Publish.MESSAGE_TYPE, publish.request, ApplicationError.INVALID_ARGUMENT, ["publish to topic URI '{0}' with invalid application payload: {1}".format(publish.topic, e)])
session._transport.send(reply)
return
## authorize action
def _on_message(self, inc_msg):
self.log.debug('WampMQTTServerProtocol._on_message(inc_msg={inc_msg})', inc_msg=inc_msg)
if isinstance(inc_msg, message.Challenge):
assert inc_msg.method == "ticket"
msg = message.Authenticate(signature=self._pw_challenge)
del self._pw_challenge
self._wamp_session.onMessage(msg)
elif isinstance(inc_msg, message.Welcome):
self._waiting_for_connect.callback((0, False))
elif isinstance(inc_msg, message.Abort):
self._waiting_for_connect.callback((1, False))
elif isinstance(inc_msg, message.Subscribed):
# Successful subscription!
mqtt_id = self._subrequest_to_mqtt_subrequest[inc_msg.request]
message.Hello.MESSAGE_TYPE: message.Hello,
message.Welcome.MESSAGE_TYPE: message.Welcome,
message.Abort.MESSAGE_TYPE: message.Abort,
message.Challenge.MESSAGE_TYPE: message.Challenge,
message.Authenticate.MESSAGE_TYPE: message.Authenticate,
message.Goodbye.MESSAGE_TYPE: message.Goodbye,
message.Error.MESSAGE_TYPE: message.Error,
message.Publish.MESSAGE_TYPE: message.Publish,
message.Published.MESSAGE_TYPE: message.Published,
message.Subscribe.MESSAGE_TYPE: message.Subscribe,
message.Subscribed.MESSAGE_TYPE: message.Subscribed,
message.Unsubscribe.MESSAGE_TYPE: message.Unsubscribe,
message.Unsubscribed.MESSAGE_TYPE: message.Unsubscribed,
message.Event.MESSAGE_TYPE: message.Event,
message.Call.MESSAGE_TYPE: message.Call,
message.Cancel.MESSAGE_TYPE: message.Cancel,
message.Result.MESSAGE_TYPE: message.Result,
message.Register.MESSAGE_TYPE: message.Register,
message.Registered.MESSAGE_TYPE: message.Registered,
message.Unregister.MESSAGE_TYPE: message.Unregister,
message.Unregistered.MESSAGE_TYPE: message.Unregistered,
message.Invocation.MESSAGE_TYPE: message.Invocation,
message.Interrupt.MESSAGE_TYPE: message.Interrupt,
message.Yield.MESSAGE_TYPE: message.Yield
}
"""
Mapping of WAMP message type codes to WAMP message classes.
"""
def __init__(self, serializer):
"""
txaio.add_callbacks(on_reply, success, error)
elif isinstance(msg, message.Interrupt):
if msg.request not in self._invocations:
# raise ProtocolError("INTERRUPT received for non-pending invocation {0}".format(msg.request))
self.log.debug('INTERRUPT received for non-pending invocation {request}', request=msg.request)
else:
invoked = self._invocations[msg.request]
# this will result in a CancelledError which will
# be captured by the error handler around line 979
# to delete the invocation..
txaio.cancel(invoked.on_reply)
elif isinstance(msg, message.Registered):
if msg.request in self._register_reqs:
# get and pop outstanding register request
request = self._register_reqs.pop(msg.request)
# create new registration if not yet tracked
if msg.registration not in self._registrations:
registration = Registration(self, msg.registration, request.procedure, request.endpoint)
self._registrations[msg.registration] = registration
else:
raise ProtocolError("REGISTERED received for already existing registration ID {0}".format(msg.registration))
txaio.resolve(request.on_reply, registration)
else:
raise ProtocolError("REGISTERED received for non-pending request ID {0}".format(msg.request))
# note: __all__ must be a list here, since we dynamically
# extend it depending on availability of more serializers
__all__ = ['Serializer',
'JsonObjectSerializer',
'JsonSerializer']
class Serializer(object):
"""
Base class for WAMP serializers. A WAMP serializer is the core glue between
parsed WAMP message objects and the bytes on wire (the transport).
"""
MESSAGE_TYPE_MAP = {
message.Hello.MESSAGE_TYPE: message.Hello,
message.Welcome.MESSAGE_TYPE: message.Welcome,
message.Abort.MESSAGE_TYPE: message.Abort,
message.Challenge.MESSAGE_TYPE: message.Challenge,
message.Authenticate.MESSAGE_TYPE: message.Authenticate,
message.Goodbye.MESSAGE_TYPE: message.Goodbye,
message.Error.MESSAGE_TYPE: message.Error,
message.Publish.MESSAGE_TYPE: message.Publish,
message.Published.MESSAGE_TYPE: message.Published,
message.Subscribe.MESSAGE_TYPE: message.Subscribe,
message.Subscribed.MESSAGE_TYPE: message.Subscribed,
message.Unsubscribe.MESSAGE_TYPE: message.Unsubscribe,
message.Unsubscribed.MESSAGE_TYPE: message.Unsubscribed,
message.Event.MESSAGE_TYPE: message.Event,
if yield_.payload is None:
# validate normal args/kwargs payload
try:
self._router.validate('call_result', invocation_request.call.procedure, yield_.args, yield_.kwargs)
except Exception as e:
is_valid = False
reply = message.Error(message.Call.MESSAGE_TYPE,
invocation_request.call.request,
ApplicationError.INVALID_ARGUMENT,
["call result 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.Result(invocation_request.call.request,
args=yield_.args,
kwargs=yield_.kwargs,
progress=yield_.progress,
callee=callee,
callee_authid=callee_authid,
callee_authrole=callee_authrole,
forward_for=forward_for)
else:
reply = message.Result(invocation_request.call.request,
payload=yield_.payload,
progress=yield_.progress,
enc_algo=yield_.enc_algo,
enc_key=yield_.enc_key,
enc_serializer=yield_.enc_serializer,
callee=callee,
callee_authid=callee_authid,
def _register(obj, fn, procedure, options):
message.check_or_raise_uri(procedure,
message='{}.register()'.format(self.__class__.__name__),
strict=False,
allow_empty_components=True,
allow_none=False)
request_id = self._request_id_gen.next()
on_reply = txaio.create_future()
endpoint_obj = Endpoint(fn, obj, options.details_arg if options else None)
if prefix is not None:
procedure = u"{}{}".format(prefix, procedure)
self._register_reqs[request_id] = RegisterRequest(request_id, on_reply, procedure, endpoint_obj)
if options:
msg = message.Register(request_id, procedure, **options.message_attr())
else:
msg = message.Register(request_id, procedure)
def _on_backend_joined(session, details):
msg = message.Welcome(self._session_id,
ProxyFrontendSession.ROLES,
realm=details.realm,
authid=details.authid,
authrole=details.authrole,
authmethod=auth_result.authmethod,
authprovider=auth_result.authprovider,
authextra=dict(details.authextra or {}, **self._custom_authextra))
self._backend_session = session
self.transport.send(msg)
self.log.info('Proxy frontend session WELCOME: session_id={session_id}, session={session}, msg={msg}',
session_id=hlid(self._session_id), session=self, msg=msg)