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)

Return True if the record accepts this nested record.

Parameters:

record (bytes)

Return type:

bool

class csb43.aeb43.record.CompositeRecordMixin

Implements required methods for composite bytes records.

append(raw)

Append a bytes record to the collection of dependent records.

Parameters:

raw (bytes | bytearray)

Return type:

None

class csb43.aeb43.record.FieldValue(field_id, value)

An identified field value.

Create new instance of FieldValue(field_id, value)

Parameters:
  • field_id (Any)

  • value (bytes)

field_id: Any

Alias for field number 0

value: bytes

Alias for field number 1

class csb43.aeb43.record.Record(context=None, raw=None)

An AEB43 record.

Parameters:
  • context (Aeb43Context | None)

  • raw (dataclasses.InitVar[Union[bytes, bytearray, NoneType]])

__iter__()

Iterate raw records associated to this object.

Return type:

Iterator[bytes]

from_raw(raw)

Set a new record.

Parameters:

raw (bytes | bytearray)

Return type:

list[FieldValue]

get_field(field_id)

Get raw field.

Parameters:

field_id (Any)

Return type:

bytes | bytearray

to_dict(translated=True)

Return fields as a dict of typed values.

Parameters:

translated (bool)

Return type:

dict[str, Any]

update_fields(*changes, raw=None)

Update a field identified by field_id.

Parameters:
  • changes (FieldValue)

  • raw (bytes | bytearray | None)

Return type:

bytes | bytearray | None

class csb43.aeb43.record.RecordManifest(code, sections, size=80, fix_size=True, default_factory=<function create_bytes_record>)

A record configuration.

Parameters:
  • code (bytes)

  • sections (Mapping[Any, tuple[slice, Callable[[Aeb43Context, bytes | bytearray], Tuple[str | None, str | None]] | None]])

  • size (int)

  • fix_size (bool)

  • default_factory (Callable[[RecordManifest], bytes])

create_record()

Create a default record.

Return type:

bytes | bytearray

default_factory()

factory used for making new records

Parameters:

manifest (RecordManifest)

Return type:

bytes

size_for(field_id)

Get size for a field identified by field_id.

Parameters:

field_id (Any)

Return type:

int

slice_for(field_id)

Get slice for a field idenfified by field_id.

Parameters:

field_id (Any)

Return type:

slice

validate_code(record)

Validate record code.

Parameters:

record (bytes | bytearray)

Return type:

bool

validate_size(record)

Validate record size.

Parameters:

record (bytes | bytearray)

Return type:

bool

validator_for(field_id)

Get validator for a field identified by field_id.

Parameters:

field_id (Any)

Return type:

Callable[[Aeb43Context, bytes | bytearray], Tuple[str | None, str | None]] | None

code: bytes

prefix used for this record type

fix_size: bool = True

fix size for space padded or truncated lines

sections: Mapping[Any, tuple[slice, Callable[[Aeb43Context, bytes | bytearray], Tuple[str | None, str | None]] | None]]

definition for fields

size: int = 80

record size

class csb43.aeb43.record.RegexValidator(pattern, search=False, warning=False)

Validator for matching regex patterns.

Parameters:
  • pattern (dataclasses.InitVar[bytes])

  • search (bool)

  • warning (bool)

__call__(_context, field)

Validate field.

Parameters:
  • _context (Any)

  • field (bytes | bytearray)

Return type:

tuple[str | None, str | None]

search: bool = False

use re.search insted of re.match

class csb43.aeb43.record.SingleRecordMixin

Implements required methods for a bytes record that contains no other records.

__iter__()

Yield the raw field as bytes.

Return type:

Iterator[bytes]

accepts_nested_codes(record)

Return True if the record accepts this nested record.

Parameters:

record (bytes)

Return type:

bool

csb43.aeb43.record.chain_validator(*validators)

Chained validation sequence.

Parameters:

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

Return type:

Callable[[Aeb43Context, bytes | bytearray], tuple[str | None, str | None]]

csb43.aeb43.record.create_bytes_record(manifest)

Create a default bytes record.

Parameters:

manifest (RecordManifest)

Return type:

bytes

Errors and warnings.

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

Exception raised when a field does not validate.

Parameters:
  • value (Any)

  • line (int | None)

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

Warning issued when a field does not validate.

Parameters:
  • value (Any)

  • line (int | None)

csb43.aeb43.record.errors.message_error(value, line=None)

Return a message error for a context line.

Parameters:
  • value (Any)

  • line (int | None)

Return type:

str

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

Raise an exception if strict is true, otherwise issue a warning.

Parameters:
  • value (Any)

  • strict (bool)

  • silent (bool)

  • line (int | None)

Return type:

None

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, value)

Adapt input for processing or raise an Aeb43Exception.

Parameters:
  • this (Record)

  • value (InputT)

Return type:

InputT

default_factory()

Return default factory function.

Return type:

OutputT

to_bytes(this, value)

Convert a typed field to bytes chunks.

Parameters:
  • this (Record)

  • value (InputT)

Return type:

Iterator[FieldValue]

