<s> '''<STR_LIT>''' <EOL> from RESTfulResource import RESTfulResource <EOL> class AppHandler ( object ) : <EOL> def __init__ ( self , linkBaseDict = None ) : <EOL> if linkBaseDict is None : <EOL> try : <EOL> import __builtin__ <EOL> self . linkBaseDict = __builtin__ . eval ( '<STR_LIT>' ) <EOL> except AttributeError : <EOL> print '<STR_LIT>' <EOL> else : <EOL> self . linkBaseDict = linkBaseDict <EOL> self . _propertyLinks = { } <EOL> self . _linkCache = { } <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:0> : - <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> def _updateHandler ( self , updateRef = None ) : <EOL> pass <EOL> class additionHandler ( AppHandler ) : <EOL> def __init__ ( self ) : <EOL> AppHandler . __init__ ( self ) <EOL> self . _addend1Link = None <EOL> self . _addend2Link = None <EOL> self . _sumOutLink = None <EOL> self . _propertyLinks = { '<STR_LIT>' : self . _addend1Link , <EOL> '<STR_LIT>' : self . _addend2Link , <EOL> '<STR_LIT>' : self . _sumOutLink <EOL> } <EOL> def _updateHandler ( self , updateRef = None ) : <EOL> '''<STR_LIT>''' <EOL> self . _addend1 = self . getByLink ( self . _addend1Link ) <EOL> self . _addend2 = self . getByLink ( self . _addend2Link ) <EOL> self . setByLink ( self . _sumOutLink , self . _addend1 + self . _addend2 ) <EOL> class RESTfulEndpoint ( object ) : <EOL> def __init__ ( self , reference ) : <EOL> self . _resource = reference <EOL> def get ( self ) : <EOL> return self . _resource <EOL> def set ( self , newValue ) : <EOL> self . _resource = newValue <EOL> return <EOL> class Handler ( RESTfulResource ) : <EOL> def __init__ ( self ) : <EOL> RESTfulResource . __init__ ( self ) <EOL> self . _propertyLinks = None <EOL> self . _appHandlerName = None <EOL> self . _updateHandler = None <EOL> def importByName ( self , classPath ) : <EOL> module = __import__ ( classPath ) <EOL> components = classPath . split ( '<STR_LIT:.>' ) <EOL> for component in components [ <NUM_LIT:1> : ] : <EOL> module = getattr ( module , component ) <EOL> return module <EOL> def appHandlerName ( self ) : <EOL> return self . _appHandlerName <EOL> def propertyLinks ( self ) : <EOL> return self . _propertyLinks <EOL> def updateHandler ( self ) : <EOL> return self . _updateHandler <EOL> def get ( self ) : <EOL> return self . _appHandlerName <EOL> def set ( self , appHandlerName ) : <EOL> self . _appHandlerName = appHandlerName <EOL> self . _appHandlerClass = self . importByName ( appHandlerName ) <EOL> self . _appHandler = self . _appHandlerClass ( ) <EOL> self . resources . update ( { '<STR_LIT>' : RESTfulEndpoint ( self . _appHandlerName ) } ) <EOL> if hasattr ( self . _appHandler , '<STR_LIT>' ) : <EOL> self . _propertyLinks = self . _appHandler . _propertyLinks <EOL> self . resources . update ( { '<STR_LIT>' : RESTfulEndpoint ( self . _propertyLinks ) } ) <EOL> for self . _propertyLinkName in self . _propertyLinks . keys ( ) : <EOL> self . resources . update ( { self . _propertyLinkName : RESTfulEndpoint ( self . _propertyLinks [ self . _propertyLinkName ] ) } ) <EOL> if hasattr ( self . appHandler , '<STR_LIT>' ) : <EOL> self . _updateHandler = self . _appHandler . _updateHandler <EOL> class Agent ( RESTfulResource ) : <EOL> def __init__ ( self ) : <EOL> RESTfulResource . __init__ ( self ) <EOL> self . defaultClass = '<STR_LIT>' <EOL> self . _handlers = { } <EOL> def get ( self , handlerName = None ) : <EOL> if handlerName == None : <EOL> return self . _handlers . keys ( ) <EOL> else : <EOL> if self . _handlers . has_key ( handlerName ) : <EOL> return self . _handlers [ handlerName ] <EOL> return None <EOL> def create ( self , resourceName , className = None ) : <EOL> if className == None : <EOL> if resourceName in self . wellKnownClasses : <EOL> className = resourceName <EOL> else : <EOL> className = self . defaultClass <EOL> self . resources . update ( { resourceName : globals ( ) [ className ] ( ) } ) <EOL> if className == self . defaultClass : <EOL> self . _handlers . update ( { resourceName , self . resources [ resourceName ] } ) <EOL> return self . resources [ resourceName ] </s>
