Input and Output of a KIP Document
KIP Document processing often works like a pipeline, taking in one form and outputting another. By default, both are files. But it is possible to use other exchange mechanisms. New I/O modules can be added independently from the KIP handling itself.
The default handler for File I/O is a module arpa2.kip.io.file, which
inherits from general classes in arpa2.kip.io.
By way of example, the File I/O module consists of:
-
A definition
regexesdefining the URI forms that it can handle. It uses a literal dot.as an abbreviation forstdinorstdout,/xxxfile names and the URI formatfile:///xxxorfile://localhost/xxxto match the general URI idea. -
A class
FileSourcethat reads from file. This inherits fromio.Source. -
A class
FileTargetthat writes to file. This inherits fromio.Target.
The superclasses in arpa2.kip.io are the following:
-
Connectorholds the code and abstractions shared by theSourceandTargetclasses in thearpa2.kip.iopackage. Do not inherit directly from this class, but use its code and definitions throughSourceorTarget. -
Sourcesubclasses can be used as entry_point forarpa2.kip.io.sourcesso they are made available to users (who may subsequently configure them).For every source URI in commands like
kip up,kip downand so on, a configured sequence of these classes is tried. First, an exact match is tried on all configured plugins; when all fail, then more liberal matching is tried, for which they will be sorted by a score. This allows both easy-intuitive uses and accurate, well-established patterns.To read data, a connection is made that should return a file-like object, possibly with metadata. Connection failure causes the next pattern to be tried, but an exact match that fails to connect will never fall back to the more liberal matches.
-
Targetsubclasses can be used as entry_point forarpa2.kip.io.targetsso they are made available to users (who may subsequently configure them).For every target URI in commands like
kip up,kip downand so on, a configured sequence of these classes is tried. First, an exact match is tried on all configured plugins; when all fail, then more liberal matching is tried, for which they will be sorted by a score. This allows both easy-intuitive uses and accurate, well-established patterns.To write data, a connection is made, possibly with metadata, that should return a file-like object. Connection failure causes the next pattern to be tried, but an exact match that fails to connect will never fall back to the more liberal matches.