# HG changeset patch # User Franz Glasner # Date 1458128517 -3600 # Node ID 7c7955da42ab0507d69eb5f3e8b821cb5f1b3800 # Parent 7ad6a49fc894cf0e2c671ecf4b40d494f9e73f96 An extended `itemsx()` method for INI-style configuration files to get interpreted selected options from a section diff -r 7ad6a49fc894 -r 7c7955da42ab configmix/__init__.py --- 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 diff -r 7ad6a49fc894 -r 7c7955da42ab configmix/ini.py --- 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