Exemplo n.º 1
0
def load_json(filename):
    """Add the contents of the JSON file to the config object, overwriting
    the existing key on name collisions.
    """
    try:
        config_file = open(filename)

        settings = json.loads(decomment_json(config_file.read()))
        set_from_dict(settings)

        config_file.close()

    except ValueError:
        raise ConfigParseError(filename)
    except IOError:
        raise ConfigLoadError(filename)
Exemplo n.º 2
0
def load_json(filename):
    """Add the contents of the JSON file to the config object, overwriting
    the existing key on name collisions.
    """
    try:
        config_file = open(filename)
        settings = json.loads(decomment_json(config_file.read()))

        for k, v in settings.iteritems():
            setattr(config, k, v)

    except ValueError:
        # The message they'll get here is singularly useless. Herp derp, there's
        # an error somewhere in your file. Good luck!
        raise ConfigParseError(filename)
    except IOError:
        raise ConfigLoadError(filename)
    finally:
        config_file.close()