Package yapydata :: Package datatree :: Module synini :: Class ConfigDataINIX

Class ConfigDataINIX

source code


A simple configuration file parser based on the standard ConfigParser class.

The final resulting data with completely applied syntax-extensions is available by the method readout_data().

Supports the data types:

int, float, str

multi-line lists,
multi-line search-paths

null
true, false

The optional structure:

global-attributes-without-section

The standard file extensions are:

'.ini'

The supported stnadard features of ConfigParser include:

interpolation

For detailed information refer to the parameters of the __init__ method.

Instance Methods
 
__bool__(self) source code
 
__nonzero__(self) source code
 
__getitem__(self, key)
Get the section object. Requires for Python2 the backport from Python3 "configparser", see PyPI
source code
 
get(self, key)
Get the section object - compatible to Python3 and the backport of the configparser.
source code
 
keys(self) source code
 
set(self, section, option, value) source code
Class Variables
  suffixes = 'ini',
standard suffixes for INI
Method Details

__init__(self, conf, **kargs)
(Constructor)

source code 
Args:
conf:
The file path name of the configuration file.
kargs:

For additional parameters see ConfigData.

allow_no_value:

Enables the support for keys without values of INI format files. Supported by the standard library based configparser . The value could be applied to derived custom parser:

default := False

See parameter allow_no_value of configparser.ConfigParser.

casesens:

Preserves case of keys:

default := False
comment_prefixes:

Defines the comment prefixes:

default := ('#', ';')
delimiters:

Defines the delimiters for INI format based files. Supported by the standard library based configparser . The value could be applied to derived custom parser:

default := ('=', ':',)
dict_type:

The type of dictionary to be used by the parent class:

default := None

empty_lines_in_values:

default := False
inline_comment_prefixes:

Defines the inline comment prefixes:

default := None
interpolation:

Enables the creation and replacement of variables within configuration files. Depends on the derived class, when not supported simply ignored:

default := True

See parameter interpolation of configparser.ConfigParser.

sectionpaths:

Enables the conversion and interpretation of section names as path entries. This is required, when the versatility of the converted and/or merged syntaxes are of different degree, and the actual used syntax data path elements could not be converted. In this case an intermediate sub-syntax is supported by a dotted path notation, which could be converted between the applied syntaxes:

sectionpaths := (
     True         # long data paths e.g. from *JSON* are
                  # converted to dotted section names
                  # and vice versa
   | False        # requires compatible versatility,
                  # else raises exception
)

default := True
sectionpaths=True:
The section names of the native INIX syntax by default constitute a one-level-only depth of data structures for the complexity of structure definition.

sectionpaths=False:

sectionpathsep:

Defines the character used in section names as path separator. The character has to be valid as provided by the config parser of the syntax, in particular a valid character for section names of INI files, and has to be semantically suitable as a special separator character:

sectionpathsep := []

default := '.'

Valid only when sectionpaths is active.

strict:

Controls the verification of duplicate sections when these are used:

strict := (
      True    # raise an exception for duplicates
    | False   # accept
)

default := False

See strict option of ConfigParser.

quiet:

Suppresses display of non-errors:

default := False
Returns:
None/object
Raises:
pass-through
Decorators:

import_data(self, conf, **kargs)

source code 
Reads the configuration file and imports data. Supported standard types are::

   'cfg', 'conf', 'ini',

The imported data for the suported standard syntax is interpreted as:

    +----------------------------------------+-------------+-------------------+-------------+-------------------------+----------------------------------------------+
    | syntax of imported config              | sections as | keys as           | path as     | insertion position      | remark                                       |
    +========================================+=============+===================+=============+=========================+==============================================+
    | `conf <parser_conf.html>`_             | sections    | keys to <section> | --          | top, <section>, DEFAULT | no rename and no nested sections, no globals |
    +----------------------------------------+-------------+-------------------+-------------+-------------------------+----------------------------------------------+
    | `ini <parser_ini.html>`_               | sections    | keys by section   | --          | top, <section>, DEFAULT | no rename and no nested sections, no globals |
    +----------------------------------------+-------------+-------------------+-------------+-------------------------+----------------------------------------------+
    | `inix <parser_inix.html>`_             | sections    | keys by section   | --          | top, <section>, DEFAULT | no rename and no nested sections, no globals |
    +----------------------------------------+-------------+-------------------+-------------+-------------------------+----------------------------------------------+

Args:
    conf:
        The file path name of the configuration file.

   kargs:
        Unknown options are passed through to the
        configuration parser.

        anchor:
            The insertion point for the imported data::

              anchor := (
                   <section>
                 | 'DEFAULT'
                 | <top>
              )
              
              top := "imports valid INIX/INI/CONF files with sections only"
              section := "the name of the section"
              'DEFAULT' := "keyword defined by the standard library as 
                            global defaults for interpolation"

              default := <top>

        strict:
            Activates validation. The boolean value is
            mapped to the corresponding option of the
            called import parser:

                +------------+----------+-------+--------+
                | parser     | option   | True  | False  |
                +============+==========+=======+========+
                | conf       | strict   | True  | False  |
                +------------+----------+-------+--------+
                | ini        | strict   | True  | False  |
                +------------+----------+-------+--------+
                | inix       | strict   | True  | False  |
                +------------+----------+-------+--------+

        syntax:
            Force the provided syntax. For available
            values refer to syntax multiplexer
            *self.synmux*.

Returns:
    True for success, else False or raises an exception.

Raises:
    pass-through

Decorators:

load_parser(self, **kargs)

source code 

Loads the syntax parser configparser.ConfigParser and patches the behaviour for common 'conf' and 'cfg' format. Supports the most of the files in '/etc' of POSIX based OS.

Args:
kargs:

For the description of the options refer to the method header of multiconf.data.load_parser(). Unknown are passed through to the loaded configuration parser.

For the following parameters see __init__:

  • allow_no_value
  • casesens
  • comment_prefixes
  • inline_comment_prefixes
  • delimiters
  • dict_type
  • empty_lines_in_values
  • interpolation
  • strict
  • quiet
Returns:
True, or raises an exception.
Raises:
pass-through
Decorators:

readout_data(self, **kargs)

source code 

Returns the configuration as JSON compatible format. Removes the special dummy section header 'globaldummy', see import_data.

Args:
kargs:
stronly:

Scans all as str only.

stronly := (
      True    # int and float are
              # converted to str
    | False   # numeric values are kept
)

default := False

Returns:
In-memory JSON compatible data.
Raises:
pass-through
Decorators: