Python Paste


INIParser

A parser for .ini-syntax files.

Implements all features I know of in .ini files:

  • sections with a [ in the first column
  • assignment via a=b or a: b
  • rfc822-style continuation lines (i.e., start the next line with indentation to make it a continuation).
  • ; or # for comments

This class should be subclassed. Subclasses may only need to implement the .assignment() method. You may want to use the .section attribute, which holds the current section (or None if no section has been defined yet).

Use .parse_error(message) when you encounter a problem; this will create an exception that will note the filename and line in which the problem occurs.


Methods

f __init__(self) ...

f reset(self) ...

f load(self, filename, encoding=None) ...

f loadfile(self, fileobj, filename=None, encoding=None) ...

f loadstring(self, string, filename=None) ...

f process_file(self) ...

f split_name_value(self, line) ...

f get_comment(self, line) ...

Returns None if not a comment

f get_section(self, line) ...

Returns None if not a section

f process_assignment(self, name, accumulated_content) ...

f assignment(self, name, content) ...

f new_section(self, section) ...

f add_comment(self, comment) ...

f error_missing_equal(self, line) ...

f parse_error(self, msg, line=None, exception=None) ...

See the source for more information.