Source documentation

ihih - simple configuration parsers with dictionary-like interface

License: BSD 3-Clause

class ihih.IHIH(filenames, *args, **kwargs)

Bases: dict

IHIH - simple configuration parser

One key/value pair per line.

encoding = 'utf8'

define the encoding

__init__(filenames, *args, **kwargs)

attempt to parse a list of filenames

Parameters:

  • filenames – if is a string, it is treated as a single file, otherwise it is treated as an iterable
  • other parameters are passed to the dict constructor
reload(force=False)

call parse() on each configuration file

parse(filename, force=False)

parse a configuration file

Note

filename should be an absolute path.

_unescape(value, quote=None)

remove escape prefix on “known escape”

See _escaped_chars.

This method attempt to utf8 encode unicode() objects.

_handle_fragment(fragment, quote=None)

handle a fragment of a value

Provided to help on subclassing.

_strip_comment(value)

remove the comment on value

_parse_value(value, data)

parse the “value” part of a “key / value”

This function handle the quoted parts.

Parameters:

  • value (basestring() instance): value to parse
  • data: instance supporting += operator
_cast_str(value)

return a string representation of value

__contains__(key)

True if self contains key

Note

The key will be casted as str() (see: _cast_str()).

__setitem__(key, value)

set item key to value

Note

Both variables will be casted as str() (see: _cast_str()).

__getitem__(key)

return key value as internal type

You probably want to use one of the following: get_str(), get_unicode(), get_float().

Note

The key will be casted as str() (see: _cast_str()).

__delitem__(key)

delete key from dict

Note

The key will be casted as str() (see: _cast_str()).

get_str(key, default=None)

return key value as str() or default if not found

Note

The key will be casted as str() (see: _cast_str()).

get(key, default=None)

alias to get_str()

__weakref__

list of weak references to the object (if defined)

get_unicode(key, default=None, errors='strict')

return key value as unicode() or default if not found

The errors parameter is passed to str.decode().

Note

The key will be casted as str() (see: _cast_str()).

get_float(key, default=None, errors='strict')

return key value as float() or default if not found

If errors is “ignore”, return default value instead of raising TypeError on failure.

Note

The key will be casted as str() (see: _cast_str()).

class ihih.IHIHI(*args, **kwargs)

Bases: ihih.IHIH

IHIH Interpolate - IHIH with variable interpolation

_handle_fragment(fragment, quote=None)

search for variables in fragment

__getitem__(key, path=None)

return key value as internal type with interpolated variables

For more informations, see: __getitem__().

_recursive(value)

recursive variable handler

Default: empty string

You can overwrite this function when subclassing and chose to return a unexpended version of the variable, raise an error or make a single, non recursive, lookup.

Project Versions

Previous topic

ihih — simple configuration parsers

Next topic

Examples

This Page