Back to index

enigmail  1.4.3
Classes | Functions | Variables
configobj Namespace Reference

Classes

class  UnknownType
class  Builder
class  ConfigObjError
class  NestingError
class  ParseError
class  DuplicateError
class  ConfigspecError
class  InterpolationError
class  InterpolationLoopError
class  RepeatSectionError
class  MissingInterpolationOption
class  UnreprError
class  InterpolationEngine
class  ConfigParserInterpolation
class  TemplateInterpolation
class  Section
class  ConfigObj
class  SimpleVal

Functions

def enumerate
def getObj
def unrepr
def _splitlines
def flatten_errors

Variables

list INTP_VER = sys.version_info[:2]
 compiler = None
string BOM_UTF8 = '\xef\xbb\xbf'
string BOM_UTF16_LE = '\xff\xfe'
string BOM_UTF16_BE = '\xfe\xff'
 BOM_UTF16 = BOM_UTF16_LE
dictionary BOMS
dictionary BOM_LIST
dictionary BOM_SET
 VdtMissingValue = None
string __version__ = '4.4.0'
string __revision__ = '$Id: configobj.py,v 3.5 2007/07/02 18:20:24 benjamin%smedbergs.us Exp $'
string __docformat__ = "restructuredtext en"
tuple __all__
string DEFAULT_INTERPOLATION = 'configparser'
string DEFAULT_INDENT_TYPE = ' '
int MAX_INTERPOL_DEPTH = 10
dictionary OPTION_DEFAULTS
dictionary interpolation_engines

Class Documentation

class configobj::UnknownType

Definition at line 167 of file configobj.py.


Function Documentation

def configobj._splitlines (   instring) [private]
Split a string on lines, without losing line endings or truncating.

Definition at line 230 of file configobj.py.

00230 
00231 def _splitlines(instring):
00232     """Split a string on lines, without losing line endings or truncating."""
00233     

def configobj.enumerate (   obj)
enumerate for Python 2.2.

Definition at line 99 of file configobj.py.

00099 
00100     def enumerate(obj):
00101         """enumerate for Python 2.2."""
00102         i = -1
00103         for item in obj:
00104             i += 1
00105             yield i, item
00106 
try:

Here is the caller graph for this function:

def configobj.flatten_errors (   cfg,
  res,
  levels = None,
  results = None 
)
An example function that will turn a nested dictionary of results
(as returned by ``ConfigObj.validate``) into a flat list.

``cfg`` is the ConfigObj instance being checked, ``res`` is the results
dictionary returned by ``validate``.

