pidibble.baserecord module

class pidibble.baserecord.BaseRecord(input_dict)[source]

Bases: object

A class representing a base record with fields and methods for parsing and displaying.

empty()[source]

Check if the record is empty, meaning all fields are empty strings.

Returns:

True if all fields are empty strings, False otherwise.

Return type:

bool

pstr(excludes=['key', 'format', 'continuation'], pad=20)[source]

Generate a formatted string representation of the BaseRecord instance, excluding specified keys.

Parameters:
  • excludes (list, optional) – A list of keys to exclude from the output (default is [‘key’, ‘format’, ‘continuation’]).

  • pad (int, optional) – The padding for the keys in the output string (default is 20).

Returns:

A formatted string representation of the BaseRecord instance, excluding specified keys.

Return type:

str

class pidibble.baserecord.BaseRecordParser(fmtdict, typemap, allowed={})[source]

Bases: StringParser

A parser for fixed-width string records that generates BaseRecord instances. Inherits from StringParser.

add_fields(fields)[source]

Add fields to the parser’s field map.

Parameters:

fields (dict) – A dictionary of fields to add to the parser’s field map.

parse(record)[source]

Parse a fixed-width string record into a BaseRecord instance.

Parameters:

record (str) – The fixed-width string record to parse.

Returns:

A BaseRecord instance containing the parsed fields.

Return type:

BaseRecord

pidibble.baserecord.rstr(d, excludes, pad)[source]

Generate a formatted string representation of a dictionary, excluding specified keys.

Parameters:
  • d (dict) – The dictionary to format.

  • excludes (list) – A list of keys to exclude from the output.

  • pad (int) – The padding for the keys in the output string.

Returns:

A formatted string representation of the dictionary.

Return type:

str