to_field(this)

Convert bytes chunks to a typed field.

Parameters:

this (Record)

Return type:

OutputT

class csb43.aeb43.fields.FieldMixin

Chacheable descriptor field mix-in.

pop_pending_changes(this)

Pop field pending changes.

Parameters:

this (Any)

Return type:

tuple[FieldValue, …] | None

csb43.aeb43.fields.as_string(this, field_id)

Get the field identified by field_id from a record as a string.

Parameters:
  • this (Record)

  • field_id (Any)

Return type:

str

Descriptor field for Currency type representation.

class csb43.aeb43.fields.currency.Currency(field_id, factory=<function euro_currency>)

Currency code.

Parameters:
adapt(this, value)

Adapt input for processing or raise an Aeb43Exception.

Parameters:
Return type:

AnyCurrency

default_factory()

Return default factory function.

Return type:

AnyCurrency

factory()

Return euro currency.

Return type:

AnyCurrency

to_bytes(this, value)

Convert a typed field to bytes chunks.

Parameters:
Return type:

Iterator[FieldValue]

to_field(this)

Convert bytes chunks to a typed field.

Parameters:

this (Record)

Return type:

AnyCurrency

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

Return a validator for currency numeric code.

Parameters:

warning (bool)

Return type:

RegexValidator

csb43.aeb43.fields.currency.euro_currency()

Return euro currency.

Return type:

AnyCurrency

Descriptor for date fields.

class csb43.aeb43.fields.date.Date(field_id, factory=<built-in method today of type object>)

Date field.

Parameters:
  • field_id (Any)

  • factory (Callable[[], date])

classmethod factory()

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

adapt(this, value)

Adapt input for processing or raise an Aeb43Exception.

Parameters:
  • this (Record)

  • value (date | datetime)

Return type:

date

default_factory()

Return default factory function.

Return type:

date

to_bytes(this, value)

Convert a typed field to bytes chunks.

Parameters:
  • this (Record)

  • value (date | datetime)

Return type:

Iterator[FieldValue]

to_field(this)

Convert bytes chunks to a typed field.

Parameters:

this (Record)

Return type:

date

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

Return a standard date validator.

Parameters:

warning (bool)

Return type:

RegexValidator

Descriptor for AEB43 information mode fields.

class csb43.aeb43.fields.information_mode.InformationModeField(field_id, factory=<function InformationModeField.<lambda>>)

Descriptor field for information mode enum.

Parameters:
static convert_bytes(this, value)

Convert from bytes to information mode.

Parameters:
  • this (Record)

  • value (bytes | bytearray)

Return type:

InformationMode

adapt(this, value)

Adapt input for processing or raise an Aeb43Exception.

Parameters:
Return type:

int

default_factory()

Return default factory function.

Return type:

InformationMode

to_bytes(this, value)

Convert a typed field to bytes chunks.

Parameters:
Return type:

Iterator[FieldValue]

to_field(this)

Convert bytes chunks to a typed field.

Parameters:

this (Record)

Return type:

InformationMode

class csb43.aeb43.fields.information_mode.OnModeValidator(validator1, validator2, validator3)

Validator for each information mode.

Parameters:
  • 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]])

__call__(context, field)

Validate a record.

Parameters:
Return type:

tuple[str | None, str | None]

Descriptors for representing int fields.

class csb43.aeb43.fields.integer.Integer(field_id, factory=<class 'int'>)

Integer field.

Parameters:
  • field_id (Any)

  • factory (Callable[[], int])

factory

alias of int

adapt(this, value)

Adapt input for processing or raise an Aeb43Exception.

Parameters:
Return type:

int

default_factory()

Return default factory function.

Return type:

int

to_bytes(this, value)

Convert a typed field to bytes chunks.

Parameters:
Return type:

Iterator[FieldValue]

to_field(this)

Convert bytes chunks to a typed field.

Parameters:

this (Record)

Return type:

int

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

Validator for integer fields.

Parameters:
  • size (int)

  • min_value (int | None)

  • max_value (int | None)

  • warning (bool)

__call__(_context, field)

Validate field.

Parameters:
  • _context (Any)

  • field (bytes | bytearray)

Return type:

tuple[str | None, str | None]

max_value: int | None = None

maximum allowed value

min_value: int | None = None

minimum allowed value

size: int

number of digits (base 10)

warning: bool = False

emit warning if validation fails instead of auto

Descriptors for money amount fields.

class csb43.aeb43.fields.money.Money(value_id, mode_id=None, default_mode=b'2', padding=b'0', non_negative=False, factory=<class 'decimal.Decimal'>)

Money field.

Parameters:
  • value_id (Any)

  • mode_id (Any | None)

  • default_mode (bytes)

  • padding (bytes)

  • non_negative (bool)

  • factory (Callable[[], Decimal])

factory

alias of Decimal

adapt(this, value)

Adapt input for processing or raise an Aeb43Exception.

Parameters:
  • this (Record)

  • value (Decimal | int)

Return type:

Decimal

default_factory()

Return default factory function.

