Robot Framework Integrated Development Environment (RIDE)
robotide.preferences.configobj.ConfigObj Class Reference

An object to read, create, and write config files. More...

Inheritance diagram for robotide.preferences.configobj.ConfigObj:
robotide.preferences.configobj.Section dict

Public Member Functions

def __init__ (self, infile=None, options=None, configspec=None, encoding=None, interpolation=True, raise_errors=False, list_values=True, create_empty=False, file_error=False, stringify=True, indent_type=None, default_encoding=None, unrepr=False, write_empty_values=False, _inspec=False)
 Parse a config file or create a config file object. More...
 
def __repr__ (self)
 x.__repr__() <==> repr(x) More...
 
def reload (self)
 Reload a ConfigObj from file. More...
 
def reset (self)
 Clear ConfigObj instance and restore to 'freshly created' state. More...
 
def validate (self, validator, preserve_errors=False, copy=False, section=None)
 Test the ConfigObj against a configspec. More...
 
def write (self, outfile=None, section=None)
 Write the current ConfigObj as a file. More...
 
- Public Member Functions inherited from robotide.preferences.configobj.Section
def __delitem__ (self, key)
 Remove items from the sequence when deleting. More...
 
def __getitem__ (self, key)
 Fetch the item and do string interpolation. More...
 
def __init__ (self, parent, depth, main, indict=None, name=None)
 
def __reduce__ (self)
 
def __setitem__ (self, key, value, unrepr=False)
 Correctly set a value. More...
 
def __setstate__ (self, state)
 
def as_bool (self, key)
 Accepts a key as input. More...
 
def as_float (self, key)
 A convenience method which coerces the specified value to a float. More...
 
def as_int (self, key)
 A convenience method which coerces the specified value to an integer. More...
 
def as_list (self, key)
 A convenience method which fetches the specified value, guaranteeing that it is a list. More...
 
def clear (self)
 A version of clear that also affects scalars/sections Also clears comments and configspec. More...
 
def dict (self)
 Return a deepcopy of self as a dictionary. More...
 
def get (self, key, default=None)
 A version of get that doesn't bypass string interpolation. More...
 
def items (self)
 D.items() -> list of D's (key, value) pairs, as 2-tuples. More...
 
def iteritems (self)
 D.iteritems() -> an iterator over the (key, value) items of D. More...
 
def iterkeys (self)
 D.iterkeys() -> an iterator over the keys of D. More...
 
def itervalues (self)
 D.itervalues() -> an iterator over the values of D. More...
 
def keys (self)
 D.keys() -> list of D's keys. More...
 
def merge (self, indict)
 A recursive update - useful for merging config files. More...
 
def pop (self, key, default=MISSING)
 'D.pop(k[,d]) -> v, remove specified key and return the corresponding value. More...
 
def popitem (self)
 Pops the first (key,val) More...
 
def rename (self, oldkey, newkey)
 Change a keyname to another, without changing position in sequence. More...
 
def restore_default (self, key)
 Restore (and return) default value for the specified key. More...
 
def restore_defaults (self)
 Recursively restore default values to all members that have them. More...
 
def setdefault (self, key, default=None)
 A version of setdefault that sets sequence if appropriate. More...
 
def update (self, indict)
 A version of update that uses our __setitem__. More...
 
def values (self)
 D.values() -> list of D's values. More...
 
def walk (self, function, raise_errors=True, call_on_sections=False, **keywargs)
 Walk every member and call a function on the keyword and value. More...
 

Public Attributes

 BOM
 BOM discovered self.BOM = True Don't need to remove BOM. More...
 
 configspec
 
 create_empty
 
 default_encoding
 
 encoding
 
 file_error
 
 filename
 
 final_comment
 
 indent_type
 
 initial_comment
 
 interpolation
 
 list_values
 
 newlines
 
 raise_errors
 
 stringify
 
 unrepr
 
 write_empty_values
 
