Mercurial > hgrepos > Python > libs > ConfigMix
changeset 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 | 7ad6a49fc894 |
| children | 17af7a78710c |
| files | configmix/__init__.py configmix/ini.py |
| diffstat | 2 files changed, 26 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/configmix/__init__.py Thu Mar 10 17:33:23 2016 +0100 +++ b/configmix/__init__.py Wed Mar 16 12:41:57 2016 +0100 @@ -10,7 +10,7 @@ from __future__ import division, print_function, absolute_import -__version__ = "0.1" +__version__ = "0.2.dev0" import copy
--- 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
