Ask Solem %!s(int64=9) %!d(string=hai) anos
pai
achega
8de8bb99b2

+ 17 - 13
celery/app/base.py

@@ -39,6 +39,7 @@ from celery.utils import abstract
 from celery.utils import gen_task_name
 from celery.utils import gen_task_name
 from celery.utils.dispatch import Signal
 from celery.utils.dispatch import Signal
 from celery.utils.functional import first, maybe_list, head_from_fun
 from celery.utils.functional import first, maybe_list, head_from_fun
+from celery.utils.timeutils import timezone
 from celery.utils.imports import instantiate, symbol_by_name
 from celery.utils.imports import instantiate, symbol_by_name
 from celery.utils.log import get_logger
 from celery.utils.log import get_logger
 from celery.utils.objects import FallbackContext, mro_lookup
 from celery.utils.objects import FallbackContext, mro_lookup
@@ -58,7 +59,7 @@ __all__ = ['Celery']
 
 
 logger = get_logger(__name__)
 logger = get_logger(__name__)
 
 
-_EXECV = os.environ.get('FORKED_BY_MULTIPROCESSING')
+USING_EXECV = os.environ.get('FORKED_BY_MULTIPROCESSING')
 BUILTIN_FIXUPS = {
 BUILTIN_FIXUPS = {
     'celery.fixups.django:fixup',
     'celery.fixups.django:fixup',
 }
 }
@@ -89,6 +90,7 @@ def _after_fork_cleanup_app(app):
 
 
 
 
 class PendingConfiguration(UserDict, AttributeDictMixin):
 class PendingConfiguration(UserDict, AttributeDictMixin):
+
     callback = None
     callback = None
     data = None
     data = None
 
 
@@ -104,7 +106,8 @@ class Celery(object):
     """Celery application.
     """Celery application.
 
 
     :param main: Name of the main module if running as `__main__`.
     :param main: Name of the main module if running as `__main__`.
-        This is used as a prefix for task names.
+        This is used as the prefix for autogenerated task names.
+
     :keyword broker: URL of the default broker used.
     :keyword broker: URL of the default broker used.
     :keyword loader: The loader class, or the name of the loader class to use.
     :keyword loader: The loader class, or the name of the loader class to use.
                      Default is :class:`celery.loaders.app.AppLoader`.
                      Default is :class:`celery.loaders.app.AppLoader`.
@@ -145,6 +148,8 @@ class Celery(object):
     #: See :ref:`extending-bootsteps`.
     #: See :ref:`extending-bootsteps`.
     steps = None
     steps = None
 
 
+    builtin_fixups = BUILTIN_FIXUPS
+
     amqp_cls = 'celery.app.amqp:AMQP'
     amqp_cls = 'celery.app.amqp:AMQP'
     backend_cls = None
     backend_cls = None
     events_cls = 'celery.events:Events'
     events_cls = 'celery.events:Events'
@@ -153,10 +158,10 @@ class Celery(object):
     control_cls = 'celery.app.control:Control'
     control_cls = 'celery.app.control:Control'
     task_cls = 'celery.app.task:Task'
     task_cls = 'celery.app.task:Task'
     registry_cls = TaskRegistry
     registry_cls = TaskRegistry
+
     _fixups = None
     _fixups = None
     _pool = None
     _pool = None
     _conf = None
     _conf = None
-    builtin_fixups = BUILTIN_FIXUPS
     _after_fork_registered = False
     _after_fork_registered = False
 
 
     #: Signal sent when app is loading configuration.
     #: Signal sent when app is loading configuration.
@@ -240,6 +245,10 @@ class Celery(object):
         self.on_init()
         self.on_init()
         _register_app(self)
         _register_app(self)
 
 
+    def on_init(self):
+        """Optional callback called at init."""
+        pass
+
     def __autoset(self, key, value):
     def __autoset(self, key, value):
         if value:
         if value:
             self._preconf[key] = value
             self._preconf[key] = value
@@ -278,10 +287,6 @@ class Celery(object):
         self._pool = None
         self._pool = None
         _deregister_app(self)
         _deregister_app(self)
 
 
-    def on_init(self):
-        """Optional callback called at init."""
-        pass
-
     def start(self, argv=None):
     def start(self, argv=None):
         """Run :program:`celery` using `argv`.
         """Run :program:`celery` using `argv`.
 
 
@@ -289,8 +294,8 @@ class Celery(object):
 
 
         """
         """
         return instantiate(
         return instantiate(
-            'celery.bin.celery:CeleryCommand',
-            app=self).execute_from_commandline(argv)
+            'celery.bin.celery:CeleryCommand', app=self
+        ).execute_from_commandline(argv)
 
 
     def worker_main(self, argv=None):
     def worker_main(self, argv=None):
         """Run :program:`celery worker` using `argv`.
         """Run :program:`celery worker` using `argv`.
@@ -299,8 +304,8 @@ class Celery(object):
 
 
         """
         """
         return instantiate(
         return instantiate(
-            'celery.bin.worker:worker',
-            app=self).execute_from_commandline(argv)
+            'celery.bin.worker:worker', app=self
+        ).execute_from_commandline(argv)
 
 
     def task(self, *args, **opts):
     def task(self, *args, **opts):
         """Decorator to create a task class out of any callable.
         """Decorator to create a task class out of any callable.
@@ -332,7 +337,7 @@ class Celery(object):
             application is fully set up (finalized).
             application is fully set up (finalized).
 
 
         """
         """
-        if _EXECV and opts.get('lazy', True):
+        if USING_EXECV and opts.get('lazy', True):
             # When using execv the task in the original module will point to a
             # When using execv the task in the original module will point to a
             # different app, so doing things like 'add.request' will point to
             # different app, so doing things like 'add.request' will point to
             # a different task instance.  This makes sure it will always use
             # a different task instance.  This makes sure it will always use
@@ -1127,7 +1132,6 @@ class Celery(object):
         :setting:`timezone` setting.
         :setting:`timezone` setting.
 
 
         """
         """
-        from celery.utils.timeutils import timezone
         conf = self.conf
         conf = self.conf
         tz = conf.timezone
         tz = conf.timezone
         if not tz:
         if not tz:

+ 6 - 7
celery/app/control.py

@@ -55,13 +55,12 @@ class Inspect(object):
         self.limit = limit
         self.limit = limit
 
 
     def _prepare(self, reply):
     def _prepare(self, reply):
