character_range.maps¶
Implementation of IndexMap,
CharacterMap and ByteMap.
- class IndexMap(intervals: Iterable[Interval[_Char]], lookup_char: Callable[[_Char], int] | None = None, lookup_index: Callable[[int], _Char] | None = None)[source]¶
A two-way mapping between character or byte to its corresponding index.
Methods
- __getitem__(item: _Char) int[source]¶
- __getitem__(item: int) _Char
Either look for the character/index in the underlying maps, or delegate that task to the look-up functions given.
Results are cached.
- Raises:
ValueError – If
itemis neither a character/byte nor an index.IndexError – If
lookup_char
Properties
- property element_type: type[_Char]¶
The type of the map’s elements.
- class CharacterMap(intervals: Iterable[Interval[_Char]], lookup_char: Callable[[_Char], int] | None = None, lookup_index: Callable[[int], _Char] | None = None)[source]¶
- ASCII_LOWERCASE: ClassVar[CharacterMap] = CharacterMap(a-z)¶
- ASCII_UPPERCASE: ClassVar[CharacterMap] = CharacterMap(A-Z)¶
- ASCII_LETTERS: ClassVar[CharacterMap] = CharacterMap(a-zA-Z)¶
- ASCII_DIGITS: ClassVar[CharacterMap] = CharacterMap(0-9)¶
- LOWERCASE_HEX_DIGITS: ClassVar[CharacterMap] = CharacterMap(0-9a-f)¶
- UPPERCASE_HEX_DIGITS: ClassVar[CharacterMap] = CharacterMap(0-9A-F)¶
- LOWERCASE_BASE_36: ClassVar[CharacterMap] = CharacterMap(0-9a-z)¶
- UPPERCASE_BASE_36: ClassVar[CharacterMap] = CharacterMap(0-9A-Z)¶
- ASCII: ClassVar[CharacterMap] = CharacterMap(\x00-\xFF)¶
- NON_ASCII: ClassVar[CharacterMap] = CharacterMap(\u0100-\U0010FFFF)¶
- UNICODE: ClassVar[CharacterMap] = CharacterMap(\x00-\U0010FFFF)¶
- class ByteMap(intervals: Iterable[Interval[_Char]], lookup_char: Callable[[_Char], int] | None = None, lookup_index: Callable[[int], _Char] | None = None)[source]¶
- exception NoIntervals[source]¶
Bases:
ValueErrorRaised when no intervals are passed to the map constructor.
- exception OverlappingIntervals[source]¶
Bases:
ValueErrorRaised when there are at least two overlapping intervals in the list of intervals passed to the map constructor.
- exception ConfigurationConflict[source]¶
Bases:
ValueErrorRaised when the map constructor is passed:
A list of intervals whose elements don’t have the same type.
Only one lookup function but not the other.