Browse Source

regen can now be serialized using JSON (it's now a subclass of lists)

Ask Solem 13 years ago
parent
commit
aa668e1f53
2 changed files with 22 additions and 6 deletions
  1. 4 5
      celery/local.py
  2. 18 1
      celery/utils/functional.py

+ 4 - 5
celery/local.py

@@ -52,9 +52,12 @@ class Proxy(object):
     def __doc__(self):
         return self._get_current_object().__doc__
 
+    def _get_class(self):
+        return self._get_current_object().__class__
+
     @property
     def __class__(self):
-        return self._get_current_object().__class__
+        return self._get_class()
 
     def _get_current_object(self):
         """Return the current object.  This is useful if you want the real
@@ -198,7 +201,3 @@ def maybe_evaluate(obj):
         return obj.__maybe_evaluate__()
     except AttributeError:
         return obj
-
-
-def regen(it):
-    return PromiseProxy(list, (it, ))

+ 18 - 1
celery/utils/functional.py

@@ -18,9 +18,10 @@ from functools import partial, wraps
 from itertools import islice
 from threading import Lock, RLock
 
+from kombu.utils import cached_property
 from kombu.utils.functional import promise, maybe_promise
 
-from .compat import UserDict, OrderedDict
+from .compat import UserDict, UserList, OrderedDict
 
 KEYWORD_MARK = object()
 is_not_None = partial(operator.is_not, None)
@@ -244,3 +245,19 @@ def uniq(it):
         if obj not in seen:
             yield obj
             seen.add(obj)
+
+
+class _regen(UserList, list):
+    # must be subclass of list so that json can encode.
+    def __init__(self, it):
+        self.__it = it
+
+    @cached_property
+    def data(self):
+        return list(self.__it)
+
+
+def regen(it):
+    if isinstance(it, (list, tuple)):
+        return it
+    return _regen(it)