-        if not reply:
-            return
-        by_node = flatten_reply(reply)
-        if self.destination and \
-                not isinstance(self.destination, (list, tuple)):
-            return by_node.get(self.destination)
-        return by_node
+        if reply:
+            by_node = flatten_reply(reply)
+            if (self.destination and
+                    not isinstance(self.destination, (list, tuple))):
+                return by_node.get(self.destination)
+            return by_node
 
 
     def _request(self, command, **kwargs):
     def _request(self, command, **kwargs):
         return self._prepare(self.app.control.broadcast(
         return self._prepare(self.app.control.broadcast(

+ 4 - 4
celery/tests/app/test_app.py

@@ -138,7 +138,7 @@ class test_App(AppCase):
 
 
     @depends_on_current_app
     @depends_on_current_app
     def test_task_windows_execv(self):
     def test_task_windows_execv(self):
-        prev, _appbase._EXECV = _appbase._EXECV, True
+        prev, _appbase.USING_EXECV = _appbase.USING_EXECV, True
         try:
         try:
             @self.app.task(shared=False)
             @self.app.task(shared=False)
             def foo():
             def foo():
@@ -147,8 +147,8 @@ class test_App(AppCase):
             self.assertTrue(foo._get_current_object())  # is proxy
             self.assertTrue(foo._get_current_object())  # is proxy
 
 
         finally:
         finally:
-            _appbase._EXECV = prev
-        assert not _appbase._EXECV
+            _appbase.USING_EXECV = prev
+        assert not _appbase.USING_EXECV
 
 
     def test_task_takes_no_args(self):
     def test_task_takes_no_args(self):
         with self.assertRaises(TypeError):
         with self.assertRaises(TypeError):
@@ -405,7 +405,7 @@ class test_App(AppCase):
                 check(task)
                 check(task)
                 return task
                 return task
 
 
-            assert not _appbase._EXECV
+            assert not _appbase.USING_EXECV
 
 
             @app.task(filter=filter, shared=False)
             @app.task(filter=filter, shared=False)
             def foo():
             def foo():

+ 1 - 1
celery/utils/encoding.py

@@ -6,7 +6,7 @@
     This module has moved to :mod:`kombu.utils.encoding`.
     This module has moved to :mod:`kombu.utils.encoding`.
 
 
 """
 """
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 
 from kombu.utils.encoding import (  # noqa
 from kombu.utils.encoding import (  # noqa
     default_encode, default_encoding, bytes_t, bytes_to_str, str_t,
     default_encode, default_encoding, bytes_t, bytes_to_str, str_t,

+ 2 - 1
celery/utils/functional.py

@@ -6,7 +6,7 @@
     Utilities for functions.
     Utilities for functions.
 
 
 """
 """
-from __future__ import absolute_import, print_function
+from __future__ import absolute_import, print_function, unicode_literals
 
 
 import sys
 import sys
 import threading
 import threading
@@ -321,6 +321,7 @@ def regen(it):
 
 
 class _regen(UserList, list):
 class _regen(UserList, list):
     # must be subclass of list so that json can encode.
     # must be subclass of list so that json can encode.
+
     def __init__(self, it):
     def __init__(self, it):
         self.__it = it
         self.__it = it
         self.__index = 0
         self.__index = 0

+ 1 - 1
celery/utils/imports.py

@@ -6,7 +6,7 @@
     Utilities related to importing modules and symbols by name.
     Utilities related to importing modules and symbols by name.
 
 
 """
 """
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 
 import imp as _imp
 import imp as _imp
 import importlib
 import importlib

+ 2 - 3
celery/utils/iso8601.py

@@ -1,5 +1,4 @@
-"""
-Originally taken from pyiso8601 (http://code.google.com/p/pyiso8601/)
+"""Originally taken from pyiso8601 (http://code.google.com/p/pyiso8601/)
 
 
 Modified to match the behavior of dateutil.parser:
 Modified to match the behavior of dateutil.parser:
 
 
@@ -31,7 +30,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 
 """
 """
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 
 import re
 import re
 
 

+ 1 - 1
celery/utils/log.py

@@ -6,7 +6,7 @@
     Logging utilities.
     Logging utilities.
 
 
 """
 """
-from __future__ import absolute_import, print_function
+from __future__ import absolute_import, print_function, unicode_literals
 
 
 import logging
 import logging
 import numbers
 import numbers

+ 1 - 1
celery/utils/mail.py

@@ -6,7 +6,7 @@
     How task error emails are formatted and sent.
     How task error emails are formatted and sent.
 
 
 """
 """
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 
 import smtplib
 import smtplib
 import socket
 import socket

+ 1 - 1
celery/utils/objects.py

@@ -6,7 +6,7 @@
     Object related utilities including introspection, etc.
     Object related utilities including introspection, etc.
 
 
 """
 """
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 
 __all__ = ['mro_lookup']
 __all__ = ['mro_lookup']
 
 

+ 1 - 1
celery/utils/serialization.py

@@ -6,7 +6,7 @@
     Utilities for safely pickling exceptions.
     Utilities for safely pickling exceptions.
 
 
 """
 """
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 
 from base64 import b64encode as base64encode, b64decode as base64decode
 from base64 import b64encode as base64encode, b64decode as base64decode
 from inspect import getmro
 from inspect import getmro

+ 1 - 1
celery/utils/sysinfo.py

@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
 # -*- coding: utf-8 -*-
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 
 import os
 import os
 
 

+ 1 - 1
celery/utils/text.py

@@ -6,7 +6,7 @@
     Text formatting utilities
     Text formatting utilities
 
 
 """
 """
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 
 from textwrap import fill
 from textwrap import fill
 
 

+ 1 - 1
celery/utils/threads.py

@@ -6,7 +6,7 @@
     Threading utilities.
     Threading utilities.
 
 
 """
 """
-from __future__ import absolute_import, print_function
+from __future__ import absolute_import, print_function, unicode_literals
 
 
 import os
 import os
 import socket
 import socket

+ 1 - 1
celery/utils/timer2.py

@@ -6,7 +6,7 @@
     Scheduler for Python functions.
     Scheduler for Python functions.
 
 
 """
 """
-from __future__ import absolute_import, print_function
+from __future__ import absolute_import, print_function, unicode_literals
 
 
 import os
 import os
 import sys
 import sys

+ 1 - 1
celery/utils/timeutils.py

@@ -6,7 +6,7 @@
     This module contains various utilities related to dates and times.
     This module contains various utilities related to dates and times.
 
 
 """
 """
-from __future__ import absolute_import, print_function
+from __future__ import absolute_import, print_function, unicode_literals
 
 
 import numbers
 import numbers
 import os
 import os