Example #1
0
 def _get_values(self, context):
     if debug: print 'Calculator evaluate', self, context
     _module_lock.acquire()
     try:
         local_context = {}
         id = thread_id()
         if id in self._threads:
             self._threads.remove(id) #if we don't remove it, this may become permanent
             raise ECircularReference('Recursion detected', self.name)
         self._threads.add(id)
     finally:
         _module_lock.release()
     try:
         for k in context.iterkeys():
             v = context[k]
             if debug: print 'Calculator key/value: ',k, v
             if callable(v): #node gets and forced variables
                 x = v()
                 if not hasattr(x,'__abs__'):
                     if hasattr(x,'__float__'):
                         x = float(x)
                     elif hasattr(x,'__int__'):
                         x = int(x)
                 local_context[k] = x
                 if debug: print 'Callable returned :', local_context[k]
             else:
                 local_context[k] = v
     finally:
         _module_lock.acquire()
         try:
             self._threads.discard(id)
         finally:
             _module_lock.release()
     return local_context
Example #2
0
 def _get_values(self, context):
     if debug: print 'Calculator evaluate', self, context
     _module_lock.acquire()
     try:
         local_context = {}
         id = thread_id()
         if id in self._threads:
             self._threads.remove(
                 id)  #if we don't remove it, this may become permanent
             raise ECircularReference('Recursion detected', self.name)
         self._threads.add(id)
     finally:
         _module_lock.release()
     try:
         for k in context.iterkeys():
             v = context[k]
             if debug: print 'Calculator key/value: ', k, v
             if callable(v):  #node gets and forced variables
                 x = v()
                 if not hasattr(x, '__abs__'):
                     if hasattr(x, '__float__'):
                         x = float(x)
                     elif hasattr(x, '__int__'):
                         x = int(x)
                 local_context[k] = x
                 if debug: print 'Callable returned :', local_context[k]
             else:
                 local_context[k] = v
     finally:
         _module_lock.acquire()
         try:
             self._threads.discard(id)
         finally:
             _module_lock.release()
     return local_context
Example #3
0
 def _get_values(self, context):
     _module_lock.acquire()
     try:
         local_context = {}
         id = thread_id()
         if id in self._threads:
             #if we don't remove it, this may become permanent
             self._threads.remove(id)
             raise ECircularReference('Recursion detected', self.name)
         self._threads.add(id)
     finally:
         _module_lock.release()
     try:
         for k in context.iterkeys():
             v = context[k]
             local_context[k] = v() if callable(v) else v
     finally:
         _module_lock.acquire()
         try:
             self._threads.discard(id)
         finally:
             _module_lock.release()
     return local_context
Example #4
0
 def _get_values(self, context):
     _module_lock.acquire()
     try:
         local_context = {}
         id = thread_id()
         if id in self._threads:
             #if we don't remove it, this may become permanent
             self._threads.remove(id)
             raise ECircularReference('Recursion detected', self.name)
         self._threads.add(id)
     finally:
         _module_lock.release()
     try:
         for k in context.iterkeys():
             v = context[k]
             local_context[k] = v() if callable(v) else v
     finally:
         _module_lock.acquire()
         try:
             self._threads.discard(id)
         finally:
             _module_lock.release()
     return local_context