Don't use __getattr__ in config stores; use __getitem__ and talk to them using store[key] instead of getattr(store, key). Simpler and maybe faster (1 method lookup vs failed attribute lookup + method lookup).
This commit is contained in:
parent
5f81247353
commit
4dafba1270
|
@ -166,10 +166,10 @@ class TerminatorConfig:
|
||||||
for source in self.sources:
|
for source in self.sources:
|
||||||
dbg ("TConfig: Looking for: '%s' in '%s'"%(keyname, source.type))
|
dbg ("TConfig: Looking for: '%s' in '%s'"%(keyname, source.type))
|
||||||
try:
|
try:
|
||||||
val = getattr (source, keyname)
|
val = source[keyname]
|
||||||
dbg (" TConfig: got: '%s' from a '%s'"%(val, source.type))
|
dbg (" TConfig: got: '%s' from a '%s'"%(val, source.type))
|
||||||
return (val)
|
return (val)
|
||||||
except:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
dbg (" TConfig: Out of sources")
|
dbg (" TConfig: Out of sources")
|
||||||
|
@ -181,13 +181,13 @@ class TerminatorConfValuestore:
|
||||||
reconfigure_callback = None
|
reconfigure_callback = None
|
||||||
|
|
||||||
# Our settings
|
# Our settings
|
||||||
def __getattr__ (self, keyname):
|
def __getitem__ (self, keyname):
|
||||||
if self.values.has_key (keyname):
|
if self.values.has_key (keyname):
|
||||||
dbg ("Returning '%s'"%keyname)
|
dbg ("Returning '%s'"%keyname)
|
||||||
return self.values[keyname]
|
return self.values[keyname]
|
||||||
else:
|
else:
|
||||||
dbg ("Failed to find '%s'"%keyname)
|
dbg ("Failed to find '%s'"%keyname)
|
||||||
raise (AttributeError)
|
raise (KeyError)
|
||||||
|
|
||||||
class TerminatorConfValuestoreDefault (TerminatorConfValuestore):
|
class TerminatorConfValuestoreDefault (TerminatorConfValuestore):
|
||||||
def __init__ (self):
|
def __init__ (self):
|
||||||
|
@ -313,7 +313,7 @@ class TerminatorConfValuestoreGConf (TerminatorConfValuestore):
|
||||||
if self.reconfigure_callback:
|
if self.reconfigure_callback:
|
||||||
self.reconfigure_callback ()
|
self.reconfigure_callback ()
|
||||||
|
|
||||||
def __getattr__ (self, key = ""):
|
def __getitem__ (self, key = ""):
|
||||||
if self.cache.has_key (key):
|
if self.cache.has_key (key):
|
||||||
dbg (" VSGConf: returning cached value: %s"%self.cache[key])
|
dbg (" VSGConf: returning cached value: %s"%self.cache[key])
|
||||||
return (self.cache[key])
|
return (self.cache[key])
|
||||||
|
@ -362,7 +362,7 @@ class TerminatorConfValuestoreGConf (TerminatorConfValuestore):
|
||||||
self.cache[key] = ret
|
self.cache[key] = ret
|
||||||
return (ret)
|
return (ret)
|
||||||
else:
|
else:
|
||||||
raise (AttributeError)
|
raise (KeyError)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue