Skip to content

Instantly share code, notes, and snippets.

@inirudebwoy
Forked from anonymous/SettingsReader.py
Created November 28, 2012 20:27
Show Gist options
  • Save inirudebwoy/ba419c5df789d1f65c4c to your computer and use it in GitHub Desktop.
Save inirudebwoy/ba419c5df789d1f65c4c to your computer and use it in GitHub Desktop.
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