bases.alphabet.range_alphabet

Alphabets implicitly specified by Unicode codepoint range.

RangeAlphabet

class RangeAlphabet(codepoints, *, case_sensitive=True)[source]

Bases: Alphabet

Class for alphabets implicitly specified by a range of Unicode codepoints and optional case sensitivity (default: case-sensitive).

Example usage:

>>> from bases.alphabet import RangeAlphabet
>>> RangeAlphabet(range(0x00, 0x100))
RangeAlphabet(range(0x0, 0x100))
Parameters:
  • codepoints (range) – a range of unicode codepoints for the alphabet

  • case_sensitive (bool, optional) – whether the alphabet is case-sensitive

Raises:
  • ValueError – if the range is shorter than 2 integers

  • ValueError – if the alphabet is case-insensitive and it contains both uppercase and lowercase versions of the same character

as_string_alphabet()[source]

Converts this alphabet into a string alphabet explicitly defined by the string containing all characters in the codepoint range.

Example usage:

>>> RangeAlphabet(range(0x20, 0x7E)).as_string_alphabet()
StringAlphabet(' !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMN
                OPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}')
Return type:

StringAlphabet

property codepoints

The codepoint range that defines this alphabet.

Example usage:

>>> RangeAlphabet(range(0x00, 0x100)).codepoints
range(0, 256)
Return type:

range

lower()[source]

Returns a new alphabet with all cased characters turned to lowercase.

Example usage:

>>> alphabet.base16
StringAlphabet('0123456789ABCDEF')
>>> alphabet.base16.lower()
StringAlphabet('0123456789abcdef')
Return type:

StringAlphabet

property revdir

Reverse directory for the alphabet, mapping characters to their index.

Example usage:

>>> alphabet.base16.revdir
mappingproxy({'0': 0, '1': 1, '2': 2, '3': 3, '4': 4,
              '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
              'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15})

For case-insensitive alphabets, this contains both cases of any cased characters:

>>> alphabet.base16.with_case_sensitivity(False).revdir
mappingproxy({'0': 0, '1': 1, '2': 2, '3': 3, '4': 4,
              '5': 5, '6': 6, '7': 7,'8': 8, '9': 9,
              'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15,
              'a': 10, 'b': 11, 'c': 12, 'd': 13, 'e': 14, 'f': 15})
Return type:

Mapping[str, int]

upper()[source]

Returns a new alphabet with all cased characters turned to uppercase.

Example usage:

>>> alphabet.base32z
StringAlphabet('ybndrfg8ejkmcpqxot1uwisza345h769',
               case_sensitive=False)
>>> alphabet.base32z.upper()
StringAlphabet('YBNDRFG8EJKMCPQXOT1UWISZA345H769',
               case_sensitive=False)
Return type:

StringAlphabet

with_case_sensitivity(case_sensitive)[source]

Returns a new alphabet with the same characters as this one but with specified case sensitivity.

Example usage:

>>> alphabet.base32
StringAlphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
               case_sensitive=False)
>>> alphabet.base32.with_case_sensitivity(True)
StringAlphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567')
Parameters:

case_sensitive (bool, optional) – whether the new alphabet is case-sensitive

Return type:

RangeAlphabet