anyconfig.backend.shellvars

Simple Shell vars’ definitions backend:

  • Format to support: Simple shell variables’ definitions w/o any shell variable expansions nor complex shell statements such as conditionals, etc.

  • Requirements: None (built-in)

  • Development Status :: 3 - Alpha

  • Limitations: Currently, it only supports a varialbe defined in a line.

  • Special options: None

Changelog:

    New in version 0.7.0:
  • Added an experimental parser for simple shelll vars’ definitions w/o shell variable expansions nor complex shell statements like conditionals.

anyconfig.backend.shellvars._parseline(line)

Parse a line contains shell variable definition.

Parameters

line – A string to parse, must not start with ‘#’ (comment)

Returns

A tuple of (key, value), both key and value may be None

>>> _parseline("aaa=")
('aaa', '')
>>> _parseline("aaa=bbb")
('aaa', 'bbb')
>>> _parseline("aaa='bb b'")
('aaa', 'bb b')
>>> _parseline('aaa="bb#b"')
('aaa', 'bb#b')
>>> _parseline('aaa="bb\"b"')
('aaa', 'bb"b')
>>> _parseline("aaa=bbb   # ccc")
('aaa', 'bbb')
anyconfig.backend.shellvars.load(stream, container=<class 'dict'>)

Load and parse a file or file-like object stream provides simple shell variables’ definitions.

Parameters
  • stream – A file or file like object

  • container – Factory function to create a dict-like object to store properties

Returns

Dict-like object holding shell variables’ definitions

>>> from anyconfig.compat import StringIO as to_strm
>>> load(to_strm(''))
{}
>>> load(to_strm("# "))
{}
>>> load(to_strm("aaa="))
{'aaa': ''}
>>> load(to_strm("aaa=bbb"))
{'aaa': 'bbb'}
>>> load(to_strm("aaa=bbb # ..."))
{'aaa': 'bbb'}
class anyconfig.backend.shellvars.Parser

Bases: anyconfig.backend.base.StreamParser

Parser for Shell variable definition files.

_type = 'shellvars'
_ordered = True
_dict_opts = ['ac_dict']
load_from_stream(stream, container, **kwargs)

Load config from given file like object stream.

Parameters
  • stream – A file or file like object of shell scripts define shell variables

  • container – callble to make a container object

  • kwargs – optional keyword parameters (ignored)

Returns

Dict-like object holding config parameters

dump_to_stream(cnf, stream, **kwargs)

Dump config cnf to a file or file-like object stream.

Parameters
  • cnf – Shell variables data to dump

  • stream – Shell script file or file like object

  • kwargs – backend-specific optional keyword parameters :: dict

__module__ = 'anyconfig.backend.shellvars'