slidge.util.db#

This module covers a backend for storing user data persistently and managing a pseudo-roster for the gateway component.

Module Contents#

Classes#

EncryptedShelf

Shelf implementation using the "dbm" generic dbm interface.

GatewayUser

A dataclass representing a gateway user

UserStore

Basic user store implementation using shelve from the python standard library

YesSet

A pseudo-set which always test True for membership

RosterBackend

A pseudo-roster for the gateway component.

Attributes#

class slidge.util.db.EncryptedShelf(filename, key, flag='c', protocol=None, writeback=False)[source]#

Bases: shelve.DbfilenameShelf

Shelf implementation using the “dbm” generic dbm interface.

This is initialized with the filename for the dbm database. See the module’s __doc__ string for an overview of the interface.

Parameters:
cache: dict[source]#
dict: dict[source]#
writeback: bool[source]#
keyencoding: str[source]#
_protocol: int[source]#
__getitem__(key)[source]#
__setitem__(key, value)[source]#
class slidge.util.db.GatewayUser[source]#

A dataclass representing a gateway user

property jid: slixmpp.JID[source]#

The user’s (bare) JID

Returns:

Return type:

slixmpp.JID

bare_jid: str[source]#

Bare JID of the user

registration_form: dict[str, str | None][source]#

Content of the registration form, as a dict

plugin_data: dict | None[source]#
registration_date: datetime.datetime | None[source]#
__hash__()[source]#

Return hash(self).

__repr__()[source]#

Return repr(self).

__post_init__()[source]#
get(field, default='')[source]#

Get fields from the registration form (required to comply with slixmpp backend protocol)

Parameters:
  • field (str) – Name of the field

  • default (str) – Default value to return if the field is not present

Returns:

Value of the field

Return type:

Optional[str]

commit()[source]#
class slidge.util.db.UserStore[source]#

Basic user store implementation using shelve from the python standard library

Set_file must be called before it is usable

set_file(filename, secret_key=None)[source]#

Set the file to use to store user data

Parameters:
  • filename (os.PathLike) – Path to the shelf file

  • secret_key (Optional[str]) – Secret key to store files encrypted on disk

get_all()[source]#

Get all users in the store

Returns:

An iterable of GatewayUsers

Return type:

Iterable[GatewayUser]

add(jid, registration_form)[source]#

Add a user to the store.

NB: there is no reason to call this manually, as this should be covered by slixmpp XEP-0077 and XEP-0100 plugins

Parameters:
  • jid (slixmpp.JID) – JID of the gateway user

  • registration_form (dict[str, Optional[str]]) – Content of the registration form (XEP-0077)

commit(user)[source]#
Parameters:

user (GatewayUser) –

get(_gateway_jid, _node, ifrom, iq)[source]#

Get a user from the store

NB: there is no reason to call this, it is used by SliXMPP internal API

Parameters:
  • _gateway_jid

  • _node

  • ifrom (slixmpp.JID) –

  • iq

Returns:

Return type:

Optional[GatewayUser]

remove(_gateway_jid, _node, ifrom, _iq)[source]#

Remove a user from the store

NB: there is no reason to call this, it is used by SliXMPP internal API

Parameters:

ifrom (slixmpp.JID) –

remove_by_jid(jid)[source]#

Remove a user from the store, by JID

Parameters:

jid (slixmpp.JID) –

get_by_jid(jid)[source]#

Convenience function to get a user from their JID.

Parameters:

jid (slixmpp.JID) – JID of the gateway user

Returns:

Return type:

Optional[GatewayUser]

get_by_stanza(s)[source]#

Convenience function to get a user from a stanza they sent.

Parameters:

s (Union[slixmpp.Presence, slixmpp.Message, slixmpp.Iq]) – A stanza sent by the gateway user

Returns:

Return type:

Optional[GatewayUser]

close()[source]#
class slidge.util.db.YesSet[source]#

Bases: set

A pseudo-set which always test True for membership

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

__contains__(item)[source]#

x.__contains__(y) <==> y in x.

class slidge.util.db.RosterBackend[source]#

A pseudo-roster for the gateway component.

If a user is in the user store, this will behave as if the user is part of the roster with subscription “both”, and “none” otherwise.

This is rudimentary but the only sane way I could come up with so far.

static entries(_owner_jid, _default=None)[source]#
static save(_owner_jid, _jid, _item_state, _db_state)[source]#
static load(_owner_jid, jid, _db_state)[source]#
slidge.util.db.user_store[source]#
slidge.util.db.log[source]#