slidge.util#

Submodules#

Package Contents#

Classes#

ABCSubclassableOnceAtMost

Metaclass for defining Abstract Base Classes (ABCs).

BiDict

Abstract base class for generic types.

FormField

Represents a field of the form that a user will see when registering to the gateway

SearchResult

SubclassableOnce

Functions#

class slidge.util.ABCSubclassableOnceAtMost(name, bases, dct)[source]#

Bases: abc.ABCMeta, SubclassableOnce

Metaclass for defining Abstract Base Classes (ABCs).

Use this metaclass to create an ABC. An ABC can be subclassed directly, and then acts as a mix-in class. You can also register unrelated concrete classes (even built-in classes) and unrelated ABCs as ‘virtual subclasses’ – these and their descendants will be considered subclasses of the registering ABC by the built-in issubclass() function, but the registering ABC won’t show up in their MRO (Method Resolution Order) nor will method implementations defined by the registering ABC be callable (not even via super()).

class slidge.util.BiDict(*args, **kwargs)[source]#

Bases: Generic[KeyType, ValueType], dict

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:

class Mapping(Generic[KT, VT]):
    def __getitem__(self, key: KT) -> VT:
        ...
    # Etc.

This class can then be used as follows:

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
    try:
        return mapping[key]
    except KeyError:
        return default

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

__setitem__(key, value)#

Set self[key] to value.

Parameters
  • key (KeyType) –

  • value (ValueType) –

class slidge.util.FormField[source]#

Represents a field of the form that a user will see when registering to the gateway via their XMPP client.

var :str =#

Internal name of the field, will be used to retrieve via slidge.GatewayUser.registration_form

label :Optional[str]#

Description of the field that the aspiring user will see

required :bool = False#

Whether this field is mandatory or not

private :bool = False#

For sensitive info that should not be displayed on screen while the user types. Forces field_type to “text-private”

type :field_type = text-single#

Type of the field, see XEP-0004

value :str =#

Pre-filled value. Will be automatically pre-filled if a registered user modifies their subscription

options :Optional[list[dict[str, str]]]#
dict()#
__post_init__()#
class slidge.util.SearchResult[source]#
fields :Iterable[FormField]#
items :Iterable[dict[str, str]]#
class slidge.util.SubclassableOnce(name, bases, dct)[source]#

Bases: type

TEST_MODE = False#
get_self_or_unique_subclass()#
get_unique_subclass()#
reset_subclass()#
slidge.util.is_valid_phone_number(phone)[source]#
Parameters

phone (Optional[str]) –