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 gateway user

UserStore

Basic user store implementation using shelve from the python standard library

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

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:
get(key, default=None)#

D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.

pop(key, default=__marker)#

D.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised.

popitem()#

D.popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple; but raise KeyError if D is empty.

clear()#

D.clear() -> None. Remove all items from D.

update(other=(), /, **kwds)#

D.update([E, ]**F) -> None. Update D from mapping/iterable E and F. If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

setdefault(key, default=None)#

D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D

keys()#

D.keys() -> a set-like object providing a view on D’s keys

items()#

D.items() -> a set-like object providing a view on D’s items

values()#

D.values() -> an object providing a view on D’s values

class slidge.util.db.GatewayUser#

A gateway user

property jid: slixmpp.JID#

The user’s (bare) JID

Returns:

Return type:

slixmpp.JID

bare_jid: str#

Bare JID of the user

registration_form: dict[str, str | None]#

Content of the registration form, as a dict

class slidge.util.db.UserStore#

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)#

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()#

Get all users in the store

Returns:

An iterable of GatewayUsers

Return type:

Iterable[GatewayUser]

add(jid, registration_form)#

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)

get(_gateway_jid, _node, ifrom, iq)#

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)#

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)#

Remove a user from the store, by JID

Parameters:

jid (slixmpp.JID) –

get_by_jid(jid)#

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)#

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]