Browse Source

Use anyjson to find the best JSON module installed on the system.

Ask Solem 16 years ago
parent
commit
830012dfab
2 changed files with 5 additions and 7 deletions
  1. 4 7
      celery/views.py
  2. 1 0
      setup.py

+ 4 - 7
celery/views.py

@@ -2,11 +2,8 @@
 from django.http import HttpResponse, Http404
 from celery.task import tasks, is_done, apply_async
 from celery.result import AsyncResult
+from anyjson import serialize as JSON_dump
 
-try:
-    import simplejson as json
-except ImportError:
-    from django.utils import simplejson as json
 
 
 def apply(request, task_name, *args):
@@ -28,13 +25,13 @@ def apply(request, task_name, *args):
 
     task = tasks[task_name]
     result = apply_async(task, args=args, kwargs=kwargs)
-    return json.dumps({"ok": "true", "task_id": result.task_id})
+    return JSON_dump({"ok": "true", "task_id": result.task_id})
 
 
 def is_task_done(request, task_id):
     """Returns task execute status in JSON format."""
     response_data = {"task": {"id": task_id, "executed": is_done(task_id)}}
-    return HttpResponse(json.dumps(response_data), mimetype="application/json")
+    return HttpResponse(JSON_dump(response_data), mimetype="application/json")
 
 
 def task_status(request, task_id):
@@ -53,5 +50,5 @@ def task_status(request, task_id):
             "status": status,
             "result": async_result.result,
         }
-    return HttpResponse(json.dumps({"task": response_data}),
+    return HttpResponse(JSON_dump({"task": response_data}),
             mimetype="application/json")

+ 1 - 0
setup.py

@@ -41,6 +41,7 @@ class RunTests(Command):
 
 
 install_requires = ["django-unittest-depth",
+                    "anyjson",
                     "carrot>=0.5.0",
                     "python-daemon"]
 py_version_info = sys.version_info