Mercurial > hgrepos > Python > libs > ConfigMix
diff 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 |
line wrap: on
line diff
--- a/configmix/ini.py Thu Mar 10 17:33:23 2016 +0100 +++ b/configmix/ini.py Wed Mar 16 12:41:57 2016 +0100 @@ -107,6 +107,31 @@ u('false'): False, u('off'): False} + def itemsx(self, section, options): + """Get all the options given in `options` of section `section`. + Fetch them with `self.getx()` in the order given. + + Return a list of ``(name, value)`` pairs for each option in + `options` in the given `section`. + + """ + d = [] + for option in options: + try: + val = self.getx(section, option) + except (NoSectionError, NoOptionError): + pass + else: + d.append((option, val, )) + return d + + def items_as_dictx(self, section, options): + """Similar to `self.itemsx()` but return a (possibly ordered) + dict instead of a list of key-value pairs. + + """ + return DictImpl(self.itemsx(section, options)) + def load(filename, extract=["config"]): """Load a single INI file and read/interpolate the sections given in
