def subscribe(self, func, uri=None): ''' \brief Adds a subscriber to the event bus. The given function pointer passed is called whenever an event is sent that matches the given regular expression. If no regular expression was given, the function is called for any emitted signal. \param func The function to call. \param uri The URI trigger this fuction to be called. \returns The unique identifier of this registration, an int. The caller can store and use that ID to unsubscribe. ''' # log log.info("adding subscriber: {0} -> {1}".format( uri, func, ) ) # param validation assert callable(func) if uri: assert isinstance(uri,str) # create the Subscription instance subs = Subscription.Subscription(func,uri) # get a unique ID for that subscriber id = self._getNextId() # store subs try: self._dataLock.acquire() self._subscriptions[id] = subs finally: self._dataLock.release() return id
from Subscription import * from Connection import * import os.path passfile = "pass.txt" # Simple program to use cryptography. if(os.path.exists(passfile)): connection = Connection(passfile) else: subscription = Subscription(passfile)