A dictionary-like object that represents a section in a config file. More...
Public Member Functions | |
| 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 | __repr__ (self) |
| x.__repr__() <==> repr(x) More... | |
| 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 | |
| comments | |
| configspec | |
| default_values | |
| defaults | |
| depth | |
| extra_values | |
| inline_comments | |
| main | |
| name | |
| parent | |
| scalars | |
| sections | |
Private Member Functions | |
| def | _initialise (self) |
| def | _interpolate (self, key, value) |
Private Attributes | |
| _created | |
| _interpolation_engine | |
Static Private Attributes | |
| __doc__ | |
| def | __iter__ = iterkeys |
| def | __str__ = __repr__ |
A dictionary-like object that represents a section in a config file.
It does string interpolation if the 'interpolation' attribute of the 'main' object is set to True.
Interpolation is tried first from this object, then from the 'DEFAULT' section of this object, next from the parent and its 'DEFAULT' section, and so on until the main object is reached.
A Section will behave like an ordered dictionary - following the order of the scalars and sections attributes. You can use this to change the order of members.
Iteration follows the order: scalars, then sections.
Definition at line 500 of file configobj.py.
| def robotide.preferences.configobj.Section.__init__ | ( | self, | |
| parent, | |||
| depth, | |||
| main, | |||
indict = None, |
|||
name = None |
|||
| ) |
Definition at line 518 of file configobj.py.
| def robotide.preferences.configobj.Section.__delitem__ | ( | self, | |
| key | |||
| ) |
Remove items from the sequence when deleting.
Definition at line 655 of file configobj.py.
| def robotide.preferences.configobj.Section.__getitem__ | ( | self, | |
| key | |||
| ) |
Fetch the item and do string interpolation.
Definition at line 579 of file configobj.py.
| def robotide.preferences.configobj.Section.__reduce__ | ( | self | ) |
Definition at line 507 of file configobj.py.
| def robotide.preferences.configobj.Section.__repr__ | ( | self | ) |
x.__repr__() <==> repr(x)
Reimplemented in robotide.preferences.configobj.ConfigObj.
Definition at line 768 of file configobj.py.
| def robotide.preferences.configobj.Section.__setitem__ | ( | self, | |
| key, | |||
| value, | |||
unrepr = False |
|||
| ) |
Correctly set a value.
Making dictionary values Section instances. (We have to special case 'Section' instances - which are also dicts)
Keys must be strings. Values need only be strings (or lists of strings) if main.stringify is set.
unrepr must be set when setting a value to a dictionary, without creating a new sub-section.
Definition at line 608 of file configobj.py.
| def robotide.preferences.configobj.Section.__setstate__ | ( | self, | |
| state | |||
| ) |
Definition at line 503 of file configobj.py.
|
private |
Definition at line 538 of file configobj.py.
|
private |
Definition at line 555 of file configobj.py.
| def robotide.preferences.configobj.Section.as_bool | ( | self, | |
| key | |||
| ) |
Accepts a key as input.
The corresponding value must be a string or the objects (True or 1) or (False or 0). We allow 0 and 1 to retain compatibility with Python 2.2.
If the string is one of True, On, Yes, or 1 it returns True.
If the string is one of False, Off, No, or 0 it returns False.
as_bool is not case sensitive.
Any other input will raise a ValueError.
a = ConfigObj() a['a'] = 'fish' a.as_bool('a')
Traceback (most recent call last): ValueError: Value "fish" is neither True nor False
a['b'] = 'True' a.as_bool('b')
1
a['b'] = 'off' a.as_bool('b')
0
Definition at line 980 of file configobj.py.
| def robotide.preferences.configobj.Section.as_float | ( | self, | |
| key | |||
| ) |
A convenience method which coerces the specified value to a float.
If the value is an invalid literal for float, a ValueError will be raised.
a = ConfigObj() a['a'] = 'fish' a.as_float('a') #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last): ValueError: invalid literal for float(): fish
a['b'] = '1' a.as_float('b')
1.0
a['b'] = '3.2' a.as_float('b') #doctest: +ELLIPSIS
3.2...
Definition at line 1038 of file configobj.py.
| def robotide.preferences.configobj.Section.as_int | ( | self, | |
| key | |||
| ) |
A convenience method which coerces the specified value to an integer.
If the value is an invalid literal for int, a ValueError will be raised.
a = ConfigObj() a['a'] = 'fish' a.as_int('a')
Traceback (most recent call last): ValueError: invalid literal for int() with base 10: 'fish'
a['b'] = '1' a.as_int('b')
1
a['b'] = '3.2' a.as_int('b')
Traceback (most recent call last): ValueError: invalid literal for int() with base 10: '3.2'
Definition at line 1016 of file configobj.py.
| def robotide.preferences.configobj.Section.as_list | ( | self, | |
| key | |||
| ) |
A convenience method which fetches the specified value, guaranteeing that it is a list.
a = ConfigObj() a['a'] = 1 a.as_list('a')
[1]
a['a'] = (1,) a.as_list('a')
[1]
a['a'] = [1] a.as_list('a')
[1]
Definition at line 1057 of file configobj.py.
| def robotide.preferences.configobj.Section.clear | ( | self | ) |
A version of clear that also affects scalars/sections Also clears comments and configspec.
Leaves other attributes alone : depth/main/parent are not affected
Definition at line 715 of file configobj.py.
| def robotide.preferences.configobj.Section.dict | ( | self | ) |
Return a deepcopy of self as a dictionary.
All members that are Section instances are recursively turned to ordinary dictionaries - by calling their dict method.
n = a.dict() n == a
1
n is a
0
Definition at line 795 of file configobj.py.
| def robotide.preferences.configobj.Section.get | ( | self, | |
| key, | |||
default = None |
|||
| ) |
A version of get that doesn't bypass string interpolation.
Definition at line 666 of file configobj.py.
| def robotide.preferences.configobj.Section.items | ( | self | ) |
D.items() -> list of D's (key, value) pairs, as 2-tuples.
Definition at line 736 of file configobj.py.
| def robotide.preferences.configobj.Section.iteritems | ( | self | ) |
D.iteritems() -> an iterator over the (key, value) items of D.
Definition at line 751 of file configobj.py.
| def robotide.preferences.configobj.Section.iterkeys | ( | self | ) |
D.iterkeys() -> an iterator over the keys of D.
Definition at line 756 of file configobj.py.
| def robotide.preferences.configobj.Section.itervalues | ( | self | ) |
D.itervalues() -> an iterator over the values of D.
Definition at line 763 of file configobj.py.
| def robotide.preferences.configobj.Section.keys | ( | self | ) |
D.keys() -> list of D's keys.
Definition at line 741 of file configobj.py.
| def robotide.preferences.configobj.Section.merge | ( | self, | |
| indict | |||
| ) |
A recursive update - useful for merging config files.
a = '''[section1]
... option1 = True ... [[subsection]] ... more_options = False ... # end of file'''.splitlines()
b = '''# File is user.ini
... [section1] ... option1 = False ... # end of file'''.splitlines()
c1 = ConfigObj(b) c2 = ConfigObj(a) c2.merge(c1) c2
ConfigObj({'section1': {'option1': 'False', 'subsection': {'more_options': 'False'}}})
Definition at line 829 of file configobj.py.
| def robotide.preferences.configobj.Section.pop | ( | self, | |
| key, | |||
default = MISSING |
|||
| ) |
'D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised'
Definition at line 685 of file configobj.py.
| def robotide.preferences.configobj.Section.popitem | ( | self | ) |
Pops the first (key,val)
Definition at line 698 of file configobj.py.
| def robotide.preferences.configobj.Section.rename | ( | self, | |
| oldkey, | |||
| newkey | |||
| ) |
Change a keyname to another, without changing position in sequence.
Implemented so that transformations can be made on keys, as well as on values. (used by encode and decode)
Also renames comments.
Definition at line 846 of file configobj.py.
| def robotide.preferences.configobj.Section.restore_default | ( | self, | |
| key | |||
| ) |
Restore (and return) default value for the specified key.
This method will only work for a ConfigObj that was created with a configspec and has been validated.
If there is no default value for this key, KeyError is raised.
Definition at line 1072 of file configobj.py.
| def robotide.preferences.configobj.Section.restore_defaults | ( | self | ) |
Recursively restore default values to all members that have them.
This method will only work for a ConfigObj that was created with a configspec and has been validated.
It doesn't delete or modify entries without default values.
Definition at line 1089 of file configobj.py.
| def robotide.preferences.configobj.Section.setdefault | ( | self, | |
| key, | |||
default = None |
|||
| ) |
A version of setdefault that sets sequence if appropriate.
Definition at line 727 of file configobj.py.
| def robotide.preferences.configobj.Section.update | ( | self, | |
| indict | |||
| ) |
A version of update that uses our __setitem__.
Definition at line 676 of file configobj.py.
| def robotide.preferences.configobj.Section.values | ( | self | ) |
D.values() -> list of D's values.
Definition at line 746 of file configobj.py.
| def robotide.preferences.configobj.Section.walk | ( | self, | |
| function, | |||
raise_errors = True, |
|||
call_on_sections = False, |
|||
| ** | keywargs | ||
| ) |
Walk every member and call a function on the keyword and value.
Return a dictionary of the return values
If the function raises an exception, raise the errror unless raise_errors=False, in which case set the return value to False.
Any unrecognised keyword arguments you pass to walk, will be pased on to the function you pass in.
Note: if call_on_sections is True then - on encountering a subsection, first the function is called for the whole subsection, and then recurses into it's members. This means your function must be able to handle strings, dictionaries and lists. This allows you to change the key of subsections as well as for ordinary members. The return value when called on the whole subsection has to be discarded.
See the encode and decode methods for examples, including functions.
.. admonition:: caution
You can use ``walk`` to transform the names of members of a section but you mustn't add or delete members.
config = '''[XXXXsection]
... XXXXkey = XXXXvalue'''.splitlines()
cfg = ConfigObj(config) cfg
ConfigObj({'XXXXsection': {'XXXXkey': 'XXXXvalue'}})
def transform(section, key):
... val = section[key] ... newkey = key.replace('XXXX', 'CLIENT1') ... section.rename(key, newkey) ... if isinstance(val, (tuple, list, dict)): ... pass ... else: ... val = val.replace('XXXX', 'CLIENT1') ... section[newkey] = val
cfg.walk(transform, call_on_sections=True)
{'CLIENT1section': {'CLIENT1key': None}}
cfg
ConfigObj({'CLIENT1section': {'CLIENT1key': 'CLIENT1value'}})
Definition at line 913 of file configobj.py.
|
staticprivate |
Definition at line 778 of file configobj.py.
|
staticprivate |
Definition at line 759 of file configobj.py.
|
staticprivate |
Definition at line 777 of file configobj.py.
|
private |
Definition at line 552 of file configobj.py.
|
private |
Definition at line 573 of file configobj.py.
| robotide.preferences.configobj.Section.comments |
Definition at line 544 of file configobj.py.
| robotide.preferences.configobj.Section.configspec |
Definition at line 547 of file configobj.py.
| robotide.preferences.configobj.Section.default_values |
Definition at line 550 of file configobj.py.
| robotide.preferences.configobj.Section.defaults |
Definition at line 549 of file configobj.py.
| robotide.preferences.configobj.Section.depth |
Definition at line 527 of file configobj.py.
| robotide.preferences.configobj.Section.extra_values |
Definition at line 551 of file configobj.py.
| robotide.preferences.configobj.Section.inline_comments |
Definition at line 545 of file configobj.py.
| robotide.preferences.configobj.Section.main |
Definition at line 525 of file configobj.py.
| robotide.preferences.configobj.Section.name |
Definition at line 529 of file configobj.py.
| robotide.preferences.configobj.Section.parent |
Definition at line 523 of file configobj.py.
| robotide.preferences.configobj.Section.scalars |
Definition at line 540 of file configobj.py.
| robotide.preferences.configobj.Section.sections |
Definition at line 542 of file configobj.py.