bases.alphabet
Module containing classes for alphabets.
base10
- base10 = StringAlphabet('0123456789')
Base-10 alphabet.
base16
- base16 = StringAlphabet('0123456789ABCDEF', case_sensitive=False)
Uppercase case-insensitive base-16 alphabet.
base2
- base2 = StringAlphabet('01')
Base-2 alphabet.
base32
base32hex
base32z
- base32z = StringAlphabet('ybndrfg8ejkmcpqxot1uwisza345h769', case_sensitive=False)
Lowercase case-insensitive human-oriented base-32 alphabet from https://philzimmermann.com/docs/human-oriented-base-32-encoding.txt
base36
- base36 = StringAlphabet('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', case_sensitive=False)
Uppercase case-insensitive base-36 alphabet.
base45
- base45 = StringAlphabet('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:', case_sensitive=False)
Uppercase case-insensitive base-45 alphabet from https://datatracker.ietf.org/doc/draft-faltstrom-base45/
base58btc
- base58btc = StringAlphabet('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz')
Case-sensitive base-58 alphabet used by Bitcoin.
base58flickr
- base58flickr = StringAlphabet('123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ')
Case-sensitive base-58 alphabet used by Flickr.
base58ripple
- base58ripple = StringAlphabet('rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz')
Case-sensitive base-58 alphabet used by Ripple.
base64
base64url
base8
- base8 = StringAlphabet('01234567')
Base-8 alphabet.
get
has
make
- make(chars, *, case_sensitive=True, name=None)[source]
Utility function to create custom alphabets. Automatically creates an instance of
StringAlphabet
orRangeAlphabet
based on whether a string or range is passed.Example usage with string (case-insensitive base-16):
>>> alphabet.make("0123456789ABCDEF", case_sensitive=False) StringAlphabet('0123456789ABCDEF', case_sensitive=False)
Example usage with range (extended ASCII):
>>> alphabet.make(range(0x00, 0x100)) RangeAlphabet(range(0x00, 0x100))
If the optional keyword argument
name
is specified, the alphabet is automatically registered usingregister
.- Parameters:
- Return type:
register
- register(**alphabets)[source]
Registers any number of new alphabets by name.
Example usage:
>>> from bases import alphabet >>> alphabet.register(base16lower=alphabet.base16.lower()) >>> alphabet.get("base16lower") StringAlphabet('0123456789abcdef')
Alphabet names must conform with:
re.match(r"^base[0-9][a-zA-Z0-9_]*$", name)
table
- table(*, prefix='')[source]
Iterates over all registered alphabets, optionally restricting to those with given prefix.
Example usage:
>>> from bases import alphabet >>> dict(alphabet.table(prefix="base32")) {'base32': StringAlphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', case_sensitive=False), 'base32hex': StringAlphabet('0123456789ABCDEFGHIJKLMNOPQRSTUV', case_sensitive=False), 'base32z': StringAlphabet('ybndrfg8ejkmcpqxot1uwisza345h769', case_sensitive=False)}
unregister
- unregister(*names)[source]
Unregisters any number of existing alphabets by name.
Example usage:
>>> from bases import alphabet >>> alphabet.unregister("base16", "base32") >>> alphabet.has("base16") False >>> alphabet.get("base16") KeyError: "Alphabet named 'base16' does not exist."
Note that pre-defined constants are unaffected by this:
>>> alphabet.base16 StringAlphabet('0123456789ABCDEF')