<s> from copy import copy <EOL> from stewbot . components . BaseClass import BaseClass <EOL> class Documentation ( BaseClass ) : <EOL> def __init__ ( self , tree , logger , default = None ) : <EOL> BaseClass . __init__ ( self , logger = logger ) <EOL> self . trace ( ) <EOL> self . tree = copy ( tree ) <EOL> self . default = default <EOL> class NoDefaultException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class NoSuchKeyException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , keys , default = None ) : <EOL> self . trace ( ) <EOL> if not len ( keys ) : <EOL> if default : <EOL> return default <EOL> elif self . default : <EOL> return self . default <EOL> elif self . tree [ None ] : <EOL> return self . tree [ None ] <EOL> else : <EOL> raise self . NoDefaultException , '<STR_LIT>' <EOL> subtree = self . tree <EOL> found = <NUM_LIT:0> <EOL> for key in keys : <EOL> key = key . lower ( ) . strip ( ) <EOL> try : <EOL> if key in subtree : <EOL> subtree = subtree [ key ] <EOL> found = <NUM_LIT:1> <EOL> continue <EOL> break <EOL> except TypeError : <EOL> break <EOL> if found : <EOL> try : <EOL> return subtree [ None ] <EOL> except TypeError : <EOL> return subtree <EOL> else : <EOL> raise self . NoSuchKeyException , '<STR_LIT>' </s>
