1.1.13. server_events

This module provides functionality to allow the client application to subscribe to events which are published by the server.

1.1.13.1. Functions

event_type_filter(event_types, is_method=False)[source]

A decorator to filter a signal handler by the specified event types. Using this will ensure that the decorated function is only called for the specified event types and not others which may have been subscribed to elsewhere in the application.

Parameters:
  • event_types (list, str) – A single event type as a string or a list of event type strings.
  • is_method (bool) – Whether or not the function being decorated is a class method.

1.1.13.2. Classes

class ServerEventSubscriber(rpc)[source]

Bases: GObject.GObject

An object which provides functionality to subscribe to events that are published by the remote King Phisher server instance. This object manages the subscriptions and forwards the events allowing consumers to connect to the available GObject signals.

Note

Both the ServerEventSubscriber.subscribe() and ServerEventSubscriber.unsubscribe() methods of this object internally implement reference counting for the server events. This makes it possible for multiple subscriptions to be created and deleted without interfering with each other.

The socket is opened automatically when this object is initialized and will automatically attempt to reconnect if the connection is closed if the reconnect attribute is true. After initializing this object, check the is_connected attribute to ensure that it is properly connected to the server.

__init__(rpc)[source]
Parameters:rpc (KingPhisherRPCClient) – The client’s connected RPC instance.
is_connected[source]

True if the event socket is connected to the server.

is_subscribed(event_id, event_type)[source]

Check if the client is currently subscribed to the specified server event.

Parameters:
  • event_id (str) – The identifier of the event to subscribe to.
  • event_type (str) – A sub-type for the corresponding event.
Returns:

Whether or not the client is subscribed to the event.

Return type:

bool

reconnect = None[source]

Whether or not the socket should attempt to reconnect itself when it has been closed.

shutdown()[source]

Disconnect the event socket from the remote server. After the object is shutdown, remove events will no longer be published.

Parameters:timeout (int) – An optional timeout for how long to wait on the worker thread.
subscribe(event_id, event_types, attributes)[source]

Subscribe the client to the specified event published by the server. When the event is published the specified attributes of it and it’s corresponding id and type information will be sent to the client.

Parameters:
  • event_id (str) – The identifier of the event to subscribe to.
  • event_types (list) – A list of sub-types for the corresponding event.
  • attributes (list) – A list of attributes of the event object to be sent to the client.
unsubscribe(event_id, event_types, attributes)[source]

Unsubscribe from an event published by the server that the client previously subscribed to.

Parameters:
  • event_id (str) – The identifier of the event to subscribe to.
  • event_types (list) – A list of sub-types for the corresponding event.
  • attributes (list) – A list of attributes of the event object to be sent to the client.