A wrapper for easily making bitwise flags.
Project description
A small no-requirements package for making bitwise flags in Python.
Installing
Available on PyPi:
pip install -U vf-flags
To install off of Github you can do the following
pip install -U git+https://github.com/Voxel-Fox-Ltd/Flags
Quick Example
Here’s a basic example of creating a flags class using decorators.
import vfflags
class WebsitePermissions(vfflags.Flags):
@vfflags.flag_value
def view_posts(self):
"""If the user can view posts."""
return 0b001
@vfflags.flag_value
def edit_posts(self):
"""If the user can edit posts."""
return 0b010
@vfflags.flag_value
def delete_posts(self):
return 0b100
Here’s an alternative way to create a flags class using a class attribute.
import vfflags
class WebsitePermissions(vfflags.Flags):
# You can optionally add a docstring by adding your value to a tuple
CREATE_FLAGS = {
"view_posts": (0b001, "If the user can view posts."),
"edit_posts": (0b010, "If the user can edit posts."),
"delete_posts": 0b100,
}
Here’s the usage of either of the above.
perms1 = WebsitePermissions(0b011) # Init with a value
perms1.view_posts # True
perms1.delete_posts # False
perms2 = WebsitePermissions(delete_posts=True) # Init with kwargs
perms2.view_posts # False
perms2.delete_posts # True
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vf-flags-0.2.2.tar.gz.
File metadata
- Download URL: vf-flags-0.2.2.tar.gz
- Upload date:
- Size: 39.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
263d3797542f4e94ec9b4479bf79a3aacaa0bee069beb56aa968b9e41fdf695d
|
|
| MD5 |
e8b294611a738f89eddc8e3e14ea0a60
|
|
| BLAKE2b-256 |
651a751335d7f22da5fcf6803ebb4b12d704aec9f39ad2b2f0127d7f900fb3d9
|
File details
Details for the file vf_flags-0.2.2-py3-none-any.whl.
File metadata
- Download URL: vf_flags-0.2.2-py3-none-any.whl
- Upload date:
- Size: 27.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74e35d7c1807105329b04841b459d5e87008586ab25728750d4715c91ed0e10b
|
|
| MD5 |
891868cb8aef36877c07fcc0226cf42c
|
|
| BLAKE2b-256 |
dac06bf463bf29a90ddf491a9d33713378b20d183cb1378e6582b3c365cf18e1
|