Encoding¶
These are helpers used to encode/decode encoded strings to something else like bytes.
Base classes¶
- aiostem.utils.encoding.T = TypeVar(T, bound=bytes | int)¶
Invariant
TypeVarbound totyping.Union[bytes,int].Generic type used for our encoders.
- class aiostem.utils.encoding.EncoderProtocol[source]¶
-
Protocol for encoding from and decoding data to another type.
- class aiostem.utils.encoding.EncodedBase[source]¶
-
Generic encoded value to/from a string using the
EncoderProtocol.-
CORE_SCHEMA:
ClassVar[InvalidSchema|AnySchema|NoneSchema|BoolSchema|IntSchema|FloatSchema|DecimalSchema|StringSchema|BytesSchema|DateSchema|TimeSchema|DatetimeSchema|TimedeltaSchema|LiteralSchema|MissingSentinelSchema|EnumSchema|IsInstanceSchema|IsSubclassSchema|CallableSchema|ListSchema|TupleSchema|SetSchema|FrozenSetSchema|GeneratorSchema|DictSchema|AfterValidatorFunctionSchema|BeforeValidatorFunctionSchema|WrapValidatorFunctionSchema|PlainValidatorFunctionSchema|WithDefaultSchema|NullableSchema|UnionSchema|TaggedUnionSchema|ChainSchema|LaxOrStrictSchema|JsonOrPythonSchema|TypedDictSchema|ModelFieldsSchema|ModelSchema|DataclassArgsSchema|DataclassSchema|ArgumentsSchema|ArgumentsV3Schema|CallSchema|CustomErrorSchema|JsonSchema|UrlSchema|MultiHostUrlSchema|DefinitionsSchema|DefinitionReferenceSchema|UuidSchema|ComplexSchema]¶ Main core validation schema.
-
CORE_SCHEMA:
Byte encoders¶
- class aiostem.utils.encoding.EncodedBytes[source]¶
Bases:
EncodedBase[bytes]Bytes that can be encoded and decoded from a string using an external encoder.
-
CORE_SCHEMA:
ClassVar[InvalidSchema|AnySchema|NoneSchema|BoolSchema|IntSchema|FloatSchema|DecimalSchema|StringSchema|BytesSchema|DateSchema|TimeSchema|DatetimeSchema|TimedeltaSchema|LiteralSchema|MissingSentinelSchema|EnumSchema|IsInstanceSchema|IsSubclassSchema|CallableSchema|ListSchema|TupleSchema|SetSchema|FrozenSetSchema|GeneratorSchema|DictSchema|AfterValidatorFunctionSchema|BeforeValidatorFunctionSchema|WrapValidatorFunctionSchema|PlainValidatorFunctionSchema|WithDefaultSchema|NullableSchema|UnionSchema|TaggedUnionSchema|ChainSchema|LaxOrStrictSchema|JsonOrPythonSchema|TypedDictSchema|ModelFieldsSchema|ModelSchema|DataclassArgsSchema|DataclassSchema|ArgumentsSchema|ArgumentsV3Schema|CallSchema|CustomErrorSchema|JsonSchema|UrlSchema|MultiHostUrlSchema|DefinitionsSchema|DefinitionReferenceSchema|UuidSchema|ComplexSchema] = {'strict': True, 'type': 'bytes'}¶ Our core schema is for
bytes.
-
CORE_SCHEMA:
- class aiostem.utils.encoding.Base16Encoder[source]¶
Bases:
EncoderProtocol[bytes]Specific encoder for hex encoded strings.
- classmethod decode(data: str) bytes[source]¶
Decode the provided hex string to original bytes data.
- Parameters:
data (
str) – A hex-encoded string to decode.- Raises:
PydanticCustomError – On decoding error.
- Returns:
bytes– The corresponding decoded bytes.
- class aiostem.utils.encoding.Base32Encoder[source]¶
Bases:
EncoderProtocol[bytes]Encoder for base32 bytes.
- classmethod decode(data: str) bytes[source]¶
Decode the provided base32 bytes to original bytes data.
- Parameters:
data (
str) – A base32-encoded string to decode.- Raises:
PydanticCustomError – On decoding error.
- Returns:
bytes– The corresponding decoded bytes.
- class aiostem.utils.encoding.Base64Encoder[source]¶
Bases:
EncoderProtocol[bytes]Encoder for base64 bytes.
- classmethod decode(data: str) bytes[source]¶
Decode the provided base64 bytes to original bytes data.
- Parameters:
data (
str) – A base64-encoded string to decode.- Raises:
PydanticCustomError – On decoding error.
- Returns:
bytes– The corresponding decoded bytes.