Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'python/src/tcf/channel/__init__.py')
-rw-r--r--python/src/tcf/channel/__init__.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/python/src/tcf/channel/__init__.py b/python/src/tcf/channel/__init__.py
index 1a96a3b7d..0b81bbc73 100644
--- a/python/src/tcf/channel/__init__.py
+++ b/python/src/tcf/channel/__init__.py
@@ -118,7 +118,7 @@ def toJSONSequence(args):
return None
buf = cStringIO.StringIO()
for arg in args:
- json.dump(arg, buf, separators=(',', ':'))
+ json.dump(arg, buf, separators=(',', ':'), cls=TCFJSONEncoder)
buf.write('\0')
return buf.getvalue()
@@ -135,11 +135,19 @@ def fromJSONSequence(bytes):
objects.append(None)
return objects
-_ByteArrayType = type(bytearray())
def toByteArray(data):
if data is None: return None
t = type(data)
- if t is _ByteArrayType: return data
+ if t is bytearray: return data
if t is types.StringType:
return binascii.a2b_base64(data)
- raise exceptions.Exception()
+ raise exceptions.TypeError(str(t))
+
+class TCFJSONEncoder(json.JSONEncoder):
+ def default(self, o):
+ if isinstance(o, bytearray):
+ return binascii.b2a_base64(o)
+ elif hasattr('__iter__', o):
+ return tuple(o)
+ else:
+ json.JSONEncoder.default(self, o)

Back to the top