(This is a recursive function, so you shouldn't use the ``levels`` or
``results`` arguments - they are used by the function.

Returns a list of keys that failed. Each member of the list is a tuple :
::

    ([list of sections...], key, result)

If ``validate`` was called with ``preserve_errors=False`` (the default)
then ``result`` will always be ``False``.

*list of sections* is a flattened list of sections that the key was found
in.

If the section was missing then key will be ``None``.

If the value (or section) was missing then ``result`` will be ``False``.

If ``validate`` was called with ``preserve_errors=True`` and a value
was present, but failed the check, then ``result`` will be the exception
object returned. You can use this as a string that describes the failure.

For example *The value "3" is of the wrong type*.

>>> import validate
>>> vtor = validate.Validator()
>>> my_ini = '''
...     option1 = True
...     [section1]
...     option1 = True
...     [section2]
...     another_option = Probably
...     [section3]
...     another_option = True
...     [[section3b]]
...     value = 3
...     value2 = a
...     value3 = 11
...     '''
>>> my_cfg = '''
...     option1 = boolean()
...     option2 = boolean()
...     option3 = boolean(default=Bad_value)
...     [section1]
...     option1 = boolean()
...     option2 = boolean()
...     option3 = boolean(default=Bad_value)
...     [section2]
...     another_option = boolean()
...     [section3]
...     another_option = boolean()
...     [[section3b]]
...     value = integer
...     value2 = integer
...     value3 = integer(0, 10)
...         [[[section3b-sub]]]
...         value = string
...     [section4]
...     another_option = boolean()
...     '''
>>> cs = my_cfg.split('\\n')
>>> ini = my_ini.split('\\n')
>>> cfg = ConfigObj(ini, configspec=cs)
>>> res = cfg.validate(vtor, preserve_errors=True)
>>> errors = []
>>> for entry in flatten_errors(cfg, res):
...     section_list, key, error = entry
...     section_list.insert(0, '[root]')
...     if key is not None:
...        section_list.append(key)
...     else:
...         section_list.append('[missing]')
...     section_string = ', '.join(section_list)
...     errors.append((section_string, ' = ', error))
>>> errors.sort()
>>> for entry in errors:
...     print entry[0], entry[1], (entry[2] or 0)
[root], option2  =  0
[root], option3  =  the value "Bad_value" is of the wrong type.
[root], section1, option2  =  0
[root], section1, option3  =  the value "Bad_value" is of the wrong type.
[root], section2, another_option  =  the value "Probably" is of the wrong type.
[root], section3, section3b, section3b-sub, [missing]  =  0
[root], section3, section3b, value2  =  the value "a" is of the wrong type.
[root], section3, section3b, value3  =  the value "11" is too big.
[root], section4, [missing]  =  0

Definition at line 2157 of file configobj.py.

02157 
02158 def flatten_errors(cfg, res, levels=None, results=None):
02159     """
02160     An example function that will turn a nested dictionary of results
02161     (as returned by ``ConfigObj.validate``) into a flat list.
02162     
02163     ``cfg`` is the ConfigObj instance being checked, ``res`` is the results
02164     dictionary returned by ``validate``.
02165     
02166     (This is a recursive function, so you shouldn't use the ``levels`` or
02167     ``results`` arguments - they are used by the function.
02168     
02169     Returns a list of keys that failed. Each member of the list is a tuple :
02170     ::
02171     
02172         ([list of sections...], key, result)
02173     
02174     If ``validate`` was called with ``preserve_errors=False`` (the default)
02175     then ``result`` will always be ``False``.
02176 
02177     *list of sections* is a flattened list of sections that the key was found
02178     in.
02179     
02180     If the section was missing then key will be ``None``.
02181     
02182     If the value (or section) was missing then ``result`` will be ``False``.
02183     
02184     If ``validate`` was called with ``preserve_errors=True`` and a value
02185     was present, but failed the check, then ``result`` will be the exception
02186     object returned. You can use this as a string that describes the failure.
02187     
02188     For example *The value "3" is of the wrong type*.
02189     
02190     >>> import validate
02191     >>> vtor = validate.Validator()
02192     >>> my_ini = '''
02193     ...     option1 = True
02194     ...     [section1]
02195     ...     option1 = True
02196     ...     [section2]
02197     ...     another_option = Probably
02198     ...     [section3]
02199     ...     another_option = True
02200     ...     [[section3b]]
02201     ...     value = 3
02202     ...     value2 = a
02203     ...     value3 = 11
02204     ...     '''
02205     >>> my_cfg = '''
02206     ...     option1 = boolean()
02207     ...     option2 = boolean()
02208     ...     option3 = boolean(default=Bad_value)
02209     ...     [section1]
02210     ...     option1 = boolean()
02211     ...     option2 = boolean()
02212     ...     option3 = boolean(default=Bad_value)
02213     ...     [section2]
02214     ...     another_option = boolean()
02215     ...     [section3]
02216     ...     another_option = boolean()
02217     ...     [[section3b]]
02218     ...     value = integer
02219     ...     value2 = integer
02220     ...     value3 = integer(0, 10)
02221     ...         [[[section3b-sub]]]
02222     ...         value = string
02223     ...     [section4]
02224     ...     another_option = boolean()
02225     ...     '''
02226     >>> cs = my_cfg.split('\\n')
02227     >>> ini = my_ini.split('\\n')
02228     >>> cfg = ConfigObj(ini, configspec=cs)
02229     >>> res = cfg.validate(vtor, preserve_errors=True)
02230     >>> errors = []
02231     >>> for entry in flatten_errors(cfg, res):
02232     ...     section_list, key, error = entry
02233     ...     section_list.insert(0, '[root]')
02234     ...     if key is not None:
02235     ...        section_list.append(key)
02236     ...     else:
02237     ...         section_list.append('[missing]')
02238     ...     section_string = ', '.join(section_list)
02239     ...     errors.append((section_string, ' = ', error))
02240     >>> errors.sort()
02241     >>> for entry in errors:
02242     ...     print entry[0], entry[1], (entry[2] or 0)
02243     [root], option2  =  0
02244     [root], option3  =  the value "Bad_value" is of the wrong type.
02245     [root], section1, option2  =  0
02246     [root], section1, option3  =  the value "Bad_value" is of the wrong type.
02247     [root], section2, another_option  =  the value "Probably" is of the wrong type.
02248     [root], section3, section3b, section3b-sub, [missing]  =  0
02249     [root], section3, section3b, value2  =  the value "a" is of the wrong type.
02250     [root], section3, section3b, value3  =  the value "11" is too big.
02251     [root], section4, [missing]  =  0
02252     """
02253     if levels is None:
02254         # first time called
02255         levels = []
02256         results = []
02257     if res is True:
02258         return results
02259     if res is False:
02260         results.append((levels[:], None, False))
02261         if levels:
02262             levels.pop()
02263         return results
02264     for (key, val) in res.items():
02265         if val == True:
02266             continue
02267         if isinstance(cfg.get(key), dict):
02268             # Go down one level
02269             levels.append(key)
02270             flatten_errors(cfg[key], val, levels, results)
02271             continue
02272         results.append((levels[:], key, val))
02273     #
02274     # Go up one level
02275     if levels:
02276         levels.pop()
02277     #
02278     return results
02279 
02280 """*A programming language is a medium of expression.* - Paul Graham"""
def configobj.getObj (   s)

Definition at line 160 of file configobj.py.

00160 
00161 def getObj(s):
00162     s = "a=" + s
00163     if compiler is None:
00164         raise ImportError('compiler module not available')
00165     p = compiler.parse(s)
00166     return p.getChildren()[1].getChildren()[0].getChildren()[1]

Here is the caller graph for this function:

def configobj.unrepr (   s)

Definition at line 225 of file configobj.py.

00225 
00226 def unrepr(s):
00227     if not s:
00228         return s
00229     return Builder().build(getObj(s))

Here is the call graph for this function:


Variable Documentation

Initial value:
00001 (
00002     '__version__',
00003     'DEFAULT_INDENT_TYPE',
00004     'DEFAULT_INTERPOLATION',
00005     'ConfigObjError',
00006     'NestingError',
00007     'ParseError',
00008     'DuplicateError',
00009     'ConfigspecError',
00010     'ConfigObj',
00011     'SimpleVal',
00012     'InterpolationError',
00013     'InterpolationLoopError',
00014     'MissingInterpolationOption',
00015     'RepeatSectionError',
00016     'UnreprError',
00017     'UnknownType',
00018     '__docformat__',
00019     'flatten_errors',
00020 )

Definition at line 118 of file configobj.py.

string configobj.__docformat__ = "restructuredtext en"

Definition at line 116 of file configobj.py.

string configobj.__revision__ = '$Id: configobj.py,v 3.5 2007/07/02 18:20:24 benjamin%smedbergs.us Exp $'

Definition at line 114 of file configobj.py.

string configobj.__version__ = '4.4.0'

Definition at line 112 of file configobj.py.

dictionary configobj.BOM_LIST
Initial value:
00001 {
00002     'utf_16': 'utf_16',
00003     'u16': 'utf_16',
00004     'utf16': 'utf_16',
00005     'utf-16': 'utf_16',
00006     'utf16_be': 'utf16_be',
00007     'utf_16_be': 'utf16_be',
00008     'utf-16be': 'utf16_be',
00009     'utf16_le': 'utf16_le',
00010     'utf_16_le': 'utf16_le',
00011     'utf-16le': 'utf16_le',
00012     'utf_8': 'utf_8',
00013     'u8': 'utf_8',
00014     'utf': 'utf_8',
00015     'utf8': 'utf_8',
00016     'utf-8': 'utf_8',
00017     }

Definition at line 64 of file configobj.py.

dictionary configobj.BOM_SET
Initial value:
00001 {
00002     'utf_8': BOM_UTF8,
00003     'utf_16': BOM_UTF16,
00004     'utf16_be': BOM_UTF16_BE,
00005     'utf16_le': BOM_UTF16_LE,
00006     None: BOM_UTF8
00007     }

Definition at line 83 of file configobj.py.

Definition at line 47 of file configobj.py.

string configobj.BOM_UTF16_BE = '\xfe\xff'

Definition at line 44 of file configobj.py.

string configobj.BOM_UTF16_LE = '\xff\xfe'

Definition at line 42 of file configobj.py.

string configobj.BOM_UTF8 = '\xef\xbb\xbf'

Definition at line 40 of file configobj.py.

dictionary configobj.BOMS
Initial value:
00001 {
00002     BOM_UTF8: ('utf_8', None),
00003     BOM_UTF16_BE: ('utf16_be', 'utf_16'),
00004     BOM_UTF16_LE: ('utf16_le', 'utf_16'),
00005     BOM_UTF16: ('utf_16', 'utf_16'),
00006     }

Definition at line 55 of file configobj.py.

Definition at line 27 of file configobj.py.

Definition at line 140 of file configobj.py.

string configobj.DEFAULT_INTERPOLATION = 'configparser'

Definition at line 139 of file configobj.py.

Initial value:
00001 {
00002     'configparser': ConfigParserInterpolation,
00003     'template': TemplateInterpolation,
00004 }

Definition at line 445 of file configobj.py.

list configobj.INTP_VER = sys.version_info[:2]

Definition at line 22 of file configobj.py.

Definition at line 141 of file configobj.py.

Initial value:
00001 {
00002     'interpolation': True,
00003     'raise_errors': False,
00004     'list_values': True,
00005     'create_empty': False,
00006     'file_error': False,
00007     'configspec': None,
00008     'stringify': True,
00009     # option may be set to one of ('', ' ', '\t')
00010     'indent_type': None,
00011     'encoding': None,
00012     'default_encoding': None,
00013     'unrepr': False,
00014     'write_empty_values': False,
00015 }

Definition at line 143 of file configobj.py.

Definition at line 94 of file configobj.py.