kxg.tokens.Token

class kxg.tokens.Token[source]

Bases: kxg.forums.ForumObserver

Event Handlers:

on_add_to_world(*args, **kwargs)

on_update_game(*args, **kwargs)

on_report_to_referee(reporter)

on_remove_from_world(*args, **kwargs)

Public Methods:

__init__()

Initialize self.

__repr__(**kwargs)

Return repr(self).

__getstate__()

__setstate__(state)

__extend__()

has_extension(actor)

get_extension(actor)

get_extensions()

watch_method(method_name, callback)

Register the given callback to be called whenever the method with the given name is called.

Inherited from ForumObserver

namedtuple(field_names, *[, rename, …])

Returns a new subclass of tuple with named fields.

__init__()

Initialize self.

__getstate__()

__setstate__(state)

subscribe_to_message(message_cls, callback)

subscribe_to_sync_response(message_cls, callback)

subscribe_to_undo_response(message_cls, callback)

unsubscribe_from_message(message_cls[, callback])

unsubscribe_from_sync_response(message_cls)

unsubscribe_from_undo_response(message_cls)

Private Methods:

_give_id(id_factory)

_check_if_forum_observation_enabled()

Give a helpful error if the user attempts to subscribe or unsubscribe from messages while the token is not registered with a world.

_add_to_world(world, actors)

_create_extensions(actors)

_remove_from_world()

Clear all the internal data the token needed while it was part of the world.

Inherited from ForumObserver

_react_to_message(message)

_react_to_sync_response(message)

_react_to_undo_response(message)

_enable_forum_observation()

_disable_forum_observation()

_check_if_forum_observation_enabled()

Give a helpful error if the user attempts to subscribe or unsubscribe from messages while the token is not registered with a world.

_add_callback(event, message_cls, callback)

_drop_callback(event, message_cls, callback)

_call_callbacks(event, message)

_get_nested_observers()

class CallbackInfo(message_cls, callback)

Bases: tuple

__add__(value, /)

Return self+value.

__contains__(key, /)

Return key in self.

__eq__(value, /)

Return self==value.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__getitem__(key, /)

Return self[key].

__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

__gt__(value, /)

Return self>value.

__hash__()

Return hash(self).

__iter__()

Implement iter(self).

__le__(value, /)

Return self<=value.

__len__()

Return len(self).

__lt__(value, /)

Return self<value.

__mul__(value, /)

Return self*value.

__ne__(value, /)

Return self!=value.

static __new__(_cls, message_cls, callback)

Create new instance of CallbackInfo(message_cls, callback)

__repr__()

Return a nicely formatted representation string

__rmul__(value, /)

Return value*self.

__slots__ = ()
_asdict()

Return a new OrderedDict which maps field names to their values.

_fields = ('message_cls', 'callback')
_fields_defaults = {}
classmethod _make(iterable)

Make a new CallbackInfo object from a sequence or iterable

_replace(**kwds)

Return a new CallbackInfo object replacing specified fields with new values

property callback

Alias for field number 1

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

property message_cls

Alias for field number 0

class WatchedMethod(method)[source]

Bases: object

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

Call self as a function.

__init__(method)[source]

Initialize self. See help(type(self)) for accurate signature.

add_watcher(watcher)[source]
__extend__()[source]
__getstate__()[source]
__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

__repr__(**kwargs)[source]

Return repr(self).

__setstate__(state)[source]
_add_callback(event, message_cls, callback)
_add_to_world(world, actors)[source]
_call_callbacks(event, message)
_check_if_forum_observation_enabled()[source]

Give a helpful error if the user attempts to subscribe or unsubscribe from messages while the token is not registered with a world.

This can easily happen if the user attempts to subscribe to messages in the constructor. However, because the constructor is only called on one client and message handlers cannot be pickled, subscribing at this time would create hard-to-find synchronization bugs.

_create_extensions(actors)[source]
_disable_forum_observation()
_drop_callback(event, message_cls, callback)
_enable_forum_observation()
_get_nested_observers()
_give_id(id_factory)[source]
_react_to_message(message)
_react_to_sync_response(message)
_react_to_undo_response(message)
_remove_from_world()[source]

Clear all the internal data the token needed while it was part of the world.

Note that this method doesn’t actually remove the token from the world. That’s what World._remove_token does. This method is just responsible for setting the internal state of the token being removed.

get_extension(actor)[source]
get_extensions()[source]
has_extension(actor)[source]
property has_id
property has_world
property id
namedtuple(field_names, *, rename=False, defaults=None, module=None)

Returns a new subclass of tuple with named fields.

>>> Point = namedtuple('Point', ['x', 'y'])
>>> Point.__doc__                   # docstring for the new class
'Point(x, y)'
>>> p = Point(11, y=22)             # instantiate with positional args or keywords
>>> p[0] + p[1]                     # indexable like a plain tuple
33
>>> x, y = p                        # unpack like a regular tuple
>>> x, y
(11, 22)
>>> p.x + p.y                       # fields also accessible by name
33
>>> d = p._asdict()                 # convert to a dictionary
>>> d['x']
11
>>> Point(**d)                      # convert from a dictionary
Point(x=11, y=22)
>>> p._replace(x=100)               # _replace() is like str.replace() but targets named fields
Point(x=100, y=22)
on_add_to_world(*args, **kwargs)[source]
on_remove_from_world(*args, **kwargs)[source]
on_report_to_referee(reporter)[source]
on_update_game(*args, **kwargs)[source]
subscribe_to_message(message_cls, callback)
subscribe_to_sync_response(message_cls, callback)
subscribe_to_undo_response(message_cls, callback)
unsubscribe_from_message(message_cls, callback=None)
unsubscribe_from_sync_response(message_cls, callback=None)
unsubscribe_from_undo_response(message_cls, callback=None)
watch_method(method_name, callback)[source]

Register the given callback to be called whenever the method with the given name is called. You can easily take advantage of this feature in token extensions by using the watch_token decorator.

property world