asphalt.wamp.registry
¶
-
class
asphalt.wamp.registry.
Procedure
(name, handler, options)¶ Create new instance of Procedure(name, handler, options)
-
handler
¶ Alias for field number 1
-
name
¶ Alias for field number 0
-
options
¶ Alias for field number 2
-
-
class
asphalt.wamp.registry.
Subscriber
(topic, handler, options)¶ Create new instance of Subscriber(topic, handler, options)
-
handler
¶ Alias for field number 1
-
options
¶ Alias for field number 2
-
topic
¶ Alias for field number 0
-
-
class
asphalt.wamp.registry.
WAMPRegistry
(prefix='', *, procedure_defaults=None, subscription_defaults=None)¶ Hosts a collection of WAMP procedure and subscriber registrations and exception mappings.
The purpose of this class is to ease the task of collecting all of the procedure handlers, event listeners and exception mappings of the application into a single place that the client can then use to register those on the router when a session has been opened. The alternative would be to call
register_procedure()
,subscribe()
andmap_exception()
afterconnect()
. This would not be very modular, however, since the code the connects the client would have to know about every single handler callbacks in advance.Variables: Parameters: - prefix (
str
) – a prefix that is added to the name of every registered procedure - procedure_defaults (
Union
[RegisterOptions
,Dict
[str
,Any
],None
]) – default values to use for omitted arguments toadd_procedure()
- subscription_defaults (
Union
[SubscribeOptions
,Dict
[str
,Any
],None
]) – default values to use for omitted arguments toadd_subscriber()
-
add_from
(registry, prefix='')¶ Add all the procedures, subscribers and exception mappings from another registry to this one.
If no prefix has been specified, the final name of each added procedure/subscriber endpoint or mapped error will be of the form
<root prefix>.<name>
. If a prefix has been specified, the name will be<root prefix>.<prefix>.<name>
.Parameters: - registry (
WAMPRegistry
) – a WAMP registry - prefix (
str
) – prefix to add to names of all procedure endpoints
Return type: None
- registry (
-
add_procedure
(handler, name=None, options=None)¶ Add a procedure handler.
The callable will receive a
CallContext
instance as its first argument. The other positional and keyword arguments will be the arguments the caller passed to it.Parameters: - handler (
Callable
) – callable that handles the procedure calls - name (
Optional
[str
]) – name of the endpoint to register (relative to registry’s prefix); ifNone
, use the callable’s internal name - options (
Union
[RegisterOptions
,Dict
[str
,Any
],None
]) – either an Autobahn register options object or a dictionary of keyword arguments to make one
Return type: Returns: the procedure registration object
Raises: - TypeError – if the handler does not accept at least a single positional argument
- ValueError – if there is already a handler registered for this endpoint
See also
See also
See also
- handler (
-
add_subscriber
(handler, topic, options=None)¶ Decorator that registers a callable to receive events on the given topic.
The callable will receive an
EventContext
instance as its first argument and must return an awaitable. The other positional and keyword arguments will be the arguments the publisher passed to thepublish()
method.The topic may contain wildcards (
a..b
).Parameters: Return type: Returns: the subscription registration object
Raises: TypeError – if the handler is not a coroutine or does not accept at least a single positional argument
See also
See also
-
exception
(error)¶ Decorator version of
map_exception()
.Parameters: error ( str
) – the WAMP error code (e.g.foo.bar.baz
)Return type: Callable
-
map_exception
(exc_type, code)¶ Map a Python exception class to a WAMP error code.
Parameters: - code (
str
) – the WAMP error code (e.g.foo.bar.baz
) - exc_type (
Type
[BaseException
]) – an exception class
Raises: TypeError – if
exc_type
does not inherit from :class`BaseException`Return type: None
- code (
-
procedure
(name=None, options=None)¶ Decorator version of
add_procedure()
.Can be used as
@procedure(...)
or simply@procedure
.If
name
has not been specified, the function name of the handler is used.Parameters: Return type:
-
subscriber
(topic, options=None)¶ Decorator version of
add_subscriber()
.Parameters: See also
See also
Return type: Callable
- prefix (