Layout Factories

Each layout has up to four string converters. There are readers and writers, each of which has a variant for individual strings (Line) or entire files (Dict).

txf.layouts.LineReaderFactory(name, layout, iterable, **config)

Constructs a LineReader for the given layout. The reader will parse each string into a string tuple.

Parameters
  • name (str) – The name of the calling transform.

  • layout (str) – The string layout to read.

  • iterable – The source of the strings to parse.

  • config – Optional configuration parameters for the LineReader.

Returns

An iterable that generates parsed tuples of values

Raises

TransformException – if the layout is unknown or the iterable is not iterable.

txf.layouts.DictReaderFactory(name, layout, iterable, fieldnames, **config)

Constructs a DictReader for the given layout. The reader will parse each string into a record.

Parameters
  • name (str) – The name of the calling transform.

  • layout (str) – The string layout to read.

  • iterable – The source of the strings to parse.

  • fieldnames (fields) – The fields to read from the record.

  • config – Optional configuration parameters for the DictReader.

Returns

An iterable that generates parsed records

Raises

TransformException – if the layout is unknown or the iterable is not iterable.

txf.layouts.LineWriterFactory(name, layout, outfile, fieldnames, **config)

Constructs a DictWriter for the given layout that converts tuples into strings in the given layout and writes them to the output.

Parameters
  • name (str) – The name of the calling transform.

  • layout (str) – The string layout to write.

  • outfile – The destination for the strings.

  • fieldnames (fields) – The fields corresponding to the tuple values.

  • config – Optional configuration parameters for the :py:class`DictReader`.

Returns

LineWriter that writes layout tuples

Raises

TransformException – if the layout is unknown or the outfile does not have a write() method

txf.layouts.DictWriterFactory(name, layout, outfile, fieldnames, **config)

Constructs a DictWriter for the given layout that converts records into strings in the given layout and writes them to the output.

Parameters
  • name (str) – The name of the calling transform.

  • layout (str) – The string layout to write.

  • outfile (writable) – The destination for the strings.

  • fieldnames (fields) – The fields corresponding to the tuple values.

  • config – Optional configuration parameters for the DictReader.

Returns

A DictWriter that writes layout tuples

Raises

TransformException – if the layout is unknown or the outfile does not have a write() method

txf.layouts.GetLayout(layout)

Returns the factories for a layout code. If there are no entries, the layout is not defined.

Parameters

layout (str) – The layout

Returns

The factories.

Return type

dict

txf.layouts.RegisterLayout(layout, namespace)

Adds factories for a layout code, reading them from the dir() of the namespace. Existing factories are replaced.

Parameters

namespace – An object containing the factories.

txf.layouts.UnregisterLayout(layout)

Remove the factories for the layout.

Parameters

namespace – An object containing the factories.