comparison configmix/ini.py @ 28:7c7955da42ab

An extended `itemsx()` method for INI-style configuration files to get interpreted selected options from a section
author Franz Glasner <f.glasner@feldmann-mg.com>
date Wed, 16 Mar 2016 12:41:57 +0100
parents ce290b10dac5
children aa8345dae995
comparison
equal deleted inserted replaced
27:7ad6a49fc894 28:7c7955da42ab
105 u('0'): False, 105 u('0'): False,
106 u('no'): False, 106 u('no'): False,
107 u('false'): False, 107 u('false'): False,
108 u('off'): False} 108 u('off'): False}
109 109
110 def itemsx(self, section, options):
111 """Get all the options given in `options` of section `section`.
112 Fetch them with `self.getx()` in the order given.
113
114 Return a list of ``(name, value)`` pairs for each option in
115 `options` in the given `section`.
116
117 """
118 d = []
119 for option in options:
120 try:
121 val = self.getx(section, option)
122 except (NoSectionError, NoOptionError):
123 pass
124 else:
125 d.append((option, val, ))
126 return d
127
128 def items_as_dictx(self, section, options):
129 """Similar to `self.itemsx()` but return a (possibly ordered)
130 dict instead of a list of key-value pairs.
131
132 """
133 return DictImpl(self.itemsx(section, options))
134
110 135
111 def load(filename, extract=["config"]): 136 def load(filename, extract=["config"]):
112 """Load a single INI file and read/interpolate the sections given in 137 """Load a single INI file and read/interpolate the sections given in
113 `extract`. 138 `extract`.
114 139