slidge.util.util#

Module Contents#

Classes#

BiDict

Abstract base class for generic types.

SubclassableOnce

ABCSubclassableOnceAtMost

Metaclass for defining Abstract Base Classes (ABCs).

Functions#

fix_suffix(path, mime_type, file_name)

is_valid_phone_number(phone)

Attributes#

slidge.util.util.magic[source]#
slidge.util.util.fix_suffix(path, mime_type, file_name)[source]#
Parameters:
slidge.util.util.KeyType[source]#
slidge.util.util.ValueType[source]#
class slidge.util.util.BiDict(*args, **kwargs)[source]#

Bases: Generic[KeyType, ValueType], dict[KeyType, ValueType]

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)[source]#

Set self[key] to value.

Parameters:
  • key (KeyType) –

  • value (ValueType) –

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

Bases: type

TEST_MODE = False[source]#
get_self_or_unique_subclass()[source]#
get_unique_subclass()[source]#
reset_subclass()[source]#
class slidge.util.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()).

slidge.util.util.is_valid_phone_number(phone)[source]#
Parameters:

phone (Optional[str]) –

slidge.util.util.log[source]#