csb43.record

Base tools for building bytes chars records

class csb43.aeb43.record.BytesMixin

implements required methods for a bytes record

accepts_nested_codes(record: bytes) bool

return True if the record accepts this nested record

class csb43.aeb43.record.CompositeRecordMixin

implements required methods for composite bytes records

append(raw: bytes | bytearray)

append a bytes record to the collection of dependent records

class csb43.aeb43.record.FieldValue(field_id: Any, value: bytes)

an identified field value

field_id: Any

Alias for field number 0

value: bytes

Alias for field number 1

class csb43.aeb43.record.Record(context: Aeb43Context | None = None, raw: dataclasses.InitVar[AnyBytes | None] = None)

an AEB43 record

from_raw(raw: bytes | bytearray) list[FieldValue]

set a new record

get_field(field_id) bytes | bytearray

get raw field

to_dict(translated=True) dict[str, Any]

return fields as a dict of typed values

update_fields(*changes: FieldValue, raw: bytes | bytearray | None = None) bytes | bytearray | None

update a field identified by field_id

class csb43.aeb43.record.RecordManifest(code: bytes, sections: ~typing.Mapping[~typing.Any, tuple[slice, ~typing.Callable[[~csb43.aeb43.record.context.Aeb43Context, bytes | bytearray], ~typing.Tuple[str | None, str | None]] | None]], size: int = 80, fix_size: bool = True, default_factory: ~typing.Callable[[~csb43.aeb43.record.RecordManifest], bytes] = <function create_bytes_record>)

a record configuration

code - prefix used for this record type sections - definition for fields size - record size fix_size - fix size for space padded or truncated lines default_factory - factory used for making new records

create_record() bytes | bytearray

create a default record

default_factory() bytes

create a default bytes record

size_for(field_id) int

get size for a field identified by field_id

slice_for(field_id) slice

get slice for a field idenfified by field_id

validate_code(record: bytes | bytearray) bool

validate record code

validate_size(record: bytes | bytearray) bool

validate record size

validator_for(field_id) Callable[[Aeb43Context, bytes | bytearray], Tuple[str | None, str | None]] | None

get validator for a field identified by field_id

class csb43.aeb43.record.RegexValidator(pattern: dataclasses.InitVar[AnyStr], search: bool = False, warning: bool = False)

Validator for matching regex patterns

class csb43.aeb43.record.SingleRecordMixin

implements required methods for a bytes record that contains no other records

accepts_nested_codes(record: bytes) bool

return True if the record accepts this nested record

csb43.aeb43.record.chain_validator(*validators: Callable[[Aeb43Context, bytes | bytearray], Tuple[str | None, str | None]]) Callable[[Aeb43Context, Any], tuple[str | None, str | None]]

chained validation sequence

csb43.aeb43.record.create_bytes_record(manifest: RecordManifest) bytes

create a default bytes record

errors and warnings

exception csb43.aeb43.record.errors.ValidationException(value, line: int | None = None)

exception raised when a field does not validate

exception csb43.aeb43.record.errors.ValidationWarning(value, line: int | None = None)

warning issued when a field does not validate

csb43.aeb43.record.errors.message_error(value, line: int | None = None) str

a message error for a context line

csb43.aeb43.record.errors.raise_validation_exception(value, strict=False, silent=False, line: int | None = None)

raise an exception if strict is true, otherwise issue a warning

csb43.fields

Base tools for building descriptors fields for representing typed values and storing in bytes

class csb43.aeb43.fields.Field

a typed representation for a field

adapt(this: Record, value: InputT) InputT

adapt input for processing or raise an Aeb43Exception

default_factory() OutputT

return default factory function

to_bytes(this: Record, value: InputT) Iterator[FieldValue]

convert a typed field to bytes chunks

to_field(this: Record) OutputT

convert bytes chunks to a typed field

class csb43.aeb43.fields.FieldMixin

Chacheable descriptor field mix-in

pop_pending_changes(this) tuple[FieldValue, ...] | None

pop field pending changes

csb43.aeb43.fields.as_string(this: Record, field_id) str

get the field identified by field_id from a record as a string

Descriptor field for Currency type representation

class csb43.aeb43.fields.currency.Currency(field_id: ~typing.Any, factory: ~typing.Callable[[], ~csb43.utils.currency.AnyCurrency] = <function euro_currency>)

currency code

adapt(this: Record, value: str | Number | AnyCurrency) AnyCurrency

adapt input for processing or raise an Aeb43Exception

default_factory() AnyCurrency

return default factory function

factory()

return euro currency

to_bytes(this: Record, value: str | Number | AnyCurrency) Iterator[FieldValue]

convert a typed field to bytes chunks

to_field(this: Record) AnyCurrency

convert bytes chunks to a typed field

csb43.aeb43.fields.currency.currency_validator(warning=False) RegexValidator

validator for currency numeric code

csb43.aeb43.fields.currency.euro_currency()

return euro currency

Descriptor for date fields

class csb43.aeb43.fields.date.Date(field_id: ~typing.Any, factory: ~typing.Callable[[], ~datetime.date] = <built-in method today of type object>)

date field

adapt(this: Record, value: date | datetime) date

adapt input for processing or raise an Aeb43Exception

default_factory() date

return default factory function

factory()

Current date or datetime: same as self.__class__.fromtimestamp(time.time()).

to_bytes(this: Record, value: date | datetime) Iterator[FieldValue]

convert a typed field to bytes chunks

to_field(this: Record) date

convert bytes chunks to a typed field

csb43.aeb43.fields.date.date_validator(warning=False) RegexValidator

a standard date validator