Return type:

Decimal

to_bytes(this, value)

Convert a typed field to bytes chunks.

Parameters:
  • this (Record)

  • value (Decimal | int)

Return type:

Iterator[FieldValue]

to_field(this)

Convert bytes chunks to a typed field.

Parameters:

this (Record)

Return type:

Decimal

csb43.aeb43.fields.money.check_precision_loss(record, value)

Check that there are no precision loss.

The number of decimals than must be a supported quantity by the fixed-point representation.

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

Parameters:
  • record (Record)

  • value (Decimal | int)

Return type:

Decimal

csb43.aeb43.fields.money.float2decimal(record, value)

Get a scaled decimal from a float value using a limited number of decimals.

Parameters:
  • record (Record)

  • value (float)

Return type:

Decimal

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

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

Parameters:

warning (bool)

Return type:

RegexValidator

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

Return a validator for money amounts.

Parameters:
  • size (int)

  • warning (bool)

Return type:

RegexValidator

Descriptors for storing nested records.

class csb43.aeb43.fields.nested.NestedCollection(default_factory)

Field for storing record collections.

Parameters:

default_factory (Callable[[Contextual, Iterable[AnyRecord | bytes | bytearray]], RecordCollection[AnyRecord]])

class csb43.aeb43.fields.nested.NestedContextual(record_type, optional=False)

Nested record descriptor.

Parameters:
  • record_type (Type[ContextualT])

  • optional (bool)

class csb43.aeb43.fields.nested.NestedRecord(record_type, optional=False)

A nested record descriptor.

Parameters:
  • record_type (Type[ContextualT])

  • optional (bool)

class csb43.aeb43.fields.nested.RecordCollection(context_f, record_type, _data=<factory>, initial_data=None)

Collection of record objects.

Parameters:
  • context_f (Callable[[], Aeb43Context | None])

  • record_type (Type[AnyRecord])

  • _data (list[AnyRecord])

  • initial_data (dataclasses.InitVar[Iterable[Union[~AnyRecord, bytes, bytearray]]])

__getitem__(index: int) AnyRecord
__getitem__(index: slice) Sequence[AnyRecord]

Get the index-th nested item.

Parameters:

index (int | slice)

Return type:

AnyRecord | Sequence[AnyRecord]

__iter__()

Iterate nested items.

Return type:

Iterator[AnyRecord]

__len__()

Return the number of nested items.

Return type:

int

__reversed__()

Reverse the nested items.

Return type:

Iterator[AnyRecord]

append(item)

Append record to this collection.

Parameters:

item (AnyRecord | bytes | bytearray)

Return type:

None

clear()

Clear items in collection.

Return type:

None

index(value, start=0, stop=None)

Return a subset of the nested items.

Parameters:
  • value (AnyRecord)

  • start (SupportsIndex)

  • stop (SupportsIndex | None)

Return type:

int

csb43.aeb43.fields.nested.convert_record(record_type, context, value)

Convert value to a record_type object with a compatible context.

Parameters:
  • record_type (Type[AnyRecord])

  • context (Aeb43Context | None)

  • value (AnyRecord | bytes | bytearray)

Return type:

AnyRecord

Descriptor for string fields.

class csb43.aeb43.fields.string.String(field_id, padding=b' ', trim=<Trim.BOTH: 15>, align_left=True, mode=<factory>, factory=<class 'str'>)

String field.

Parameters:
factory

alias of str

adapt(this, value)

Adapt input for processing or raise an Aeb43Exception.

Parameters:
Return type:

str

default_factory()

Return default factory function.

Return type:

str

get_align_left(this)

Trim_left for the current information mode.

Parameters:

this (Record)

Return type:

bool

get_padding(this)

Get the padding for the current information mode.

Parameters:

this (Record)

Return type:

bytes

get_trim(this)

Trimmed for the current information mode.

Parameters:

this (Record)

Return type:

Trim

pad(this, record)

Pad a record.

Parameters:
  • this (Record)

  • record (bytes)

Return type:

FieldValue

to_bytes(this, value)

Convert a typed field to bytes chunks.

Parameters:
Return type:

Iterator[FieldValue]

to_field(this)

Convert bytes chunks to a typed field.

Parameters:

this (Record)

Return type:

str

align_left: bool = True

right)

Type:

align value at the left of the field (default

padding: bytes = b' '

padding character used in the raw field

trim: Trim = 15

trim padding characters before returning the string value

class csb43.aeb43.fields.string.Trim(*values)

Trim mode.

apply(value: bytes | bytearray, padding: bytes | bytearray) bytes | bytearray
apply(value: str, padding: str) str

Apply a padding.

Parameters:
  • value (bytes | bytearray | str)

  • padding (bytes | bytearray | str)

Return type:

bytes | bytearray | str

class csb43.aeb43.fields.string.TrimInfo

Trim definition for a field.

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

Return a validator for strings with printable characters.

Parameters:
  • size (int)

  • warning (bool)

Return type:

Callable[[Aeb43Context, bytes | bytearray], Tuple[str | None, str | None]]