adhocracy_core.websockets.server module

Classes used by the standalone Websocket server.

class ClientTracker[source]

Bases: object

Keeps track of the clients that want notifications.

Initialize self.

is_subscribed(client: collections.abc.Hashable, resource: <InterfaceClass adhocracy_core.interfaces.IResource>) → bool[source]

Check whether a client is subscribed to a resource.

subscribe(client: collections.abc.Hashable, resource: <InterfaceClass adhocracy_core.interfaces.IResource>) → bool[source]

Subscribe a client to a resource, if necessary.

Returns:True if the subscription was successful, False if it was unnecessary (the client was already subscribed).
unsubscribe(client: collections.abc.Hashable, resource: <InterfaceClass adhocracy_core.interfaces.IResource>) → bool[source]

Unsubscribe a client from a resource, if necessary.

Returns:True if the unsubscription was successful, False if it was unnecessary (the client was not subscribed).
delete_subscriptions_for_client(client: collections.abc.Hashable)[source]

Delete all subscriptions for a client.

delete_subscriptions_to_resource(resource: <InterfaceClass adhocracy_core.interfaces.IResource>)[source]

Delete all subscriptions to a resource.

iterate_subscribers(resource: <InterfaceClass adhocracy_core.interfaces.IResource>) → collections.abc.Iterable[source]

Return an iterator over all clients subscribed to a resource.

class DummyRequest(application_url, root)[source]

Bases: object

Dummy request to create/resolve resource urls.

This is needed to de/serialize SchemaNodes with adhocracy_core.schema.ResourceObject schema type.

Initialize self.

application_url = None

URL prefix used to extract resource paths.

root = None

The root resource to resolve resource paths

resource_url(resource, **kwargs)[source]

Return the pyramid resource url.

class ClientCommunicator[source]

Bases: autobahn.asyncio.websocket.WebSocketServerProtocol

Communicates with a client through a WebSocket connection.

Note that the zodb_connection attribute must be set instances of this class can be used!

zodb_database = None
rest_url = 'http://localhost:6541'
onConnect(request: autobahn.websocket.protocol.ConnectionRequest)[source]
onOpen()[source]
onMessage(payload: bytes, is_binary: bool)[source]
send_notification(resource: <InterfaceClass adhocracy_core.interfaces.IResource>, event_type: str)[source]

Send notification about an event affecting a resource.

send_child_notification(status: str, resource: <InterfaceClass adhocracy_core.interfaces.IResource>, child: <InterfaceClass adhocracy_core.interfaces.IResource>)[source]

Send notification concerning a child resource.

Parameters:status (str) – should be ‘new’, ‘removed’, or ‘modified’
send_new_version_notification(resource: <InterfaceClass adhocracy_core.interfaces.IResource>, new_version: <InterfaceClass adhocracy_core.interfaces.IResource>)[source]

Send notification if a new version has been added.

onClose(was_clean: bool, code: int, reason: str)[source]