comparison martini/config.py @ 10:66d11212175d

this should be ordered too
author Jeff Hammel <k0scist@gmail.com>
date Tue, 23 Aug 2016 09:26:27 -0700
parents 77c7556fa8e0
children c77259f467a3
comparison
equal deleted inserted replaced
9:77c7556fa8e0 10:66d11212175d
31 return StringIO(resource) 31 return StringIO(resource)
32 32
33 33
34 class ConfigMunger(ConfigParser): 34 class ConfigMunger(ConfigParser):
35 """combine configuration from .ini files""" 35 """combine configuration from .ini files"""
36 36
37 def __init__(self, *conf, **kw): 37 def __init__(self, *conf, **kw):
38 ConfigParser.__init__(self, defaults=kw.get('defaults',{}), 38 ConfigParser.__init__(self, defaults=kw.get('defaults',{}),
39 dict_type=OrderedDict) 39 dict_type=OrderedDict)
40 self.optionxform = str 40 self.optionxform = str
41 self.read(*conf) 41 self.read(*conf)
42 42
43 def __getitem__(self, section): 43 def __getitem__(self, section):
44 """ 44 """
45 return an object with __getitem__ defined appropriately 45 return an object with __getitem__ defined appropriately
46 to allow referencing like self['foo']['bar'] 46 to allow referencing like self['foo']['bar']
47 """ 47 """
48 return dict(self.items(section)) 48 return OrderedDict(self.items(section))
49 49
50 def get(self, section, option, default=None, raw=False, vars=None): 50 def get(self, section, option, default=None, raw=False, vars=None):
51 try: 51 try:
52 value = ConfigParser.get(self, section, option, raw, vars) 52 value = ConfigParser.get(self, section, option, raw, vars)
53 except NoOptionError: 53 except NoOptionError: