Browse Source

Base from_json on from_mapping

pull/1136/head
Daniel Neuhäuser 11 years ago
parent
commit
486c1089b0
  1. 10
      flask/config.py

10
flask/config.py

@ -167,8 +167,8 @@ class Config(dict):
def from_json(self, filename, silent=False): def from_json(self, filename, silent=False):
"""Updates the values in the config from a JSON file. This function """Updates the values in the config from a JSON file. This function
behaves as if the JSON object was a dictionary and passed ot the behaves as if the JSON object was a dictionary and passed to the
:meth:`from_object` function. :meth:`from_mapping` function.
:param filename: the filename of the JSON file. This can either be an :param filename: the filename of the JSON file. This can either be an
absolute filename or a filename relative to the absolute filename or a filename relative to the
@ -188,10 +188,7 @@ class Config(dict):
return False return False
e.strerror = 'Unable to load configuration file (%s)' % e.strerror e.strerror = 'Unable to load configuration file (%s)' % e.strerror
raise raise
for key in obj.keys(): return self.from_mapping(obj)
if key.isupper():
self[key] = obj[key]
return True
def from_mapping(self, *mapping, **kwargs): def from_mapping(self, *mapping, **kwargs):
"""Updates the config like :meth:`update` ignoring items with non-upper """Updates the config like :meth:`update` ignoring items with non-upper
@ -214,6 +211,7 @@ class Config(dict):
for (key, value) in mapping: for (key, value) in mapping:
if key.isupper(): if key.isupper():
self[key] = value self[key] = value
return True
def get_namespace(self, namespace, lowercase=True): def get_namespace(self, namespace, lowercase=True):
"""Returns a dictionary containing a subset of configuration options """Returns a dictionary containing a subset of configuration options

Loading…
Cancel
Save