Browse Source

Moves celery.task.trace.mro_lookup to celery.utils.objects module

Ask Solem 12 years ago
parent
commit
6b98ad7b18
2 changed files with 37 additions and 27 deletions
  1. 2 27
      celery/task/trace.py
  2. 35 0
      celery/utils/objects.py

+ 2 - 27
celery/task/trace.py

@@ -30,8 +30,9 @@ from celery.app import set_default_app
 from celery.app.task import Task as BaseTask, Context
 from celery.app.task import Task as BaseTask, Context
 from celery.datastructures import ExceptionInfo
 from celery.datastructures import ExceptionInfo
 from celery.exceptions import Ignore, RetryTaskError
 from celery.exceptions import Ignore, RetryTaskError
-from celery.utils.serialization import get_pickleable_exception
 from celery.utils.log import get_logger
 from celery.utils.log import get_logger
+from celery.utils.objects import mro_lookup
+from celery.utils.serialization import get_pickleable_exception
 
 
 _logger = get_logger(__name__)
 _logger = get_logger(__name__)
 
 
@@ -50,32 +51,6 @@ _tasks = None
 _patched = {}
 _patched = {}
 
 
 
 
-def mro_lookup(cls, attr, stop=(), monkey_patched=[]):
-    """Returns the first node by MRO order that defines an attribute.
-
-    :keyword stop: A list of types that if reached will stop the search.
-    :keyword monkey_patched: Use one of the stop classes if the attr's
-        module origin is not in this list, this to detect monkey patched
-        attributes.
-
-    :returns None: if the attribute was not found.
-
-    """
-    for node in cls.mro():
-        if node in stop:
-            try:
-                attr = node.__dict__[attr]
-                module_origin = attr.__module__
-            except (AttributeError, KeyError):
-                pass
-            else:
-                if module_origin not in monkey_patched:
-                    return node
-            return
-        if attr in node.__dict__:
-            return node
-
-
 def task_has_custom(task, attr):
 def task_has_custom(task, attr):
     """Returns true if the task or one of its bases
     """Returns true if the task or one of its bases
     defines ``attr`` (excluding the one in BaseTask)."""
     defines ``attr`` (excluding the one in BaseTask)."""

+ 35 - 0
celery/utils/objects.py

@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+"""
+    celery.utils.objects
+    ~~~~~~~~~~~~~~~~~~~~
+
+    Object related utilities including introspection, etc.
+
+"""
+from __future__ import absolute_import
+
+
+def mro_lookup(cls, attr, stop=(), monkey_patched=[]):
+    """Returns the first node by MRO order that defines an attribute.
+
+    :keyword stop: A list of types that if reached will stop the search.
+    :keyword monkey_patched: Use one of the stop classes if the attr's
+        module origin is not in this list, this to detect monkey patched
+        attributes.
+
+    :returns None: if the attribute was not found.
+
+    """
+    for node in cls.mro():
+        if node in stop:
+            try:
+                attr = node.__dict__[attr]
+                module_origin = attr.__module__
+            except (AttributeError, KeyError):
+                pass
+            else:
+                if module_origin not in monkey_patched:
+                    return node
+            return
+        if attr in node.__dict__:
+            return node