Abstract configuration file parser based on sections and settings
The basic idea of this class is that you subclass it, supplying
replacements for the get_handler() and/or add_setting() methods.
If your format will handle all sections the same way, just override
add_setting(). If it will handle sections differently, override
get_handler() to return an appropriate method for processing settings
in that section. If you want sections which aren't parsed as settings
at all, you'll need to revise the add_section() method to handle
such sections differently.
To use your class, you'll create an instance of the parser, then
call its readFile(), readStream() or readString() methods to
process configuration data from as many sources as you like. What
will happens when each setting is received, is of course up to your
subclass to determine.
|
Methods
|
|
add_section
add_setting
get_handler
parse
process_settings
readFile
readStream
readString
|
|
|
add_section
|
add_section (
self,
section,
lines,
lineInfo,
)
Add a section to configuration
|
|
|
add_setting
|
add_setting (
self,
section,
name,
value,
lineInfo,
)
Override this to implement your standard processing for settings
|
|
|
get_handler
|
get_handler (
self,
section,
lines,
lineInfo,
)
Override this to choose setting handlers per section
|
|
|
parse
|
parse ( self, lineSource )
Read lineInfo-stream lineSource into configuration
|
|
|
process_settings
|
process_settings (
self,
section,
lines,
handler,
)
Process a section's worth of settings using handler
|
|
|
readFile
|
readFile (
self,
filename,
mode='r',
)
Read file filename into configuration
|
|
|
readStream
|
readStream (
self,
stream,
source,
)
Read stream into configuration
|
|
|
readString
|
readString (
self,
text,
source='<string>',
)
Read text into configuration
|
|