FlagBase

Base class for bitwise flags.

Class Attributes

__disabler_factory__ : create_flag_disabler

Flag disabler function factory for subclasses.

__enabler_factory__ : create_flag_enabler

Flag enabler function factory for subclasses.

__getter_factory__ : create_flag_getter

Flag value getter descriptor for subclasses.

Methods

__new__()

You cannot subclass flag base classes.

is_strict_subset()

Returns whether self has more flags disabled than other.

is_strict_superset()

Returns whether self has more flags enabled than other.

is_subset()

Returns whether self has the same amount or more flags disabled than other.

is_superset()

Returns whether self has the same amount or more flags enabled than other.

items()

Yields the items of the flag.

This method is a generator.

Yields

name : str

The name of the specific flag

enabled : int(0, 1)

Whether the specific bitwise value is enabled.

keys()

Yields the name of the bitwise flags, which are enabled.

This method is a generator.

Yields

name : str

update_by_keys(...)

Updates the source value with the given flags and returns a new one.

ParameterTypeOptionalKeyword onlyDescription
**keyword_parameters

Keyword parameters

flag-name- bool relations.

Returns

flag : FlagBase

Raises

LookupError

If a keyword is invalid.

Examples

>>> from hata import Permission
>>> perm = Permission().update_by_keys(kick_users = True, ban_users = True)
>>> list(perm)
['kick_users', 'ban_users']
>>> perm = perm.update_by_keys(manage_roles = True, kick_users = False)
>>> list(perm)
['ban_users', 'manage_roles']

values()

Yields the shift values of the flags, under which shift value the flag is enabled.

This method is a generator.

Yields

shift : int

_get_shift_of(keys)

Gets the shift value for the given keys.

ParameterTypeDescription
keys

str

The key's name.

Returns

shift : int

Raises

LookupError

  • Invalid key given.

__contains__()

Returns whether the specific flag of the given name is enabled.

__disabler_factory__(name, shift, deprecation_info)

Creates a flag disabler function.

ParameterTypeDescription
name

str

The flag's name.

shift

int

Bit shift value.

deprecation_info

None, tuple(str, str)

Deprecation info for the field if deprecated.

Returns

flag_disabler : FunctionType

__enabler_factory__(name, shift, deprecation_info)

Creates a flag enabler function.

ParameterTypeDescription
name

str

The flag's name.

shift

int

Bit shift value.

deprecation_info

None, tuple(str, str)

Deprecation info for the field if deprecated.

Returns

flag_enabler : FunctionType

__ge__()

Returns whether self has the same amount or more flags enabled than other.

__getitem__()

Returns whether a specific flag of the given name is enabled.

__getter_factory__(name, shift, deprecation_info)

Creates a flag getter function.

ParameterTypeDescription
name

str

The flag's name.

shift

int

Bit shift value.

deprecation_info

None, tuple(str, str)

Deprecation info for the field if deprecated.

Returns

flag_getter : FunctionType

__gt__()

Returns whether self has more flags enabled than other.

__iter__()

Yields the name of the bitwise flags, which are enabled.

This method is a generator.

Yields

name : str

__le__()

Returns whether self has the same amount or more flags disabled than other.

__lt__()

Returns whether self has more flags disabled than other.

__repr__()

Returns the representation of the flag.