An object to read, create, and write config files. More...
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 | |
An object to read, create, and write config files.
Definition at line 1098 of file configobj.py.
| 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.
| 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.
|
private |
Decode ASCII strings to unicode if a self.encoding is specified.
Definition at line 1555 of file configobj.py.
|
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.
|
private |
Decode element to unicode if necessary.
Definition at line 1592 of file configobj.py.
|
private |
Definition at line 1911 of file configobj.py.
|
private |
Definition at line 1921 of file configobj.py.
|
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.
|
private |
Deal with a comment.
Definition at line 2102 of file configobj.py.
|
private |
Parse the configspec.
Definition at line 2022 of file configobj.py.
|
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.
|
private |
Given a value string, unquote, remove comment, handle lists. (including empty and single member lists)
Definition at line 1937 of file configobj.py.
|
private |
Definition at line 1390 of file configobj.py.
|
private |
Definition at line 1294 of file configobj.py.
|
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.
|
private |
Extract the value, where we are in a multiline situation.
Definition at line 1985 of file configobj.py.
|
private |
Actually parse the config file.
Definition at line 1618 of file configobj.py.
|
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.
|
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.
|
private |
Used by ``stringify`` within validate, to turn non-string values into strings.
Definition at line 1606 of file configobj.py.
|
private |
Return an unquoted version of a value.
Definition at line 1829 of file configobj.py.
|
private |
Write an individual line, for the write method.
Definition at line 2075 of file configobj.py.
|
private |
Write a section marker line.
Definition at line 2091 of file configobj.py.
| 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.
| def robotide.preferences.configobj.ConfigObj.reset | ( | self | ) |
Clear ConfigObj instance and restore to 'freshly created' state.
Definition at line 2436 of file configobj.py.
| 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.
| 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.
|
staticprivate |
Definition at line 1225 of file configobj.py.
|
private |
Definition at line 1396 of file configobj.py.
|
private |
Definition at line 1247 of file configobj.py.
|
staticprivate |
Definition at line 1103 of file configobj.py.
|
staticprivate |
Definition at line 1169 of file configobj.py.
|
staticprivate |
Definition at line 1211 of file configobj.py.
|
staticprivate |
Definition at line 1207 of file configobj.py.
|
staticprivate |
Definition at line 1184 of file configobj.py.
|
private |
Definition at line 1290 of file configobj.py.
|
staticprivate |
Definition at line 1119 of file configobj.py.
|
staticprivate |
Definition at line 1203 of file configobj.py.
|
staticprivate |
Definition at line 1199 of file configobj.py.
|
staticprivate |
Definition at line 1216 of file configobj.py.
|
staticprivate |
Definition at line 1139 of file configobj.py.
|
private |
Definition at line 2271 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.BOM |
BOM discovered self.BOM = True Don't need to remove BOM.
Definition at line 1406 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.configspec |
Definition at line 1336 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.create_empty |
Definition at line 1400 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.default_encoding |
Definition at line 1405 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.encoding |
Definition at line 1404 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.file_error |
Definition at line 1401 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.filename |
Definition at line 1296 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.final_comment |
Definition at line 1412 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.indent_type |
Definition at line 1403 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.initial_comment |
Definition at line 1411 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.interpolation |
Definition at line 1398 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.list_values |
Definition at line 1399 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.newlines |
Definition at line 1359 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.raise_errors |
Definition at line 1397 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.stringify |
Definition at line 1402 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.unrepr |
Definition at line 1409 of file configobj.py.
| robotide.preferences.configobj.ConfigObj.write_empty_values |
Definition at line 1408 of file configobj.py.