From 9869e771704ada62bab001e729c52a36525ef081 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Fri, 23 Sep 2011 16:23:59 +0200
Subject: [PATCH] =?UTF-8?q?serializer:=20Support=20newer=20=E2=80=9Cjson?=
 =?UTF-8?q?=E2=80=9D=20module?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This module is included from Python 2.6 and is based on
simplejson.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: RenΓ© Nussbaumer <rn@google.com>
---
 lib/serializer.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/serializer.py b/lib/serializer.py
index ff27261aa..5b806759c 100644
--- a/lib/serializer.py
+++ b/lib/serializer.py
@@ -29,7 +29,13 @@ backend (currently json).
 # C0103: Invalid name, since pylint doesn't see that Dump points to a
 # function and not a constant
 
-import simplejson
+try:
+  import json
+except ImportError:
+  # The "json" module was only added in Python 2.6. Earlier versions must use
+  # the separate "simplejson" module.
+  import simplejson as json
+
 import re
 
 from ganeti import errors
@@ -41,7 +47,7 @@ _JSON_INDENT = 2
 _RE_EOLSP = re.compile("[ \t]+$", re.MULTILINE)
 
 
-def _GetJsonDumpers(_encoder_class=simplejson.JSONEncoder):
+def _GetJsonDumpers(_encoder_class=json.JSONEncoder):
   """Returns two JSON functions to serialize data.
 
   @rtype: (callable, callable)
@@ -93,7 +99,7 @@ def LoadJson(txt):
   @return: the original data
 
   """
-  return simplejson.loads(txt)
+  return json.loads(txt)
 
 
 def DumpSignedJson(data, key, salt=None, key_selector=None):
-- 
GitLab