# HG changeset patch # User Jeff Hammel # Date 1332803415 25200 # Node ID 4fd88b1b08d5a020bf60b3922283e5de61da9ff1 # Parent b39e550402eaa367ef6c6a2badf3963fe755999f ABC-ing configuration providers diff -r b39e550402ea -r 4fd88b1b08d5 configuration/config.py --- a/configuration/config.py Mon Mar 26 15:55:05 2012 -0700 +++ b/configuration/config.py Mon Mar 26 16:10:15 2012 -0700 @@ -22,12 +22,33 @@ __all__ = ['Configuration', 'configuration_providers', 'types'] +### configuration providers for serialization/deserialization + configuration_providers = [] + +class ConfigurationProvider(object): + """ + abstract base class for configuration providers for + serialization/deserialization + """ + if json: class JSON(object): extensions = ['json'] def read(self, filename): return json.loads(file(filename).read()) + def write(self, config, filename): + if isinstance(filename, basestring): + f = file(filename, 'w') + newfile = True + else: + f = filename + newfile = False + try: + f.write(json.dumps(config)) + finally: + if newfile: + f.close() configuration_providers.append(JSON) if yaml: