FPIBG Utility
libconf Namespace Reference

Classes

class  AttrDict
 
class  BoolToken
 
class  ConfigParseError
 
class  ConfigSerializeError
 
class  FltToken
 
class  IntToken
 
class  LibconfArray
 
class  LibconfInt64
 
class  LibconfList
 
class  Parser
 
class  StrToken
 
class  Token
 
class  Tokenizer
 
class  TokenStream
 

Functions

 isstr (s)
 
 isint (i)
 
 decode_escapes (s)
 
 compile_regexes (token_map)
 
 load (f, filename=None, includedir='')
 
 loads (string, filename=None, includedir='')
 
 is_long_int (i)
 
 dump_int (i)
 
 dump_string (s)
 
 get_dump_type (value)
 
 get_array_value_dtype (lst)
 
 dump_value (key, value, f, indent=0)
 
 dump_collection (cfg, f, indent=0)
 
 dump_dict (cfg, f, indent=0)
 
 dumps (cfg)
 
 dump (cfg, f)
 
 main ()
 

Variables

 LONGTYPE = long
 
int SMALL_INT_MIN = -2**31
 
int SMALL_INT_MAX = 2**31 - 1
 
 ESCAPE_SEQUENCE_RE = re.compile(, re.UNICODE | re.VERBOSE)
 
 SKIP_RE = re.compile(r'\s+|#.*$|//.*$|/\*(.|\n)*?\*/', re.MULTILINE)
 
 UNPRINTABLE_CHARACTER_RE = re.compile(r'[\x00-\x1F\x7F]')
 

Function Documentation

◆ compile_regexes()

libconf.compile_regexes ( token_map)

◆ decode_escapes()

libconf.decode_escapes ( s)
Unescape libconfig string literals

◆ dump()

libconf.dump ( cfg,
f )
Serialize ``cfg`` as a libconfig-formatted stream into ``f``

``cfg`` must be a ``dict`` with ``str`` keys and libconf-supported values
(numbers, strings, booleans, possibly nested dicts, lists, and tuples).

``f`` must be a ``file``-like object with a ``write()`` method.

◆ dump_collection()

libconf.dump_collection ( cfg,
f,
indent = 0 )
Save a collection of attributes

◆ dump_dict()

libconf.dump_dict ( cfg,
f,
indent = 0 )
Save a dictionary of attributes

◆ dump_int()

libconf.dump_int ( i)
Stringize ``i``, append 'L' suffix if necessary

◆ dump_string()

libconf.dump_string ( s)
Stringize ``s``, adding double quotes and escaping as necessary

Backslash escape backslashes, double quotes, ``\f``, ``\n``, ``\r``, and
``\t``. Escape all remaining unprintable characters in ``\xFF``-style.
The returned string will be surrounded by double quotes.

◆ dump_value()

libconf.dump_value ( key,
value,
f,
indent = 0 )
Save a value of any libconfig type

This function serializes takes ``key`` and ``value`` and serializes them
into ``f``. If ``key`` is ``None``, a list-style output is produced.
Otherwise, output has ``key = value`` format.

◆ dumps()

libconf.dumps ( cfg)
Serialize ``cfg`` into a libconfig-formatted ``str``

``cfg`` must be a ``dict`` with ``str`` keys and libconf-supported values
(numbers, strings, booleans, possibly nested dicts, lists, and tuples).

Returns the formatted string.

◆ get_array_value_dtype()

libconf.get_array_value_dtype ( lst)
Return array value type, raise ConfigSerializeError for invalid arrays

Libconfig arrays must only contain scalar values and all elements must be
of the same libconfig data type. Raises ConfigSerializeError if these
invariants are not met.

Returns the value type of the array. If an array contains both int and
long int data types, the return datatype will be ``'i64'``.

◆ get_dump_type()

libconf.get_dump_type ( value)
Get the libconfig datatype of a value

Return values: ``'d'`` (dict), ``'l'`` (list), ``'a'`` (array),
``'i'`` (integer), ``'i64'`` (long integer), ``'b'`` (bool),
``'f'`` (float), or ``'s'`` (string).

Produces the proper type for LibconfList, LibconfArray, LibconfInt64
instances.

◆ is_long_int()

libconf.is_long_int ( i)
Return True if argument should be dumped as int64 type

Either because the argument is an instance of LibconfInt64, or
because it exceeds the 32bit integer value range.

◆ isint()

libconf.isint ( i)

◆ isstr()

libconf.isstr ( s)

◆ load()

libconf.load ( f,
filename = None,
includedir = '' )
Load the contents of ``f`` (a file-like object) to a Python object

The returned object is a subclass of ``dict`` that exposes string keys as
attributes as well.

Example:

    >>> with open('test/example.cfg') as f:
    ...     config = libconf.load(f)
    >>> config['window']['title']
    'libconfig example'
    >>> config.window.title
    'libconfig example'

◆ loads()

libconf.loads ( string,
filename = None,
includedir = '' )
Load the contents of ``string`` to a Python object

The returned object is a subclass of ``dict`` that exposes string keys as
attributes as well.

Example:

    >>> config = libconf.loads('window: { title: "libconfig example"; };')
    >>> config['window']['title']
    'libconfig example'
    >>> config.window.title
    'libconfig example'

◆ main()

libconf.main ( )
Open the libconfig file specified by sys.argv[1] and pretty-print it

Variable Documentation

◆ ESCAPE_SEQUENCE_RE

libconf.ESCAPE_SEQUENCE_RE = re.compile(, re.UNICODE | re.VERBOSE)

◆ LONGTYPE

libconf.LONGTYPE = long

◆ SKIP_RE

libconf.SKIP_RE = re.compile(r'\s+|#.*$|//.*$|/\*(.|\n)*?\*/', re.MULTILINE)

◆ SMALL_INT_MAX

int libconf.SMALL_INT_MAX = 2**31 - 1

◆ SMALL_INT_MIN

int libconf.SMALL_INT_MIN = -2**31

◆ UNPRINTABLE_CHARACTER_RE

libconf.UNPRINTABLE_CHARACTER_RE = re.compile(r'[\x00-\x1F\x7F]')