# HG changeset patch # User Jeff Hammel # Date 1332870694 25200 # Node ID 1bd4ddf2e81d6c9b9a0e7ad35cb06d9ada987279 # Parent 056280e7a6ea9632d06ddb8cda52f711a0869b5b deserialization should work now diff -r 056280e7a6ea -r 1bd4ddf2e81d configuration/config.py --- a/configuration/config.py Tue Mar 27 10:36:23 2012 -0700 +++ b/configuration/config.py Tue Mar 27 10:51:34 2012 -0700 @@ -29,6 +29,9 @@ class MissingValueException(Exception): """exception raised when a required value is missing""" +class ConfigurationProviderException(Exception): + """exception raised when a configuration provider is missing, etc""" + ### configuration providers for serialization/deserialization configuration_providers = [] @@ -325,7 +328,20 @@ """load configuration from a file""" # TODO: allow file object vs file name + # get the format if not format: - extension = os.path.splitext(filename)[-1] + format = self.filename2format(filename) + + # get the providers in some sensible order + providers = self.configuration_providers[:] + if format: + providers.sort(key=lambda x: int(format in x.extensions), reverse=True) - raise NotImplementedError("TODO") + # deserialize the data + for provider in providers: + try: + return provider.read(filename) + except: + continue + else: + raise ConfigurationProviderException("Could not load %s" % filename) diff -r 056280e7a6ea -r 1bd4ddf2e81d tests/unit.py --- a/tests/unit.py Tue Mar 27 10:36:23 2012 -0700 +++ b/tests/unit.py Tue Mar 27 10:51:34 2012 -0700 @@ -92,4 +92,3 @@ if __name__ == '__main__': unittest.main() -