pyplanet.core.events

The events manager contains the class that manages custom and abstract callbacks into the system callbacks. Once a signals is registered here it could be used by string reference. This makes it easy to have dynamically signals being created by other apps in a single place so it could be used over all apps.

For example you would create your own custom signal if you have a app for your own created game mode script that abstracts all the raw XML-RPC events into nice structured and maybe even including fetched data from external sources.

class pyplanet.core.events.manager._SignalManager[source]

Signal Manager class.

Note

Access this via instance.signal_manager.

finish_reservations()[source]

The method will copy all reservations to the actual signals. (PRIVATE)

finish_start(*args, **kwargs)[source]

Finish startup the core, this will copy reservations. (PRIVATE).

get_callback(call_name)[source]

Get signal by XML-RPC (script) callback.

Parameters:call_name – Callback name.
Returns:Signal class or nothing.
Return type:pyplanet.core.events.Signal
get_signal(key)[source]

Get signal by key (namespace:code).

Parameters:key – namespace:code key.
Returns:signal or none
Return type:pyplanet.core.events.Signal
init_app(app)[source]

Initiate app, load all signal/callbacks files. (just import, they should register with decorators).

Parameters:app (pyplanet.apps.AppConfig) – App instance
listen(signal, target, conditions=None, **kwargs)[source]

Register a listing client to the signal given (signal instance or string).

Parameters:
  • signal – Signal instance or string: “namespace:code”
  • target – Target method to call.
  • conditions – Reserved for future purposes.
register_signal(signal, app=None, callback=False)[source]

Register a signal to be known in the signalling system.

Parameters:
  • signal – Signal(s)
  • app – App context/instance.
  • callback – Will a callback handle the response (mostly raw callbacks).

pyplanet.core.events.callback

This file contains a glue between core callbacks and desired callbacks.

class pyplanet.core.events.callback.Callback(call, namespace, code, target=None)[source]

A callback signal is an double signal. Once for the GBX Callback itself (the Gbx callback named). And the destination Between those two signals is a sort of processor that confirms it into the PyPlanet style objects.

For example, a player connect will result in a player database object instead of the plain Maniaplanet payload. This will make it possible to develop your app as fast as possible, without any overhead and make it better with callback payload changes!

glue(signal, source, **kwargs)[source]

The glue method converts the source signal (gbx callback) into the pyplanet signal.

pyplanet.core.events.callback.handle_generic(source, signal, **kwargs)[source]

The handle_generic is a simple handle (processing glue) for just forwarding the payload from the maniaplanet server into the signal payload.

pyplanet.core.events.dispatcher

This file has been forked from Django and PyDispatcher. The PyDispatcher is licensed under BSD.

class pyplanet.core.events.dispatcher.Signal(code=None, namespace=None, process_target=None, use_caching=False)[source]

A signal is a destination tho distribute to where multiple listeners get the message. (event distribution).

class Meta[source]

The meta-class contains the code of the signal, used for string notation. An optional namespace could be given to override the app label namespace.

Warning

Only change or access this if you override the Signal class in your own class.

has_listeners()[source]

Has the signal listeners.

Returns:
process(**data)[source]

This method processed data into abstract data. You can give your own function in the init of the Signal or override the method.

Parameters:data – Raw data input
Returns:Parsed data output
register(receiver, weak=True, dispatch_uid=None)[source]

Connect receiver to sender for signal.

Parameters:
  • receiver – A function or an instance method which is to receive signals. Receivers must be hashable objects. If weak is True, then receiver must be weak referenceable.Receivers must be able to accept keyword arguments. If a receiver is connected with a dispatch_uid argument, it will not be added if another receiver was already connected with that dispatch_uid.
  • weak – Whether to use weak references to the receiver. By default, the module will attempt to use weak references to the receiver objects. If this parameter is false, then strong references will be used.
  • dispatch_uid – An identifier used to uniquely identify a particular instance of a receiver. This will usually be a string, though it may be anything hashable.
send(source, raw=False, catch_exceptions=False, gather=True)[source]

Send signal with source. If any receiver raises an error, the error propagates back through send, terminating the dispatch loop. So it’s possible that all receivers won’t be called if an error is raised.

Parameters:
  • source – The data to be send to the processor which produces data that will be send to the receivers.
  • raw – Optional bool parameter to just send the source to the receivers without any processing.
  • catch_exceptions – Catch and return the exceptions.
  • gather – Execute multiple receivers at the same time (parallel). On by default!
Returns:

Return a list of tuple pairs [(receiver, response), … ].

send_robust(source=None, raw=False, gather=True)[source]

Send signal from sender to all connected receivers catching errors.

Parameters:
  • source – The data to be send to the processor which produces data that will be send to the receivers.
  • raw – Optional bool parameter to just send the source to the receivers without any processing.
  • gather – Execute multiple receivers at the same time (parallel). On by default!
Returns:

Return a list of tuple pairs [(receiver, response), … ]. If any receiver raises an error (specifically any subclass of Exception), return the error instance as the result for that receiver.

set_self(receiver, slf)[source]

Set the self instance on a receiver.

Deprecated since version 0.0.1.

Parameters:
  • receiver – Receiver function.
  • slf – Self instance
unregister(receiver=None, dispatch_uid=None)[source]

Disconnect receiver from sender for signal. If weak references are used, disconnect need not be called. The receiver will be removed from dispatch automatically.

Parameters:
  • receiver – The registered receiver to disconnect. May be none if dispatch_uid is specified.
  • dispatch_uid – the unique identifier of the receiver to disconnect