Descriptor for AEB43 information mode fields

class csb43.aeb43.fields.information_mode.InformationModeField(field_id: ~typing.Any, factory: ~typing.Callable[[], ~csb43.aeb43.record.context.InformationMode] = <function InformationModeField.<lambda>>)

descriptor field for information mode enum

adapt(this: Record, value: InformationMode | int)

adapt input for processing or raise an Aeb43Exception

static convert_bytes(this: Record, value: bytes) InformationMode

convert from bytes to information mode

default_factory() InformationMode

return default factory function

to_bytes(this: Record, value: InformationMode | int) Iterator[FieldValue]

convert a typed field to bytes chunks

to_field(this: Record) InformationMode

convert bytes chunks to a typed field

class csb43.aeb43.fields.information_mode.OnModeValidator(validator1: Callable[[Aeb43Context, bytes | bytearray], Tuple[str | None, str | None]], validator2: Callable[[Aeb43Context, bytes | bytearray], Tuple[str | None, str | None]], validator3: Callable[[Aeb43Context, bytes | bytearray], Tuple[str | None, str | None]])

validator for each information mode

Descriptors for representing int fields

class csb43.aeb43.fields.integer.Integer(field_id: ~typing.Any, factory: ~typing.Callable[[], int] = <class 'int'>)

integer field

adapt(this: Record, value: int) int

adapt input for processing or raise an Aeb43Exception

default_factory() int

return default factory function

factory

alias of int

to_bytes(this: Record, value: int) Iterator[FieldValue]

convert a typed field to bytes chunks

to_field(this: Record) int

convert bytes chunks to a typed field

class csb43.aeb43.fields.integer.IntegerValidator(size: int, min_value: int | None = None, max_value: int | None = None, warning: bool = False)

Validator for integer fields

Attributes:
size

number of digits (base 10)

min_value

minimum allowed value

max_value

maximum allowed value

warning

emit warning if validation fails instead of auto

Descriptors for money amount fields

class csb43.aeb43.fields.money.Money(value_id: ~typing.Any, mode_id: ~typing.Any | None = None, default_mode: bytes = b'2', padding: bytes = b'0', non_negative: bool = False, factory: ~typing.Callable[[], ~decimal.Decimal] = <class 'decimal.Decimal'>)

money field

adapt(this: Record, value: Decimal | int) Decimal

adapt input for processing or raise an Aeb43Exception

default_factory() Decimal

return default factory function

factory

alias of Decimal

to_bytes(this: Record, value: Decimal | int) Iterator[FieldValue]

convert a typed field to bytes chunks

to_field(this: Record) Decimal

convert bytes chunks to a typed field

csb43.aeb43.fields.money.check_precision_loss(record: Record, value: Decimal | int) Decimal

check if there are more decimals than the supported quantity by the fixed-point representation

Raise a ValidationError/ValidationWarning and return a rounded value to the maximum number of decimals

csb43.aeb43.fields.money.float2decimal(record: Record, value: float) Decimal

get a scaled decimal from a float value using a limited number of decimals

csb43.aeb43.fields.money.money_mode_validator(warning=False) RegexValidator

a validator for money amount mode (debit or credit code)

csb43.aeb43.fields.money.money_validator(size: int = 14, warning=False) RegexValidator

a validator for money amounts

Descriptors for storing nested records

class csb43.aeb43.fields.nested.NestedCollection(default_factory: Callable[[Contextual, Iterable[AnyRecord | bytes | bytearray]], RecordCollection])

field for storing record collections

class csb43.aeb43.fields.nested.NestedContextual(record_type: Type[ContextualT], optional: bool = False)

nested record descriptor

class csb43.aeb43.fields.nested.NestedRecord(record_type: Type[ContextualT], optional: bool = False)

a nested record descriptor

class csb43.aeb43.fields.nested.RecordCollection(context_f: Callable[[], Aeb43Context | None], record_type: Type[AnyRecord], _data: list[AnyRecord] = <factory>, initial_data: dataclasses.InitVar[Iterable[AnyRecord | AnyBytes]] = None)

collection of record objects

append(item: AnyRecord | bytes | bytearray)

append record to this collection

clear()

clear items in collection

index(value[, start[, stop]]) integer -- return first index of value.

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

csb43.aeb43.fields.nested.convert_record(record_type: Type[AnyRecord], context: Aeb43Context | None, value: AnyRecord | bytes | bytearray) AnyRecord

convert value to a record_type object with a compatible context

Descriptor for string fields

class csb43.aeb43.fields.string.String(field_id: ~typing.Any, padding: bytes = b' ', trim: ~csb43.aeb43.fields.string.Trim = <Trim.BOTH: 15>, align_left: bool = True, mode: ~typing.Mapping[~csb43.aeb43.record.context.InformationMode, ~typing.Mapping[str, ~typing.Any]] = <factory>, factory: ~typing.Callable[[], str] = <class 'str'>)

string field

adapt(this: Record, value: str) str

adapt input for processing or raise an Aeb43Exception

default_factory() str

return default factory function

factory

alias of str

get_align_left(this: Record) bool

trim_left for the current information mode

get_padding(this: Record) bytes

padding for the current information mode

get_trim(this: Record) Trim

trimmed for the current information mode

pad(this: Record, record: bytes) FieldValue

pad a record

to_bytes(this: Record, value: str) Iterator[FieldValue]

convert a typed field to bytes chunks

to_field(this: Record) str

convert bytes chunks to a typed field

class csb43.aeb43.fields.string.Trim(value)

trim mode

csb43.aeb43.fields.string.string_validator(size: int, warning=False) RegexValidator

a validator for strings with printable characters