瀏覽代碼

Use cached_property from kombu.utils

Ask Solem 14 年之前
父節點
當前提交
951bbd9605

+ 3 - 1
celery/app/__init__.py

@@ -13,9 +13,11 @@ import threading
 
 
 from inspect import getargspec
 from inspect import getargspec
 
 
+from kombu.utils import cached_property
+
 from celery import registry
 from celery import registry
 from celery.app import base
 from celery.app import base
-from celery.utils import cached_property, instantiate
+from celery.utils import instantiate
 from celery.utils.functional import wraps
 from celery.utils.functional import wraps
 
 
 # Apps with the :attr:`~celery.app.base.BaseApp.set_as_current` attribute
 # Apps with the :attr:`~celery.app.base.BaseApp.set_as_current` attribute

+ 2 - 1
celery/app/amqp.py

@@ -14,10 +14,11 @@ from datetime import datetime, timedelta
 from kombu import BrokerConnection, Exchange
 from kombu import BrokerConnection, Exchange
 from kombu.connection import Resource
 from kombu.connection import Resource
 from kombu import compat as messaging
 from kombu import compat as messaging
+from kombu.utils import cached_property
 
 
 from celery import routes as _routes
 from celery import routes as _routes
 from celery import signals
 from celery import signals
-from celery.utils import gen_unique_id, textindent, cached_property
+from celery.utils import gen_unique_id, textindent
 from celery.utils import promise, maybe_promise
 from celery.utils import promise, maybe_promise
 from celery.utils.compat import UserDict
 from celery.utils.compat import UserDict
 
 

+ 3 - 1
celery/app/base.py

@@ -12,9 +12,11 @@ import platform as _platform
 
 
 from copy import deepcopy
 from copy import deepcopy
 
 
+from kombu.utils import cached_property
+
 from celery.app.defaults import DEFAULTS
 from celery.app.defaults import DEFAULTS
 from celery.datastructures import ConfigurationView
 from celery.datastructures import ConfigurationView
-from celery.utils import cached_property, instantiate, lpmerge
+from celery.utils import instantiate, lpmerge
 from celery.utils.functional import wraps
 from celery.utils.functional import wraps
 
 
 
 

+ 1 - 2
celery/backends/cache.py

@@ -1,10 +1,9 @@
 from datetime import timedelta
 from datetime import timedelta
 
 
-from kombu.utils import partition
+from kombu.utils import partition, cached_property
 
 
 from celery.backends.base import KeyValueStoreBackend
 from celery.backends.base import KeyValueStoreBackend
 from celery.exceptions import ImproperlyConfigured
 from celery.exceptions import ImproperlyConfigured
-from celery.utils import cached_property
 from celery.utils import timeutils
 from celery.utils import timeutils
 from celery.datastructures import LocalCache
 from celery.datastructures import LocalCache
 
 

+ 2 - 1
celery/backends/pyredis.py

@@ -1,9 +1,10 @@
 from datetime import timedelta
 from datetime import timedelta
 
 
+from kombu.utils import cached_property
+
 from celery.backends.base import KeyValueStoreBackend
 from celery.backends.base import KeyValueStoreBackend
 from celery.exceptions import ImproperlyConfigured
 from celery.exceptions import ImproperlyConfigured
 from celery.utils import timeutils
 from celery.utils import timeutils
-from celery.utils import cached_property
 
 
 try:
 try:
     import redis
     import redis

+ 3 - 1
celery/beat.py

@@ -15,6 +15,8 @@ except ImportError:
 
 
 from datetime import datetime
 from datetime import datetime
 
 
+from kombu.utils import cached_property
+
 from celery import __version__
 from celery import __version__
 from celery import platforms
 from celery import platforms
 from celery import registry
 from celery import registry
@@ -22,7 +24,7 @@ from celery import signals
 from celery.app import app_or_default
 from celery.app import app_or_default
 from celery.log import SilenceRepeated
 from celery.log import SilenceRepeated
 from celery.schedules import maybe_schedule, crontab
 from celery.schedules import maybe_schedule, crontab
-from celery.utils import cached_property, instantiate, maybe_promise
+from celery.utils import instantiate, maybe_promise
 from celery.utils.timeutils import humanize_seconds
 from celery.utils.timeutils import humanize_seconds
 
 
 
 

+ 2 - 1
celery/contrib/batches.py

@@ -42,10 +42,11 @@ Registering the click is done as follows:
 from itertools import count
 from itertools import count
 from Queue import Queue
 from Queue import Queue
 
 
+from kombu.utils import cached_property
+
 from celery.datastructures import consume_queue
 from celery.datastructures import consume_queue
 from celery.task import Task
 from celery.task import Task
 from celery.utils import timer2
 from celery.utils import timer2
-from celery.utils import cached_property
 from celery.worker import state
 from celery.worker import state
 
 
 
 

+ 4 - 3
celery/loaders/base.py

@@ -2,9 +2,10 @@ import importlib
 import re
 import re
 import warnings
 import warnings
 
 
-import anyjson
+from anyjson import deserialize
+from kombu.utils import cached_property
 
 
-from celery.utils import cached_property, import_from_cwd as _import_from_cwd
+from celery.utils import import_from_cwd as _import_from_cwd
 
 
 BUILTIN_MODULES = ["celery.task"]
 BUILTIN_MODULES = ["celery.task"]
 
 
@@ -69,7 +70,7 @@ class BaseLoader(object):
 
 
     def cmdline_config_parser(self, args, namespace="celery",
     def cmdline_config_parser(self, args, namespace="celery",
                 re_type=re.compile(r"\((\w+)\)"),
                 re_type=re.compile(r"\((\w+)\)"),
-                extra_types={"json": anyjson.deserialize},
+                extra_types={"json": deserialize},
                 override_types={"tuple": "json",
                 override_types={"tuple": "json",
                                 "list": "json",
                                 "list": "json",
                                 "dict": "json"}):
                                 "dict": "json"}):

+ 3 - 1
celery/task/sets.py

@@ -1,9 +1,11 @@
 import warnings
 import warnings
 
 
+from kombu.utils import cached_property
+
 from celery import registry
 from celery import registry
 from celery.app import app_or_default
 from celery.app import app_or_default
 from celery.datastructures import AttributeDict
 from celery.datastructures import AttributeDict
-from celery.utils import cached_property, gen_unique_id
+from celery.utils import gen_unique_id
 from celery.utils.compat import UserList
 from celery.utils.compat import UserList
 
 
 TASKSET_DEPRECATION_TEXT = """\
 TASKSET_DEPRECATION_TEXT = """\

+ 1 - 69
celery/utils/__init__.py

@@ -13,7 +13,7 @@ from inspect import getargspec
 from itertools import islice
 from itertools import islice
 from pprint import pprint
 from pprint import pprint
 
 
-from kombu.utils import gen_unique_id, rpartition
+from kombu.utils import gen_unique_id, rpartition, cached_property
 
 
 from celery.utils.compat import StringIO
 from celery.utils.compat import StringIO
 from celery.utils.functional import partial, wraps
 from celery.utils.functional import partial, wraps
@@ -380,74 +380,6 @@ def import_from_cwd(module, imp=None):
             pass
             pass
 
 
 
 
-class cached_property(object):
-    """Property descriptor that caches the return value
-    of the get function.
-
-    *Examples*
-
-    .. code-block:: python
-
-        @cached_property
-        def connection(self):
-            return Connection()
-
-        @connection.setter  # Prepares stored value
-        def connection(self, value):
-            if value is None:
-                raise TypeError("Connection must be a connection")
-            return value
-
-        @connection.deleter
-        def connection(self, value):
-            # Additional action to do at del(self.attr)
-            if value is not None:
-                print("Connection %r deleted" % (value, ))
-
-    """
-
-    def __init__(self, fget=None, fset=None, fdel=None, doc=None):
-        self.__get = fget
-        self.__set = fset
-        self.__del = fdel
-        self.__doc__ = doc or fget.__doc__
-        self.__name__ = fget.__name__
-        self.__module__ = fget.__module__
-
-    def __get__(self, obj, type=None):
-        if obj is None:
-            return self
-        try:
-            return obj.__dict__[self.__name__]
-        except KeyError:
-            value = obj.__dict__[self.__name__] = self.__get(obj)
-            return value
-
-    def __set__(self, obj, value):
-        if obj is None:
-            return self
-        if self.__set is not None:
-            value = self.__set(obj, value)
-        obj.__dict__[self.__name__] = value
-
-    def __delete__(self, obj):
-        if obj is None:
-            return self
-        try:
-            value = obj.__dict__.pop(self.__name__)
-        except KeyError:
-            pass
-        else:
-            if self.__del is not None:
-                self.__del(obj, value)
-
-    def setter(self, fset):
-        return self.__class__(self.__get, fset, self.__del)
-
-    def deleter(self, fdel):
-        return self.__class__(self.__get, self.__set, fdel)
-
-
 def cry():
 def cry():
     """Return stacktrace of all active threads.
     """Return stacktrace of all active threads.
 
 

+ 2 - 1
celery/worker/state.py

@@ -1,8 +1,9 @@
 import platform
 import platform
 import shelve
 import shelve
 
 
+from kombu.utils import cached_property
+
 from celery import __version__
 from celery import __version__
-from celery.utils import cached_property
 from celery.utils.compat import defaultdict
 from celery.utils.compat import defaultdict
 from celery.datastructures import LimitedSet
 from celery.datastructures import LimitedSet