Commits

Jason R. Coombs  committed ec9afc7

Updated docs to refer to bitbucket repository

  • Participants
  • Parent commits 4d9605a
  • Tags 3.3.1

Comments (0)

Files changed (2)

File docs/index.txt

 <http://www.opensource.org/licenses/mit-license.php>`_.
 
 You can install it with ``easy_install jaraco.util``, or from the
-`subversion repository
-<https://svn.jaraco.com/jaraco/python/jaraco.util#egg=jaraco.util-dev>`_ with
+`mercurial repository
+<http://bitbucket.org/jaraco/jaraco.util/get/tip.zip#egg=jaraco.util-dev>`_ with
 ``easy_install jaraco.util==dev``.
 
 Changes

File sandbox/xml_to_json.py

+import json
+import lxml
+
+class objectJSONEncoder(json.JSONEncoder):
+	"""A specialized JSON encoder that can handle simple lxml objectify types
+	>>> from lxml import objectify
+	>>> obj = objectify.fromstring("<Book><price>1.50</price><author>W. Shakespeare</author></Book>")
+	>>> objectJSONEncoder().encode(obj)
+	'{"price": 1.5, "author": "W. Shakespeare"}'
+	"""
+	def default(self,o):
+		if isinstance(o, lxml.objectify.IntElement):
+			return int(o)
+		if isinstance(o, lxml.objectify.NumberElement) or isinstance(o, lxml.objectify.FloatElement):
+			return float(o)
+		if isinstance(o, lxml.objectify.ObjectifiedDataElement):
+			return str(o)
+		if hasattr(o, '__dict__'):
+			#For objects with a __dict__, return the encoding of the __dict__
+			return o.__dict__
+		return json.JSONEncoder.default(self, o)