-
-
Save inirudebwoy/ba419c5df789d1f65c4c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class SettingsReader: | |
def __init__(self, opts, config, settings): | |
self.opts = opts | |
self.config = config | |
self.settings = settings | |
def __contains__(self, key): | |
if (key in self.opts or | |
key in self.config or | |
key in self.settings): | |
return True | |
return False | |
def __getitem__(self, key): | |
try: | |
for config in (self.opts, self.config, self.settings): | |
if key in config: | |
return config.get(key) | |
except MissingParamException: | |
raise | |
def get(self, key, function=lambda: None): | |
try: | |
return self[key] | |
except MissingParamException: | |
pass | |
return function() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment