<s> '''<STR_LIT>''' <EOL> from RESTfulResource import RESTfulResource <EOL> class Handler ( RESTfulResource ) : <EOL> def __init__ ( self , parentObject = None , resourceDescriptor = { } ) : <EOL> RESTfulResource . __init__ ( self , parentObject , resourceDescriptor ) <EOL> self . _settings = self . _resourceDescriptor <EOL> self . _linkBaseDict = self . Resources . get ( '<STR_LIT>' ) . resources <EOL> self . _linkCache = { } <EOL> self . _init ( ) <EOL> def _init ( self ) : <EOL> pass <EOL> def get ( self , Key = None ) : <EOL> if Key != None : <EOL> return self . _settings [ Key ] <EOL> else : <EOL> return self . _settings <EOL> def set ( self , newSettings ) : <EOL> self . _settings . update ( newSettings ) <EOL> def handleNotify ( self , updateRef = None ) : <EOL> self . _handleNotify ( updateRef ) <EOL> def _handleNotify ( self , updateRef = None ) : <EOL> pass <EOL> def linkToRef ( self , linkPath ) : <EOL> '''<STR_LIT>''' <EOL> self . _linkPath = linkPath <EOL> if self . _linkPath in self . _linkCache . keys ( ) : <EOL> return self . _linkCache [ self . _linkPath ] <EOL> self . _currentDict = self . _linkBaseDict <EOL> self . _pathElements = linkPath . split ( '<STR_LIT:/>' ) <EOL> for pathElement in self . _pathElements [ : - <NUM_LIT:1> ] : <EOL> self . _currentDict = self . _currentDict [ pathElement ] . resources <EOL> self . _resource = self . _currentDict [ self . _pathElements [ - <NUM_LIT:1> ] ] <EOL> self . _linkCache . update ( { self . _linkPath : self . _resource } ) <EOL> return self . _resource <EOL> def getByLink ( self , linkPath ) : <EOL> return self . linkToRef ( linkPath ) . get ( ) <EOL> def setByLink ( self , linkPath , newValue ) : <EOL> self . linkToRef ( linkPath ) . set ( newValue ) <EOL> class addHandler ( Handler ) : <EOL> def _handleNotify ( self , updateRef = None ) : <EOL> self . _addend1 = self . getByLink ( self . _settings [ '<STR_LIT>' ] ) <EOL> self . _addend2 = self . getByLink ( self . _settings [ '<STR_LIT>' ] ) <EOL> self . setByLink ( self . _settings [ '<STR_LIT>' ] , self . _addend1 + self . _addend2 ) <EOL> class logPrintHandler ( Handler ) : <EOL> def _handleNotify ( self , resource ) : <EOL> print resource . Properties . get ( '<STR_LIT>' ) , '<STR_LIT>' , resource . get ( ) <EOL> class Agent ( RESTfulResource ) : <EOL> def __init__ ( self , parentObject = None , resourceDescriptor = { } ) : <EOL> RESTfulResource . __init__ ( self , parentObject , resourceDescriptor ) <EOL> self . _handlers = { } <EOL> def get ( self , handlerName = None ) : <EOL> if handlerName == None : <EOL> return self . _handlers <EOL> else : <EOL> if self . _handlers . has_key ( handlerName ) : <EOL> return self . _handlers [ handlerName ] <EOL> return None <EOL> def create ( self , resourceDescriptor ) : <EOL> resourceName = resourceDescriptor [ '<STR_LIT>' ] <EOL> resourceClass = resourceDescriptor [ '<STR_LIT>' ] <EOL> if resourceDescriptor . has_key ( '<STR_LIT>' ) : <EOL> resourceClassPath = resourceDescriptor [ '<STR_LIT>' ] <EOL> self . importByPath ( resourceClassPath ) <EOL> if resourceName not in self . resources : <EOL> self . resources . update ( { resourceName : globals ( ) [ resourceClass ] ( self , resourceDescriptor ) } ) <EOL> self . _handlers . update ( { resourceName : resourceClass } ) <EOL> return self . resources [ resourceName ] <EOL> def importByPath ( self , classPath ) : <EOL> self . _components = classPath . split ( '<STR_LIT:.>' ) <EOL> self . _module = __import__ ( '<STR_LIT:.>' . join ( self . _components [ : - <NUM_LIT:1> ] ) ) <EOL> return self . _module </s>