- Public Attributes inherited from robotide.preferences.configobj.Section
 comments
 
 configspec
 
 default_values
 
 defaults
 
 depth
 
 extra_values
 
 inline_comments
 
 main
 
 name
 
 parent
 
 scalars
 
 sections
 

Private Member Functions

def _a_to_u (self, aString)
 Decode ASCII strings to unicode if a self.encoding is specified. More...
 
def _decode (self, infile, encoding)
 
def _decode_element (self, line)
 Decode element to unicode if necessary. More...
 
def _get_single_quote (self, value)
 
def _get_triple_quote (self, value)
 
def _handle_bom (self, infile)
 
def _handle_comment (self, comment)
 Deal with a comment. More...
 
def _handle_configspec (self, configspec)
 Parse the configspec. More...
 
def _handle_error (self, text, ErrorClass, infile, cur_index)
 
def _handle_value (self, value)
 
def _initialise (self, options=None)
 
def _load (self, infile, configspec)
 
def _match_depth (self, sect, depth)
 
def _multiline (self, value, infile, cur_index, maxline)
 Extract the value, where we are in a multiline situation. More...
 
def _parse (self, infile)
 Actually parse the config file. More...
 
def _quote (self, value, multiline=True)
 
def _set_configspec (self, section, copy)
 
def _str (self, value)
 
def _unquote (self, value)
 Return an unquoted version of a value. More...
 
def _write_line (self, indent_string, entry, this_entry, comment)
 Write an individual line, for the write method. More...
 
def _write_marker (self, indent_string, depth, entry, comment)
 Write a section marker line. More...
 

Private Attributes

 _errors
 
 _inspec
 
 _original_configspec
 
 _vdtMissingValue
 

Static Private Attributes

dictionary _bools
 
 _keyword
 
 _listvalueexp
 
 _multi_line_double
 
 _multi_line_single
 
 _nolistvalue
 
 _sectionmarker
 
 _single_line_double
 
 _single_line_single
 
dictionary _triple_quote
 
 _valueexp
 

Detailed Description

An object to read, create, and write config files.

Definition at line 1098 of file configobj.py.

Constructor & Destructor Documentation

◆ __init__()

def robotide.preferences.configobj.ConfigObj.__init__ (   self,
  infile = None,
  options = None,
  configspec = None,
  encoding = None,
  interpolation = True,
  raise_errors = False,
  list_values = True,
  create_empty = False,
  file_error = False,
  stringify = True,
  indent_type = None,
  default_encoding = None,
  unrepr = False,
  write_empty_values = False,
  _inspec = False 
)

Parse a config file or create a config file object.

``ConfigObj(infile=None, configspec=None, encoding=None, interpolation=True, raise_errors=False, list_values=True, create_empty=False, file_error=False, stringify=True, indent_type=None, default_encoding=None, unrepr=False, write_empty_values=False, _inspec=False)``

Definition at line 1242 of file configobj.py.

Member Function Documentation

◆ __repr__()

def robotide.preferences.configobj.ConfigObj.__repr__ (   self)

x.__repr__() <==> repr(x)

Reimplemented from robotide.preferences.configobj.Section.

Definition at line 1422 of file configobj.py.

◆ _a_to_u()

def robotide.preferences.configobj.ConfigObj._a_to_u (   self,
  aString 
)
private

Decode ASCII strings to unicode if a self.encoding is specified.

Definition at line 1555 of file configobj.py.

◆ _decode()

def robotide.preferences.configobj.ConfigObj._decode (   self,
  infile,
  encoding 
)
private
   Decode infile to unicode. Using the specified encoding.

   if is a string, it also needs converting to a list.

Definition at line 1569 of file configobj.py.

◆ _decode_element()

def robotide.preferences.configobj.ConfigObj._decode_element (   self,
  line 
)
private

Decode element to unicode if necessary.

Definition at line 1592 of file configobj.py.

◆ _get_single_quote()

def robotide.preferences.configobj.ConfigObj._get_single_quote (   self,
  value 
)
private

Definition at line 1911 of file configobj.py.

◆ _get_triple_quote()

def robotide.preferences.configobj.ConfigObj._get_triple_quote (   self,
  value 
)
private

Definition at line 1921 of file configobj.py.

◆ _handle_bom()

def robotide.preferences.configobj.ConfigObj._handle_bom (   self,
  infile 
)
private
   Handle any BOM, and decode if necessary.

   If an encoding is specified, that *must* be used - but the BOM should
   still be removed (and the BOM attribute set).

   (If the encoding is wrongly specified, then a BOM for an alternative
   encoding won't be discovered or removed.)

   If an encoding is not specified, UTF8 or UTF16 BOM will be detected and
   removed. The BOM attribute will be set. UTF16 will be decoded to
   unicode.

   NOTE: This method must not be called with an empty ``infile``.

   Specifying the *wrong* encoding is likely to cause a
   ``UnicodeDecodeError``.

   ``infile`` must always be returned as a list of lines, but may be
   passed in as a single string.

Definition at line 1456 of file configobj.py.

◆ _handle_comment()

def robotide.preferences.configobj.ConfigObj._handle_comment (   self,
  comment 
)
private

Deal with a comment.

Definition at line 2102 of file configobj.py.

◆ _handle_configspec()

def robotide.preferences.configobj.ConfigObj._handle_configspec (   self,
  configspec 
)
private

Parse the configspec.

Definition at line 2022 of file configobj.py.

◆ _handle_error()

def robotide.preferences.configobj.ConfigObj._handle_error (   self,
  text,
  ErrorClass,
  infile,
  cur_index 
)
private
   Handle an error according to the error settings.

   Either raise the error or store it.
   The error will have occured at ``cur_index``

Definition at line 1813 of file configobj.py.

◆ _handle_value()

def robotide.preferences.configobj.ConfigObj._handle_value (   self,
  value 
)
private
   Given a value string, unquote, remove comment,
   handle lists. (including empty and single member lists)

Definition at line 1937 of file configobj.py.

◆ _initialise()

def robotide.preferences.configobj.ConfigObj._initialise (   self,
  options = None 
)
private

Definition at line 1390 of file configobj.py.

◆ _load()

def robotide.preferences.configobj.ConfigObj._load (   self,
  infile,
  configspec 
)
private

Definition at line 1294 of file configobj.py.

◆ _match_depth()

def robotide.preferences.configobj.ConfigObj._match_depth (   self,
  sect,
  depth 
)
private
   Given a section and a depth level, walk back through the sections
   parents to see if the depth level matches a previous section.

   Return a reference to the right section,
   or raise a SyntaxError.

Definition at line 1793 of file configobj.py.

◆ _multiline()

def robotide.preferences.configobj.ConfigObj._multiline (   self,
  value,
  infile,
  cur_index,
  maxline 
)
private

Extract the value, where we are in a multiline situation.

Definition at line 1985 of file configobj.py.

◆ _parse()

def robotide.preferences.configobj.ConfigObj._parse (   self,
  infile 
)
private

Actually parse the config file.

Definition at line 1618 of file configobj.py.

◆ _quote()

def robotide.preferences.configobj.ConfigObj._quote (   self,
  value,
  multiline = True 
)
private
   Return a safely quoted version of a value.

   Raise a ConfigObjError if the value cannot be safely quoted.
   If multiline is ``True`` (default) then use triple quotes
   if necessary.

   * Don't quote values that don't need it.
   * Recursively quote members of a list and return a comma joined list.
   * Multiline is ``False`` for lists.
   * Obey list syntax for empty and single member lists.

   If ``list_values=False`` then the value is only quoted if it contains
   a ``\\n`` (is multiline) or '#'.

   If ``write_empty_values`` is set, and the value is an empty string, it
   won't be quoted.

Definition at line 1858 of file configobj.py.

◆ _set_configspec()

def robotide.preferences.configobj.ConfigObj._set_configspec (   self,
  section,
  copy 
)
private
   Called by validate. Handles setting the configspec on subsections
   including sections to be validated by __many__

Definition at line 2048 of file configobj.py.

◆ _str()

def robotide.preferences.configobj.ConfigObj._str (   self,
  value 
)
private
   Used by ``stringify`` within validate, to turn non-string values
   into strings.

Definition at line 1606 of file configobj.py.

◆ _unquote()

def robotide.preferences.configobj.ConfigObj._unquote (   self,
  value 
)
private

Return an unquoted version of a value.

Definition at line 1829 of file configobj.py.

◆ _write_line()

def robotide.preferences.configobj.ConfigObj._write_line (   self,
  indent_string,
  entry,
  this_entry,
  comment 
)
private

Write an individual line, for the write method.

Definition at line 2075 of file configobj.py.

◆ _write_marker()

def robotide.preferences.configobj.ConfigObj._write_marker (   self,
  indent_string,
  depth,
  entry,
  comment 
)
private

Write a section marker line.

Definition at line 2091 of file configobj.py.

◆ reload()

def robotide.preferences.configobj.ConfigObj.reload (   self)

Reload a ConfigObj from file.

This method raises a ReloadError if the ConfigObj doesn't have a filename attribute pointing to a file.

Definition at line 2452 of file configobj.py.

◆ reset()

def robotide.preferences.configobj.ConfigObj.reset (   self)

Clear ConfigObj instance and restore to 'freshly created' state.

Definition at line 2436 of file configobj.py.

◆ validate()

def robotide.preferences.configobj.ConfigObj.validate (   self,
  validator,
  preserve_errors = False,
  copy = False,
  section = None 
)

Test the ConfigObj against a configspec.

It uses the validator object from validate.py.

To run validate on the current ConfigObj, call: ::

test = config.validate(validator)

(Normally having previously passed in the configspec when the ConfigObj was created - you can dynamically assign a dictionary of checks to the configspec attribute of a section though).

It returns True if everything passes, or a dictionary of pass/fails (True/False). If every member of a subsection passes, it will just have the value True. (It also returns False if all members fail).

In addition, it converts the values from strings to their native types if their checks pass (and stringify is set).

If preserve_errors is True (False is default) then instead of a marking a fail with a False, it will preserve the actual exception object. This can contain info about the reason for failure. For example the VdtValueTooSmallError indicates that the value supplied was too small. If a value (or section) is missing it will still be marked as False.

You must have the validate module to use preserve_errors=True.

You can then use the flatten_errors function to turn your nested results dictionary into a flattened list of failures - useful for displaying meaningful error messages.

Definition at line 2262 of file configobj.py.

◆ write()

def robotide.preferences.configobj.ConfigObj.write (   self,
  outfile = None,
  section = None 
)

Write the current ConfigObj as a file.

tekNico: FIXME: use StringIO instead of real files

filename = a.filename a.filename = 'test.ini' a.write() a.filename = filename a == ConfigObj('test.ini', raise_errors=True)

1

import os os.remove('test.ini')

Definition at line 2127 of file configobj.py.

Member Data Documentation

◆ _bools

robotide.preferences.configobj.ConfigObj._bools
staticprivate

Definition at line 1225 of file configobj.py.

◆ _errors

robotide.preferences.configobj.ConfigObj._errors
private

Definition at line 1396 of file configobj.py.

◆ _inspec

robotide.preferences.configobj.ConfigObj._inspec
private

Definition at line 1247 of file configobj.py.

◆ _keyword

robotide.preferences.configobj.ConfigObj._keyword
staticprivate

Definition at line 1103 of file configobj.py.

◆ _listvalueexp

robotide.preferences.configobj.ConfigObj._listvalueexp
staticprivate

Definition at line 1169 of file configobj.py.

◆ _multi_line_double

robotide.preferences.configobj.ConfigObj._multi_line_double
staticprivate

Definition at line 1211 of file configobj.py.

◆ _multi_line_single

robotide.preferences.configobj.ConfigObj._multi_line_single
staticprivate

Definition at line 1207 of file configobj.py.

◆ _nolistvalue

robotide.preferences.configobj.ConfigObj._nolistvalue
staticprivate

Definition at line 1184 of file configobj.py.

◆ _original_configspec

robotide.preferences.configobj.ConfigObj._original_configspec
private

Definition at line 1290 of file configobj.py.

◆ _sectionmarker

robotide.preferences.configobj.ConfigObj._sectionmarker
staticprivate

Definition at line 1119 of file configobj.py.

◆ _single_line_double

robotide.preferences.configobj.ConfigObj._single_line_double
staticprivate

Definition at line 1203 of file configobj.py.

◆ _single_line_single

robotide.preferences.configobj.ConfigObj._single_line_single
staticprivate

Definition at line 1199 of file configobj.py.

◆ _triple_quote

robotide.preferences.configobj.ConfigObj._triple_quote
staticprivate

Definition at line 1216 of file configobj.py.

◆ _valueexp

robotide.preferences.configobj.ConfigObj._valueexp
staticprivate

Definition at line 1139 of file configobj.py.

◆ _vdtMissingValue

robotide.preferences.configobj.ConfigObj._vdtMissingValue
private

Definition at line 2271 of file configobj.py.

◆ BOM

robotide.preferences.configobj.ConfigObj.BOM

BOM discovered self.BOM = True Don't need to remove BOM.

Definition at line 1406 of file configobj.py.

◆ configspec

robotide.preferences.configobj.ConfigObj.configspec

Definition at line 1336 of file configobj.py.

◆ create_empty

robotide.preferences.configobj.ConfigObj.create_empty

Definition at line 1400 of file configobj.py.

◆ default_encoding

robotide.preferences.configobj.ConfigObj.default_encoding

Definition at line 1405 of file configobj.py.

◆ encoding

robotide.preferences.configobj.ConfigObj.encoding

Definition at line 1404 of file configobj.py.

◆ file_error

robotide.preferences.configobj.ConfigObj.file_error

Definition at line 1401 of file configobj.py.

◆ filename

robotide.preferences.configobj.ConfigObj.filename

Definition at line 1296 of file configobj.py.

◆ final_comment

robotide.preferences.configobj.ConfigObj.final_comment

Definition at line 1412 of file configobj.py.

◆ indent_type

robotide.preferences.configobj.ConfigObj.indent_type

Definition at line 1403 of file configobj.py.

◆ initial_comment

robotide.preferences.configobj.ConfigObj.initial_comment

Definition at line 1411 of file configobj.py.

◆ interpolation

robotide.preferences.configobj.ConfigObj.interpolation

Definition at line 1398 of file configobj.py.

◆ list_values

robotide.preferences.configobj.ConfigObj.list_values

Definition at line 1399 of file configobj.py.

◆ newlines

robotide.preferences.configobj.ConfigObj.newlines

Definition at line 1359 of file configobj.py.

◆ raise_errors

robotide.preferences.configobj.ConfigObj.raise_errors

Definition at line 1397 of file configobj.py.

◆ stringify

robotide.preferences.configobj.ConfigObj.stringify

Definition at line 1402 of file configobj.py.

◆ unrepr

robotide.preferences.configobj.ConfigObj.unrepr

Definition at line 1409 of file configobj.py.

◆ write_empty_values

robotide.preferences.configobj.ConfigObj.write_empty_values

Definition at line 1408 of file configobj.py.


The documentation for this class was generated from the following file: