From ade8069507386096e4a2907ac1100a6576a70b15 Mon Sep 17 00:00:00 2001
From: astaric <anze.staric@gmail.com>
Date: Tue, 20 Aug 2013 13:42:50 +0200
Subject: [PATCH 6/7] Base64 encode pickled settings when saving schema.

If settings cannot be encoded as text, they are pickled. Pickle returns
bytes object, which cannot be stored in xml, so we base64 encode it.
---
 Orange/canvas/scheme/readwrite.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Orange/canvas/scheme/readwrite.py b/Orange/canvas/scheme/readwrite.py
index 6327dee..8bd9167 100644
--- a/Orange/canvas/scheme/readwrite.py
+++ b/Orange/canvas/scheme/readwrite.py
@@ -2,6 +2,7 @@
 Scheme save/load routines.
 
 """
+import base64
 import sys
 import warnings
 
@@ -930,14 +931,14 @@ def dumps(obj, format="literal", prettyprint=False, pickle_fallback=False):
                         exc_info=True)
 
     elif format == "pickle":
-        return pickle.dumps(obj), "pickle"
+        return base64.encodebytes(pickle.dumps(obj)).decode('ascii'), "pickle"
 
     else:
         raise ValueError("Unsupported format %r" % format)
 
     if pickle_fallback:
         log.warning("Using pickle fallback")
-        return pickle.dumps(obj), "pickle"
+        return base64.encodebytes(pickle.dumps(obj)).decode('ascii'), "pickle"
     else:
         raise Exception("Something strange happened.")
 
@@ -948,7 +949,7 @@ def loads(string, format):
     elif format == "json":
         return json.loads(string)
     elif format == "pickle":
-        return pickle.loads(string)
+        return pickle.loads(base64.decodebytes(string.encode('ascii')))
     else:
         raise ValueError("Unknown format")
 
-- 
1.8.4.3

