Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Correction for SimpleJSON support (Nikolay Igotti).

git-svn-id: http://vboxweb.googlecode.com/svn/trunk@31 729376a8-6c6b-11de-afdd-bb9f892af8c1
  • Loading branch information...
commit 9bc722ce656369520ff513854b0d6062611034e9 1 parent afb5b1f
vboxweb authored
Showing with 20 additions and 6 deletions.
  1. +20 −6 VBoxWebSrv.py
26 VBoxWebSrv.py
View
@@ -32,9 +32,11 @@
import traceback
if sys.version_info < (2, 6):
- import simplejson as json
+ import simplejson
+ isSimpleJson = True
else:
import json
+ isSimpleJson = False
from cherrypy.lib.static import serve_file
@@ -50,6 +52,11 @@ def convertObjToJSON(obj):
d.update(obj.__dict__)
return d
+if isSimpleJson:
+ class ConvertObjToJSONClass(simplejson.JSONEncoder):
+ def default(self, obj):
+ return convertObjToJSON(obj)
+
class jsHeader:
def __init__(self, ctx, arrMach, type):
self.magic = "jsVBxWb"
@@ -58,6 +65,7 @@ def __init__(self, ctx, arrMach, type):
self.sessionID = cherrypy.session.id
self.numMach = len(arrMach)
self.updateType = type
+
#
# @todo write autowrapper for attributes main-like classes below.
# Currently this involves too much copying around.
@@ -263,10 +271,13 @@ def __init__(self, ctx):
# Init JSON printer
self.jsonPrinter = None
- if hasattr(json, "dumps"):
- self.jsonPrinter = json.dumps
- elif hasattr(json, "write"):
- self.jsonPrinter = json.write
+ if isSimpleJson:
+ self.jsonPrinter = simplejson.dumps
+ else:
+ if hasattr(json, "dumps"):
+ self.jsonPrinter = json.dumps
+ elif hasattr(json, "write"):
+ self.jsonPrinter = json.write
self.arrMach = []
def populateVMList(self):
@@ -361,7 +372,10 @@ def vboxGetUpdates(self):
self.forceUpdate = False
print "type %d, %d machines modified" %(updateType, len(arrMach))
- return self.jsonPrinter(arrJSON, default=convertObjToJSON)
+ if isSimpleJson:
+ return self.jsonPrinter(arrJSON, cls=ConvertObjToJSONClass)
+ else:
+ return self.jsonPrinter(arrJSON, default=convertObjToJSON)
@cherrypy.expose
def index(self):
Please sign in to comment.
Something went wrong with that request. Please try again.