Pybankreader API

pybankreader.exceptions module

exception pybankreader.exceptions.ConfigurationError[source]

Bases: exceptions.Exception

Exception signifies a programmers error in setting up the reports

exception pybankreader.exceptions.ValidationError(field, message)[source]

Bases: exceptions.Exception

Simple exception for field-level validation errors

data = None

One line of data, if available, that a record tried to load

field = None

The field which raised the exception

interval = (0, 0)

Interval in the source data string, that the field tried to parse in the format of a tuple (start, end)

message = None

Exception message

parent = None

Optional pointer to previous ValidationError exception, as the parser progressed through the data and was trying sucessive records/fields.

record = None

The record class name, where the error occured

pybankreader.fields module

class pybankreader.fields.CharField(length, required)[source]

Bases: pybankreader.fields.Field

CharField just uses the Field superclass directly for now, nothing special

class pybankreader.fields.DecimalField(*args, **kwargs)[source]

Bases: pybankreader.fields.RegexField

Decimal is just a special-case regex, so the field is implemented this way. Mind that when you’re using decimal, the overall length of the field must count with the decimal dot!

class pybankreader.fields.Field(length, required)[source]

Bases: object

Basic field superclass. We have mandatory length and required flags, and we hold the set value (if any). Also, the name of the field as defined in classes using these for reference reasons.

field_name

Return the name of the field it has been assigned to

Return string:name of the field
length = None
required = None
value

Just return the value, nothing special here

Returns:object
class pybankreader.fields.IntegerField(*args, **kwargs)[source]

Bases: pybankreader.fields.RegexField

Integer is just a special-case regex, so the field is implemented this way

class pybankreader.fields.RegexField(regex, *args, **kwargs)[source]

Bases: pybankreader.fields.Field

Generic regex field. On top of basic checks, enforces a regex match

class pybankreader.fields.TimestampField(format, *args, **kwargs)[source]

Bases: pybankreader.fields.Field

Timestamp field takes on format parameter to be fed into strptime

pybankreader.records module

class pybankreader.records.FieldProxy(field_obj)[source]

Bases: object

A decriptor class for fields. This essentially creates a proxy to attributes. Beware of weird class-level like behavior of descriptors

class pybankreader.records.Record(initial=None)[source]

Bases: object

The base Record class. Any record definition should use this one, since it allows for the smooth definition via class attributes and adds some facade methods to load those records.

Also, it uses the same trick as Field to mainatin it’s relative position inside the Report class

load(data)[source]

Parses the data using fields and loads it inside the record. If it throws a validation error, we reload initial values back to those fields

Parameters:data (string) – Data to be loaded by the record
class pybankreader.records.RecordBase[source]

Bases: type

The record metaclass. Mainly sets up Field proxy descriptors on Field instances (class attributes)

pybankreader.reports module

class pybankreader.reports.CompoundRecord(*args)[source]

Bases: pybankreader.records.Record

A wrapper for a record field that represents a list of records and possibly of multiple types of records. This is mainly required to control the position of individual record attributes in the given report.

advance()[source]
get_record()[source]
reset()[source]
class pybankreader.reports.Report(file_like=None)[source]

Bases: object

data = None

The actual data field. All reports will have at least this one defined.

load(file_like)[source]

Read individual records and assign them to proper instance fields, as they go. When the system cannot parse a record, we advance to the next record type first, before we raise an exception indicating that the report is invalid.

class pybankreader.reports.ReportBase[source]

Bases: type

The metaclass responsible for creating hint_<record> and process_<record> fields, as well as instantiating those in correct order and mapping them onto a Report instance.

pybankreader.utils module

class pybankreader.utils.ProxyMixin(record)[source]

Bases: object

A very simple proxy class that holds an object and proxies all attribute gets to that object. No setting of attributes allowed

Module contents