Skip to main content

The simplest way to create bit-flags

Project description

intflags

Simplest way to create bit-flags.

$ pip install intflags

Usage

Create any number of intflags by using intflags.get(). You can create a union of any amount using the pipe (|) operator.

>>> import intflags

>>> a, b, c = intflags.get(3)
>>> bin(a | b | c)
'0b111'

>>> flags = a | b
>>> a in flags
True
>>> c in flags
False

Flags can be subtracted.

# ...
>>> new_flags = flags - b
>>> b in new_flags
False
>>> new_flags == a
True

You could use classes as a pseudo-namespace.

>>> class RegexFlags:
...     I, L, M, S, U, X = intflags.get(6)

Flags share an internal "namespace" ID to prevent accidental conflicts between sets. This allows multiple sets of flags to exist within the same class or module, without risk of accidentally creating a union between them.

>>> x = intflags.get(1)
>>> y = intflags.get(1)
>>> x | y
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  ...
ValueError: Flags must share a namespace to create a union.

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

intflags-1.1.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

intflags-1.1.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file intflags-1.1.0.tar.gz.

File metadata

  • Download URL: intflags-1.1.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.3 CPython/3.8.1 Windows/10

File hashes

Hashes for intflags-1.1.0.tar.gz
Algorithm Hash digest
SHA256 3fff445aab8f2205181baf6d7c6c5dcf3c2ebf47e76defff54b9abb67c3016a6
MD5 f71bf0a27f8d4e311f7cfafe9fc9f868
BLAKE2b-256 73e2b96f318110449911c2c4c46c4db6e71ff70174a75265d4c4cdf2eacfc19c

See more details on using hashes here.

File details

Details for the file intflags-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: intflags-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.3 CPython/3.8.1 Windows/10

File hashes

Hashes for intflags-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 493c92f14ad7dcaafa141f446e37e510b2d4dee598386d74d7526be045ce6905
MD5 bcc2084a00180d2b59f31a1befccf194
BLAKE2b-256 058f3e898fa736860e064b3dbd5008d5bc3cc58db09b0520234b6761b1242bca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page