Advertisement
acoconut

Decfun

Jul 20th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1.  37 def decfunc(f):
  2.  38     def inner(self, *args):
  3.  39         global classObject
  4.  40         if self == classObject:
  5.  41             if self.store == None:#for the case when same object is used for calling more than one functions
  6.  42                 self.store = Store(self.database)
  7.  43                 result = f(self,*args)
  8.  44                 self.store.commit()
  9.  45                 self.store.close()
  10.  46                 self.store = None
  11.  47             else:#To handle the nesting issue
  12.  48                 result = f(self,*args)
  13.  49                 self.store.commit()
  14.  50         else:#for the case whenever a new object calls its decorated member function
  15.  51             classObject = self
  16.  52             self.store = Store(self.database)
  17.  53             result = f(self,*args)
  18.  54             self.store.commit()
  19.  55             self.store.close()
  20.  56             self.store = None
  21.  57         return result
  22.  58     return inner
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement