def pack(cls, **kwargs):
"""Pack a bitmask from explicit bit values.
Parameters
----------
kwargs
The names of the fields and their status. Any fields not explicitly
passed will be set to False.
Returns
-------
bitmask : int
The packed bitmask.
"""
members = cls.__members__
try:
return reduce(
op.and_,
(members[k] * bool(v) for k, v in kwargs.items()),
)
except KeyError as e:
raise TypeError('{e} is not a member of {cls.__qualname__}')
评论列表
文章目录