<s> '''<STR_LIT>''' <EOL> from RESTfulResource import RESTfulResource <EOL> from urlparse import urlparse <EOL> class Observers ( RESTfulResource ) : <EOL> def __init__ ( self ) : <EOL> RESTfulResource . __init__ ( self ) <EOL> self . __schemes = [ '<STR_LIT:http>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . __observers = [ ] <EOL> def onUpdate ( self , resource ) : <EOL> self . __onUpdate ( resource ) <EOL> def __onUpdate ( self , resource ) : <EOL> for self . __observer in self . __observers : <EOL> self . __notify ( self . __observer , resource ) <EOL> def __notify ( self , observer , resource ) : <EOL> if type ( observer ) is not callable : <EOL> urlObject = urlparse ( observer ) <EOL> if urlObject . scheme == '<STR_LIT:http>' : <EOL> self . __httpNotify ( observer , resource ) <EOL> elif urlObject . scheme == '<STR_LIT>' : <EOL> self . __coapNotify ( observer , resource ) <EOL> elif urlObject . scheme == '<STR_LIT>' : <EOL> self . __callbackNotify ( observer , resource ) <EOL> else : <EOL> observer ( resource ) <EOL> def __httpNotify ( self , targetURI , resource ) : <EOL> print '<STR_LIT>' <EOL> def __coapNotify ( self , targetURI , resource ) : <EOL> print '<STR_LIT>' <EOL> def __callbackNotify ( self , observer , resource ) : <EOL> print '<STR_LIT>' <EOL> def get ( self , targetURI = None ) : <EOL> if targetURI != None : <EOL> if targetURI in self . __observers : <EOL> return targetURI <EOL> return None <EOL> return self . __observers <EOL> def set ( self , targetURI ) : <EOL> self . create ( targetURI ) <EOL> def create ( self , targetURI ) : <EOL> if urlparse ( targetURI ) . scheme not in self . __schemes : <EOL> return None <EOL> if targetURI not in self . __observers : <EOL> self . __observers . append ( targetURI ) <EOL> return targetURI <EOL> def delete ( self , targetURI ) : <EOL> if targetURI in self . __observers : <EOL> self . __observers . remove ( targetURI ) <EOL> return targetURI <EOL> return None </s>
