Commits

Joao Bueno committed bc848d7

Multiprocessing logic wrapper in place

Comments (0)

Files changed (2)

             self._real_value = self.queue.get()
         return self._real_value
 
-        
+
+def value_retriever(name):
+    def operator(self, *args, **kw):
+        real_op = getattr(self._value, name)
+        return real_op(*args, **kw)
+
+class MetaParalell(type):
+    def __new__(metacls, name, bases, dct):
+        # FIXME: check the data_model
+        # and other Python documentation -
+        #  there are mssing dunder methods still
+        special_methods = """
+        __abs__ __add__ __and__ __class__ __cmp__ __coerce__
+        __delattr__ __div__ __divmod__ __doc__ __float__
+        __floordiv__ __format__ __getattribute__ __getnewargs__
+        __hash__ __hex__ __index__ __init__ __int__ __invert__
+        __long__ __lshift__ __mod__ __mul__ __neg__ __new__
+        __nonzero__ __oct__ __or__ __pos__ __pow__ __radd__
+        __rand__ __rdiv__ __rdivmod__ __reduce__ __reduce_ex__
+        __repr__ __rfloordiv__ __rlshift__ __rmod__ __rmul__
+        __ror__ __rpow__ __rrshift__ __rshift__ __rsub__
+        __rtruediv__ __rxor__ __setattr__ __sizeof__
+        __str__ __sub__ __subclasshook__ __truediv_
+        __trunc__ __xor__ _contains__ __delitem__ __delslice__
+        __eq__ __ge__ __getitem__ __getslice__ __gt__ __iadd__
+        __imul__ __iter__ __le__ __len__ __lt__ __ne__ __reversed__
+        __setitem__ __setslice__ __call__ __enter__ __exit__
+
+        """
+        for func_name in special_methods.split():
+            dct[func_name] = value_retriever(name)
+            dct[func_name].__name__ = name
+        return type.__new__(metacls, name, bases, dct)
+
+Paralell = MetaParalell("paralell", Wrapper, {})
+
 
 def paralell(func):
     """
         self.assertEqual(wrapped(2,3), None)
         self.assertEqual(wrapped._value, 5)
         
-        
+    def test_lazy_class_factory(self):
+        from lelo._lelo import MetaParalell
+        X = MetaParalell("X", object, {})
+        x = X()
+        x._value = 10
+        self.assertEqual(x + 0, 10)
 
 if __name__ == "__main__":