From e87086c8022b3c15533203ad189656a00e3349db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicklas=20B=C3=B6rjesson?= Date: Mon, 21 Mar 2016 12:27:59 +0100 Subject: [PATCH 1/2] Be Python 3.x-compatible --- json_lxml.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/json_lxml.py b/json_lxml.py index 345d86d..d946fc7 100644 --- a/json_lxml.py +++ b/json_lxml.py @@ -2,6 +2,7 @@ """convert between python value and lxml.etree so that lxml's power can be applied to json data. In particular, xpath queries can be run against json. """ +import sys from lxml import etree type_map = dict( @@ -25,7 +26,7 @@ def element(k, v): if isinstance(v, dict): for ck, cv in v.items(): node.append(element(ck, cv)) - elif isinstance(v, unicode): + elif sys.version_info < (3,0,0) and isinstance(v, unicode): node.set('type', type(v).__name__) node.text=v.encode('utf8') elif isinstance(v, (int, float, bool, str, NoneType)): # scalar From 1037b331c7be10e8b70a9a2672e2713e0b9b9e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicklas=20B=C3=B6rjesson?= Date: Mon, 21 Mar 2016 13:22:52 +0100 Subject: [PATCH 2/2] Change to call array items "item" instead of having the position in the name --- json_lxml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_lxml.py b/json_lxml.py index d946fc7..91a32ff 100644 --- a/json_lxml.py +++ b/json_lxml.py @@ -35,7 +35,7 @@ def element(k, v): elif isinstance(v, list): node.set('type', type(v).__name__) # list xx this could be done across the board. for i, cv in enumerate(v): - node.append(element("_list_element_%d" % i, cv)) + node.append(element("item", cv)) else: assert False