فهرست منبع

Use kombu.utils.json instead of anyjson :sad:

Ask Solem 11 سال پیش
والد
کامیت
66672c0f17

+ 1 - 1
celery/apps/beat.py

@@ -99,7 +99,7 @@ class Beat(object):
                             scheduler_cls=self.scheduler_cls,
                             schedule_filename=self.schedule)
 
-        print(text_t(
+        print(text_t(   # noqa (pyflakes chokes on print)
             c.blue('__    ', c.magenta('-'),
             c.blue('    ... __   '), c.magenta('-'),
             c.blue('        _\n'),

+ 4 - 3
celery/bin/celery.py

@@ -8,7 +8,6 @@ The :program:`celery` umbrella command.
 """
 from __future__ import absolute_import, unicode_literals
 
-import anyjson
 import numbers
 import os
 import sys
@@ -16,6 +15,8 @@ import sys
 from functools import partial
 from importlib import import_module
 
+from kombu.utils import json
+
 from celery.five import string_t, values
 from celery.platforms import EX_OK, EX_FAILURE, EX_UNAVAILABLE, EX_USAGE
 from celery.utils import term
@@ -162,12 +163,12 @@ class call(Command):
         # Positional args.
         args = kw.get('args') or ()
         if isinstance(args, string_t):
-            args = anyjson.loads(args)
+            args = json.loads(args)
 
         # Keyword args.
         kwargs = kw.get('kwargs') or {}
         if isinstance(kwargs, string_t):
-            kwargs = anyjson.loads(kwargs)
+            kwargs = json.loads(kwargs)
 
         # Expires can be int/float.
         expires = kw.get('expires') or None

+ 0 - 15
celery/events/__init__.py

@@ -13,7 +13,6 @@ from __future__ import absolute_import
 import os
 import time
 import threading
-import warnings
 
 from collections import deque
 from contextlib import contextmanager
@@ -36,14 +35,6 @@ event_exchange = Exchange('celeryev', type='topic')
 
 _TZGETTER = itemgetter('utcoffset', 'timestamp')
 
-W_YAJL = """
-anyjson is currently using the yajl library.
-This json implementation is broken, it severely truncates floats
-so timestamps will not work.
-
-Please uninstall yajl or force anyjson to use a different library.
-"""
-
 CLIENT_CLOCK_SKEW = -1
 
 
@@ -151,12 +142,6 @@ class EventDispatcher(object):
             self.enable()
         self.headers = {'hostname': self.hostname}
         self.pid = os.getpid()
-        self.warn_if_yajl()
-
-    def warn_if_yajl(self):
-        import anyjson
-        if anyjson.implementation.name == 'yajl':
-            warnings.warn(UserWarning(W_YAJL))
 
     def __enter__(self):
         return self

+ 0 - 8
celery/five.py

@@ -27,14 +27,6 @@ except ImportError:  # pragma: no cover
     def Counter():  # noqa
         return defaultdict(int)
 
-try:
-    buffer_t = buffer
-except NameError:  # pragma: no cover
-    # Py3 does not have buffer, but we only need isinstance.
-
-    class buffer_t(object):  # noqa
-        pass
-
 ############## py3k #########################################################
 import sys
 PY3 = sys.version_info[0] == 3

+ 2 - 2
celery/loaders/base.py

@@ -8,7 +8,6 @@
 """
 from __future__ import absolute_import
 
-import anyjson
 import imp as _imp
 import importlib
 import os
@@ -17,6 +16,7 @@ import sys
 
 from datetime import datetime
 
+from kombu.utils import json
 from kombu.utils import cached_property
 from kombu.utils.encoding import safe_str
 
@@ -178,7 +178,7 @@ class BaseLoader(object):
     def cmdline_config_parser(
             self, args, namespace='celery',
             re_type=re.compile(r'\((\w+)\)'),
-            extra_types={'json': anyjson.loads},
+            extra_types={'json': json.loads},
             override_types={'tuple': 'json',
                             'list': 'json',
                             'dict': 'json'}):

+ 3 - 2
celery/task/http.py

@@ -8,7 +8,6 @@
 """
 from __future__ import absolute_import
 
-import anyjson
 import sys
 
 try:
@@ -17,6 +16,8 @@ except ImportError:  # pragma: no cover
     from urllib import urlencode              # noqa
     from urlparse import urlparse, parse_qsl  # noqa
 
+from kombu.utils import json
+
 from celery import shared_task, __version__ as celery_version
 from celery.five import items, reraise
 from celery.utils.log import get_task_logger
@@ -62,7 +63,7 @@ class UnknownStatusError(InvalidResponseError):
     """The remote server gave an unknown status."""
 
 
-def extract_response(raw_response, loads=anyjson.loads):
+def extract_response(raw_response, loads=json.loads):
     """Extract the response text from a raw JSON response."""
     if not raw_response:
         raise InvalidResponseError('Empty response')

+ 2 - 1
celery/tests/bin/test_celery.py

@@ -2,9 +2,10 @@ from __future__ import absolute_import
 
 import sys
 
-from anyjson import dumps
 from datetime import datetime
 
+from kombu.utils.json import dumps
+
 from celery import __main__
 from celery.platforms import EX_FAILURE, EX_USAGE, EX_OK
 from celery.bin.base import Error

+ 1 - 1
celery/tests/compat_modules/test_http.py

@@ -8,8 +8,8 @@ try:
 except ImportError:  # py3k
     from urllib.request import addinfourl  # noqa
 
-from anyjson import dumps
 from kombu.utils.encoding import from_utf8
+from kombu.utils.json import dumps
 
 from celery.five import WhateverIO, items
 from celery.task import http

+ 3 - 2
celery/tests/compat_modules/test_sets.py

@@ -1,8 +1,9 @@
 from __future__ import absolute_import
 
-import anyjson
 import warnings
 
+from kombu.utils import json
+
 from celery import uuid
 from celery.result import TaskSetResult
 from celery.task import Task
@@ -136,7 +137,7 @@ class test_subtask(SetsCase):
         )
         s.args = list(s.args)                   # tuples are not preserved
                                                 # but this doesn't matter.
-        self.assertEqual(s, self.subtask(anyjson.loads(anyjson.dumps(s))))
+        self.assertEqual(s, self.subtask(json.loads(json.dumps(s))))
 
     def test_repr(self):
         s = self.MockTask.subtask((2, ), {'cache': True})

+ 1 - 1
celery/worker/consumer.py

@@ -26,6 +26,7 @@ from billiard.common import restart_state
 from billiard.exceptions import RestartFreqExceeded
 from kombu.async.semaphore import DummyLock
 from kombu.common import QoS, ignore_errors
+from kombu.five import buffer_t, items, values
 from kombu.syn import _detect_environment
 from kombu.utils.compat import get_errno
 from kombu.utils.encoding import safe_repr, bytes_t
@@ -35,7 +36,6 @@ from celery import bootsteps
 from celery.app.trace import build_tracer
 from celery.canvas import signature
 from celery.exceptions import InvalidTaskError
-from celery.five import buffer_t, items, values
 from celery.utils.functional import noop
 from celery.utils.log import get_logger
 from celery.utils.text import truncate

+ 1 - 1
celery/worker/strategy.py

@@ -11,9 +11,9 @@ from __future__ import absolute_import
 import logging
 
 from kombu.async.timer import to_timestamp
+from kombu.five import buffer_t
 
 from celery.exceptions import InvalidTaskError
-from celery.five import buffer_t
 from celery.utils.log import get_logger
 from celery.utils.timeutils import timezone
 

+ 1 - 14
docs/faq.rst

@@ -129,22 +129,9 @@ broker this is a natural dependency.
 
 .. _`amqp`: http://pypi.python.org/pypi/amqp
 
-- `anyjson`_
-
-anyjson is an utility library to select the best possible
-JSON implementation.
-
-.. _`anyjson`: http://pypi.python.org/pypi/anyjson
-
-
 .. note::
 
-    For compatibility reasons additional packages may be installed
-    if you are running on older Python versions,
-    for example Python 2.6 depends on the ``importlib``,
-    and ``ordereddict`` libraries.
-
-    Also, to handle the dependencies for popular configuration
+    To handle the dependencies for popular configuration
     choices Celery defines a number of "bundle" packages,
     see :ref:`bundles`.
 

+ 2 - 2
docs/userguide/remote-tasks.rst

@@ -59,7 +59,7 @@ With this information you could define a simple task in Django:
 .. code-block:: python
 
     from django.http import HttpResponse
-    from anyjson import serialize
+    from json import dumps
 
 
     def multiply(request):
@@ -67,7 +67,7 @@ With this information you could define a simple task in Django:
         y = int(request.GET['y'])
         result = x * y
         response = {'status': 'success', 'retval': result}
-        return HttpResponse(serialize(response), mimetype='application/json')
+        return HttpResponse(dumps(response), mimetype='application/json')
 
 .. _webhook-rails-example:
 

+ 1 - 1
examples/httpexample/views.py

@@ -1,6 +1,6 @@
 from django.http import HttpResponse
 
-from anyjson import dumps
+from json import dumps
 
 
 def multiply(request):

+ 0 - 7
funtests/benchmarks/bench_worker.py

@@ -9,13 +9,6 @@ os.environ.update(
     USE_FAST_LOCALS='yes',
 )
 
-import anyjson
-JSONIMP = os.environ.get('JSONIMP')
-if JSONIMP:
-    anyjson.force_implementation(JSONIMP)
-
-print('anyjson implementation: {0!r}'.format(anyjson.implementation.name))
-
 from celery import Celery, group
 from celery.five import range