cubicweb/utils.py
changeset 11715 760d5c0ae08f
parent 11057 0b59724cb3f2
child 11767 432f87a63057
--- a/cubicweb/utils.py	Wed Oct 12 11:09:08 2016 +0200
+++ b/cubicweb/utils.py	Wed Oct 12 11:07:10 2016 +0200
@@ -21,6 +21,7 @@
 
 __docformat__ = "restructuredtext en"
 
+import base64
 import decimal
 import datetime
 import random
@@ -42,6 +43,9 @@
 from logilab.common.deprecation import deprecated
 from logilab.common.date import ustrftime
 
+from cubicweb import Binary
+
+
 _MARKER = object()
 
 # initialize random seed from current time
@@ -507,6 +511,8 @@
             return (obj.days * 24 * 60 * 60) + obj.seconds
         elif isinstance(obj, decimal.Decimal):
             return float(obj)
+        elif isinstance(obj, Binary):
+            return base64.b64encode(obj.getvalue()).decode('ascii')
         try:
             return json.JSONEncoder.default(self, obj)
         except TypeError: