autobahn.wamp.protocol


Module Contents

Classes

BaseSession

WAMP session base class.

ApplicationSession

WAMP application session for applications (networking framework agnostic parts).

_SessionShim

shim that lets us present pep8 API for user-classes to override,

ApplicationSessionFactory

WAMP endpoint session factory.

Functions

is_method_or_function(f)

autobahn.wamp.protocol.is_method_or_function(f)[source]
class autobahn.wamp.protocol.BaseSession[source]

Bases: autobahn.util.ObservableMixin

WAMP session base class.

This class implements autobahn.wamp.interfaces.ISession.

property transport: Optional[autobahn.wamp.interfaces.ITransport]

Implements autobahn.wamp.interfaces.ITransportHandler.transport()

property session_details: Optional[autobahn.wamp.types.SessionDetails]

Implements autobahn.wamp.interfaces.ISession.session_details()

property realm: Optional[str]
property session_id: Optional[int]
property authid: Optional[str]
property authrole: Optional[str]
property authmethod: Optional[str]
property authprovider: Optional[str]
property authextra: Optional[Dict[str, Any]]
log
is_connected() bool[source]

Implements autobahn.wamp.interfaces.ISession.is_connected()

is_attached() bool[source]

Implements autobahn.wamp.interfaces.ISession.is_attached()

define(exception: Exception, error: Optional[str] = None)[source]

Implements autobahn.wamp.interfaces.ISession.define()

_message_from_exception(request_type, request, exc, tb=None, enc_algo=None)[source]

Create a WAMP error message from an exception.

Parameters
  • request_type (int) – The request type this WAMP error message is for.

  • request (int) – The request ID this WAMP error message is for.

  • exc (Instance of Exception or subclass thereof.) – The exception.

  • tb (list or None) – Optional traceback. If present, it’ll be included with the WAMP error message.

_exception_from_message(msg)[source]

Create a user (or generic) exception from a WAMP error message.

Parameters

msg (instance of autobahn.wamp.message.Error) – A WAMP error message.

class autobahn.wamp.protocol.ApplicationSession(config: Optional[autobahn.wamp.types.ComponentConfig] = None)[source]

Bases: BaseSession

WAMP application session for applications (networking framework agnostic parts).

Implements (partially):

property config: autobahn.wamp.types.ComponentConfig
set_payload_codec(payload_codec: Optional[autobahn.wamp.interfaces.IPayloadCodec])[source]

Implements autobahn.wamp.interfaces.ISession.set_payload_codec()

get_payload_codec() Optional[autobahn.wamp.interfaces.IPayloadCodec][source]

Implements autobahn.wamp.interfaces.ISession.get_payload_codec()

onOpen(transport: autobahn.wamp.interfaces.ITransport)[source]

Implements autobahn.wamp.interfaces.ITransportHandler.onOpen()

onConnect()[source]

Implements autobahn.wamp.interfaces.ISession.onConnect()

join(realm: str, authmethods: Optional[List[str]] = None, authid: Optional[str] = None, authrole: Optional[str] = None, authextra: Optional[Dict[str, Any]] = None, resumable: Optional[bool] = None, resume_session: Optional[int] = None, resume_token: Optional[str] = None)[source]

Implements autobahn.wamp.interfaces.ISession.join()

disconnect()[source]

Implements autobahn.wamp.interfaces.ISession.disconnect()

onUserError(fail, msg)[source]

Implements autobahn.wamp.interfaces.ISession.onUserError()

_swallow_error(fail, msg)[source]

This is an internal generic error-handler for errors encountered when calling down to on*() handlers that can reasonably be expected to be overridden in user code.

Note that it cancels the error, so use with care!

Specifically, this should never be added to the errback chain for a Deferred/coroutine that will make it out to user code.

type_check(func)[source]

Does parameter type checking and validation against type hints and appropriately tells the user code and the caller (through router).

onMessage(msg: autobahn.wamp.interfaces.IMessage)[source]

Implements autobahn.wamp.interfaces.ITransportHandler.onMessage()

onClose(wasClean)[source]

Implements autobahn.wamp.interfaces.ITransportHandler.onClose()

onChallenge(challenge: autobahn.wamp.types.Challenge) str[source]

Implements autobahn.wamp.interfaces.ISession.onChallenge()

onJoin(details: autobahn.wamp.types.SessionDetails)[source]

Implements autobahn.wamp.interfaces.ISession.onJoin()

onWelcome(welcome: autobahn.wamp.message.Welcome) Optional[str][source]

Implements autobahn.wamp.interfaces.ISession.onWelcome()

_errback_outstanding_requests(exc)[source]

Errback any still outstanding requests with exc.

onLeave(details: autobahn.wamp.types.CloseDetails)[source]

Implements autobahn.wamp.interfaces.ISession.onLeave()

leave(reason: Optional[str] = None, message: Optional[str] = None)[source]

Implements autobahn.wamp.interfaces.ISession.leave()

onDisconnect()[source]

Implements autobahn.wamp.interfaces.ISession.onDisconnect()

publish(topic: str, *args, **kwargs) Optional[autobahn.wamp.request.Publication][source]

Implements autobahn.wamp.interfaces.IPublisher.publish()

subscribe(handler: Union[Callable, Any], topic: Optional[str] = None, options: Optional[autobahn.wamp.types.SubscribeOptions] = None, check_types: Optional[bool] = None) Union[autobahn.wamp.request.Subscription, List[autobahn.wamp.request.Subscription]][source]

Implements autobahn.wamp.interfaces.ISubscriber.subscribe()

_unsubscribe(subscription)[source]

Called from autobahn.wamp.protocol.Subscription.unsubscribe()

call(procedure: str, *args, **kwargs) Union[Any, autobahn.wamp.types.CallResult][source]

Implements autobahn.wamp.interfaces.ICaller.call()

Note

Regarding type hints for *args and **kwargs, doesn’t work as we can receive any Python types as list items or dict values, and because of what is discussed here https://adamj.eu/tech/2021/05/11/python-type-hints-args-and-kwargs/

register(endpoint: Union[Callable, Any], procedure: Optional[str] = None, options: Optional[autobahn.wamp.types.RegisterOptions] = None, prefix: Optional[str] = None, check_types: Optional[bool] = None) Union[autobahn.wamp.request.Registration, List[autobahn.wamp.request.Registration]][source]

Implements autobahn.wamp.interfaces.ICallee.register()

_unregister(registration)[source]

Called from autobahn.wamp.protocol.Registration.unregister()

class autobahn.wamp.protocol._SessionShim(config: Optional[autobahn.wamp.types.ComponentConfig] = None)[source]

Bases: ApplicationSession

shim that lets us present pep8 API for user-classes to override, but also backwards-compatible for existing code using ApplicationSession “directly”.

NOTE: this is not public or intended for use; you should import either autobahn.asyncio.wamp.Session or autobahn.twisted.wamp.Session depending on which async framework yo’re using.

_authenticators
onJoin(details)[source]

Implements autobahn.wamp.interfaces.ISession.onJoin()

onConnect()[source]

Implements autobahn.wamp.interfaces.ISession.onConnect()

onChallenge(challenge)[source]

Implements autobahn.wamp.interfaces.ISession.onChallenge()

onWelcome(msg)[source]

Implements autobahn.wamp.interfaces.ISession.onWelcome()

onLeave(details)[source]

Implements autobahn.wamp.interfaces.ISession.onLeave()

onDisconnect()[source]

Implements autobahn.wamp.interfaces.ISession.onDisconnect()

add_authenticator(authenticator)[source]
_merged_authextra()[source]

internal helper

Returns

a single ‘authextra’ dict, consisting of all keys from any authenticator’s authextra.

Note that when the authenticator was added, we already checked that any keys it does contain has the same value as any existing authextra.

on_join(details)[source]
on_leave(details)[source]
on_connect()[source]
on_disconnect()[source]
class autobahn.wamp.protocol.ApplicationSessionFactory(config=None)[source]

Bases: object

WAMP endpoint session factory.

session

WAMP application session class to be used in this factory.

__call__()[source]

Creates a new WAMP application session.

Returns

– An instance of the WAMP application session class as given by self.session.