[Sugar-devel] [PATCH] Stopwatch: Replace cPickle by json

Ignacio Rodríguez ignacio at sugarlabs.org
Fri Dec 6 14:27:09 EST 2013


From: Ignacio Rodríguez <ignaciorodriguez at sugarlabs.org>

---
 activity.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/activity.py b/activity.py
index 6660fa7..7a88367 100644
--- a/activity.py
+++ b/activity.py
@@ -28,7 +28,11 @@ import stopwatch
 import gobject
 import dobject
 
-import cPickle
+try:
+    import json
+except ImportError:
+    import simplejson as json
+
 import gtk.gdk
 
 SERVICE = "org.laptop.StopWatch"
@@ -169,7 +173,7 @@ class StopWatchActivity(Activity):
     
     def read_file(self, file_path):
         f = open(file_path, 'r')
-        q = cPickle.load(f)
+        q = json.loads(f.read())
         f.close()
         self.gui.set_all(q)
     
@@ -177,7 +181,8 @@ class StopWatchActivity(Activity):
         self.metadata['mime_type'] = 'application/x-stopwatch-activity'
         q = self.gui.get_all()
         f = open(file_path, 'w')
-        cPickle.dump(q, f)
+        data = json.dumps(q)
+        f.write(data)
         f.close()
         
     def _active_cb(self, widget, event):
-- 
1.8.1.2



More information about the Sugar-devel mailing list