A simple “ini” file format (pwkit.inifile)

A simple parser for ini-style files that’s better than Python’s ConfigParser/configparser.

Functions:

read

Generate a stream of pwkit.Holder instances from an ini-format file.

mutate

Rewrite an ini file chunk by chunk.

write

Write a stream of pwkit.Holder instances to an ini-format file.

mutate_stream

Lower-level version; only operates on streams, not path names.

read_stream

Lower-level version; only operates on streams, not path names.

write_stream

Lower-level version; only operates on streams, not path names.

mutate_in_place

Rewrite an ini file specififed by its path name, in place.

exception pwkit.inifile.InifileError(fmt, *args)[source]
pwkit.inifile.mutate_stream(instream, outstream)[source]

Python 3 compat note: we’re assuming stream gives bytes not unicode.

pwkit.inifile.read_stream(stream)[source]

Python 3 compat note: we’re assuming stream gives bytes not unicode.

pwkit.inifile.write(stream_or_path, holders, **kwargs)[source]

Very simple writing in ini format. The simple stringification of each value in each Holder is printed, and no escaping is performed. (This is most relevant for multiline values or ones containing pound signs.) None values are skipped.

Arguments:

stream

A text stream to write to.

holders

An iterable of objects to write. Their fields will be written as sections.

defaultsection=None

Section name to use if a holder doesn’t contain a section field.

pwkit.inifile.write_stream(stream, holders, defaultsection=None)[source]

Very simple writing in ini format. The simple stringification of each value in each Holder is printed, and no escaping is performed. (This is most relevant for multiline values or ones containing pound signs.) None values are skipped.

Arguments:

stream

A text stream to write to.

holders

An iterable of objects to write. Their fields will be written as sections.

defaultsection=None

Section name to use if a holder doesn’t contain a section field.