Ejemplo n.º 1
0
    def track(self, obj, sessid, fieldname, trackerclass, *args, **kwargs):
        """
        Create an OOB obj of class _oob_MAPPING[tracker_key] on obj. args,
        kwargs will be used to initialize the OOB hook  before adding
        it to obj.
        If property_key is not given, but the OOB has a class property
        property_name, this will be used as the property name when assigning
        the OOB to obj, otherwise tracker_key is used as the property name.
        """
        try:
            obj = obj.dbobj
        except AttributeError:
            pass

        if not "_trackerhandler" in _GA(obj, "__dict__"):
            # assign trackerhandler to object
            _SA(obj, "_trackerhandler", TrackerHandler(obj))
        # initialize object
        tracker = trackerclass(self, fieldname, sessid, *args, **kwargs)
        _GA(obj, "_trackerhandler").add(fieldname, tracker)
        # store calling arguments as a pickle for retrieval later
        obj_packed = pack_dbobj(obj)
        storekey = (obj_packed, sessid, fieldname)
        stored = (obj_packed, sessid, fieldname, trackerclass,  args, kwargs)
        self.oob_tracker_storage[storekey] = stored
Ejemplo n.º 2
0
 def _store_key(self, obj, interval, idstring=""):
     """
     Tries to create a store_key for the object.
     Returns a tuple (isdb, store_key) where isdb
     is a boolean True if obj was a database object,
     False otherwise.
     """
     try:
         obj = obj.typeclass
     except AttributeError:
         pass
     dbobj = None
     try:
         dbobj = obj.dbobj
     except AttributeError:
         pass
     isdb = True
     if dbobj:
         # create a store_key using the database representation
         objkey = pack_dbobj(dbobj)
     else:
         # non-db object, look for a property "key" on it, otherwise
         # use its memory location.
         try:
             objkey = _GA(obj, "key")
         except AttributeError:
             objkey = id(obj)
         isdb = False
     # return sidb and store_key
     return isdb, (objkey, interval, idstring)
Ejemplo n.º 3
0
    def _track(self, obj, sessid, propname, trackerclass, *args, **kwargs):
        """
        Create an OOB obj of class _oob_MAPPING[tracker_key] on obj. args,
        kwargs will be used to initialize the OOB hook  before adding
        it to obj.
        If propname is not given, but the OOB has a class property
        named as propname, this will be used as the property name when assigning
        the OOB to obj, otherwise tracker_key is used as the property name.
        """
        try:
            obj = obj.dbobj
        except AttributeError:
            pass

        if not "_trackerhandler" in _GA(obj, "__dict__"):
            # assign trackerhandler to object
            _SA(obj, "_trackerhandler", TrackerHandler(obj))
        # initialize object
        tracker = trackerclass(self, propname, sessid, *args, **kwargs)
        _GA(obj, "_trackerhandler").add(propname, tracker)
        # store calling arguments as a pickle for retrieval later
        obj_packed = pack_dbobj(obj)
        storekey = (obj_packed, sessid, propname)
        stored = (obj_packed, sessid, propname, trackerclass, args, kwargs)
        self.oob_tracker_storage[storekey] = stored
Ejemplo n.º 4
0
 def unrepeat(self, obj, sessid, func_key, interval=20):
     """
     Stop a repeating action
     """
     try:
         obj = obj.dbobj
     except AttributeError:
         pass
     store_key = (pack_dbobj(obj), sessid, func_key, interval)
     self.oob_tracker_pool.remove(store_key, interval)
     self.oob_repeat_storage.pop(store_key, None)
Ejemplo n.º 5
0
 def repeat(self, obj, sessid, func_key, interval=20, *args, **kwargs):
     """
     Start a repeating action. Every interval seconds,
     the oobfunc corresponding to func_key is called with
     args and kwargs.
     """
     if not func_key in _OOB_FUNCS:
         raise KeyError("%s is not a valid OOB function name.")
     try:
         obj = obj.dbobj
     except AttributeError:
         pass
     store_obj = pack_dbobj(obj)
     store_key = (store_obj, sessid, func_key, interval)
     # prepare to store
     self.oob_repeat_storage[store_key] = (store_obj, sessid, func_key, interval, args, kwargs)
     self.oob_tracker_pool.add(store_key, sessid, func_key, interval, *args, **kwargs)
Ejemplo n.º 6
0
 def _untrack(self, obj, sessid, propname, trackerclass, *args, **kwargs):
     """
     Remove the OOB from obj. If oob implements an
     at_delete hook, this will be called with args, kwargs
     """
     try:
         obj = obj.dbobj
     except AttributeError:
         pass
     try:
         # call at_remove hook on the trackerclass
         _GA(obj, "_trackerhandler").remove(propname, trackerclass, *args, **kwargs)
     except AttributeError:
         pass
     # remove the pickle from storage
     store_key = (pack_dbobj(obj), sessid, propname)
     self.oob_tracker_storage.pop(store_key, None)
Ejemplo n.º 7
0
 def _untrack(self, obj, sessid, propname, trackerclass, *args, **kwargs):
     """
     Remove the OOB from obj. If oob implements an
     at_delete hook, this will be called with args, kwargs
     """
     try:
         obj = obj.dbobj
     except AttributeError:
         pass
     try:
         # call at_remove hook on the trackerclass
         _GA(obj, "_trackerhandler").remove(propname, trackerclass, *args,
                                            **kwargs)
     except AttributeError:
         pass
     # remove the pickle from storage
     store_key = (pack_dbobj(obj), sessid, propname)
     self.oob_tracker_storage.pop(store_key, None)