Last active
January 4, 2016 03:09
-
-
Save mattupstate/8559844 to your computer and use it in GitHub Desktop.
A helper function for grabbing pseudo-namespaced configuration options from a Flask application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def namespaced_config_options(app, prefix): | |
"""Returns a dictionary of configuration options built from | |
the specified Flask application and string prefix. Keys in the | |
resulting dictionary will be lowercase. | |
:param app: a Flask application | |
:param prefix: a configuration namespace prefix. e.g. `IMAGE_STORE` | |
""" | |
rv = {} | |
for key, value in app.config.iteritems(): | |
if not key.startswith(prefix): | |
continue | |
rv[key[len(prefix):].lower()] = value | |
return rv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment