bases.encoding.simple
Simple base encodings.
Encoding of a bytestring b
:
if
b
contains any leading zero bytes, raisesEncodingError
converts
b
to an unsigned integeri
(big-endian)converts
i
to the encoding base, using the encoding alphabet for digits
Decoding of a string s
:
if
s
contains any leading zero characters, raisesDecodingError
converts
s
to an unsigned integeri
, using the encoding alphabet for digits of the encoding baseconverts
i
to its minimal byte representation (big-endian)
SimpleBaseEncoding
- class SimpleBaseEncoding(alphabet, *, case_sensitive=None)[source]
Bases:
BaseEncoding
Simple base encodings.
- Parameters:
- canonical_bytes(b)[source]
Returns a canonical version of the bytestring
b
: this is the bytestring obtained by first encodingb
and then decoding it.(This method is overridden by subclasses with more efficient implementations.)
- Parameters:
b (
BytesLike
) – the bytestring- Return type:
- canonical_string(s)[source]
Returns a canonical version of the string
s
: this is the string obtained by first decodings
and then encoding it.(This method is overridden by subclasses with more efficient implementations.)