Mercurial > hg > pyloader
comparison pyloader/factory.py @ 96:9dbdcb1adca1 default tip
py3
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Tue, 03 Nov 2020 10:49:55 -0800 |
parents | 1a8b151888da |
children |
comparison
equal
deleted
inserted
replaced
95:1a8b151888da | 96:9dbdcb1adca1 |
---|---|
21 from configparser import InterpolationDepthError | 21 from configparser import InterpolationDepthError |
22 from configparser import InterpolationMissingOptionError | 22 from configparser import InterpolationMissingOptionError |
23 from configparser import InterpolationSyntaxError | 23 from configparser import InterpolationSyntaxError |
24 from configparser import SafeConfigParser as ConfigParser | 24 from configparser import SafeConfigParser as ConfigParser |
25 | 25 |
26 try: | |
27 string = (str, basestring) | |
28 except NameError: | |
29 string = (str,) | |
30 | |
26 | 31 |
27 __all__ = ['CircularReferenceError', 'PyFactory', 'IniFactory'] | 32 __all__ = ['CircularReferenceError', 'PyFactory', 'IniFactory'] |
28 | 33 |
29 | 34 |
30 class CircularReferenceError(Exception): | 35 class CircularReferenceError(Exception): |
92 return self.parsed[name] | 97 return self.parsed[name] |
93 | 98 |
94 def interpolate(self, value): | 99 def interpolate(self, value): |
95 | 100 |
96 # only interpolate strings | 101 # only interpolate strings |
97 if not isinstance(value, basestring): | 102 if not isinstance(value, string): |
98 return value | 103 return value |
99 | 104 |
100 if value.startswith(self.delimeters[0]) and value.endswith(self.delimeters[1]): | 105 if value.startswith(self.delimeters[0]) and value.endswith(self.delimeters[1]): |
101 value = value[len(self.delimeters[0]):-len(self.delimeters[1])] | 106 value = value[len(self.delimeters[0]):-len(self.delimeters[1])] |
102 if value in self.config: | 107 if value in self.config: |
282 return cls.configuration(config, **parser.defaults()) | 287 return cls.configuration(config, **parser.defaults()) |
283 | 288 |
284 | 289 |
285 def main(args=sys.argv[1:]): | 290 def main(args=sys.argv[1:]): |
286 """command line entry point""" | 291 """command line entry point""" |
292 | |
287 usage = '%prog file1.ini -arg1 -arg2 --key1=value1 --key2=value2' | 293 usage = '%prog file1.ini -arg1 -arg2 --key1=value1 --key2=value2' |
288 parser = OptionParser(usage=usage, description=IniFactory.__doc__) | 294 parser = OptionParser(usage=usage, description=IniFactory.__doc__) |
289 options, args = parser.parse_args(args) | 295 options, args = parser.parse_args(args) |
290 | 296 |
291 if len(args) != 1: | 297 if len(args) != 1: |