[Sugar-devel] [PATCH] Move from simplejson to standard library json - SL #3816

Manuel Quiñones manuq at laptop.org
Tue Apr 16 08:04:49 EDT 2013


We should only use one json implementatin, see
http://bugs.sugarlabs.org/ticket/3142

Signed-off-by: Manuel Quiñones <manuq at laptop.org>
---
 src/jarabe/journal/expandedentry.py      | 8 ++++----
 src/jarabe/journal/journalentrybundle.py | 4 ++--
 src/jarabe/journal/listmodel.py          | 6 +++---
 src/jarabe/journal/model.py              | 6 +++---
 src/jarabe/journal/volumestoolbar.py     | 4 ++--
 src/jarabe/model/bundleregistry.py       | 6 +++---
 src/jarabe/model/invites.py              | 6 +++---
 7 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/src/jarabe/journal/expandedentry.py b/src/jarabe/journal/expandedentry.py
index c6b7bc4..ce0de73 100644
--- a/src/jarabe/journal/expandedentry.py
+++ b/src/jarabe/journal/expandedentry.py
@@ -26,7 +26,7 @@ from gi.repository import GObject
 from gi.repository import GLib
 from gi.repository import Gtk
 from gi.repository import Gdk
-import simplejson
+import json
 
 from sugar3.graphics import style
 from sugar3.graphics.xocolor import XoColor
@@ -101,7 +101,7 @@ class CommentsView(Gtk.TreeView):
         self._store.clear()
 
         if comments:
-            self._comments = simplejson.loads(comments)
+            self._comments = json.loads(comments)
             for comment in self._comments:
                 self._add_row(comment.get(self.FROM, ''),
                               comment.get(self.MESSAGE, ''),
@@ -184,7 +184,7 @@ class CommentsView(Gtk.TreeView):
                             entry[self.COMMENT_ICON_COLOR].to_string()),
                         })
 
-            self.emit('comments-changed', simplejson.dumps(self._comments))
+            self.emit('comments-changed', json.dumps(self._comments))
 
 
 class CellRendererCommentIcon(CellRendererIcon):
@@ -459,7 +459,7 @@ class ExpandedEntry(Gtk.EventBox):
         vbox.pack_start(halign, False, False, 0)
 
         if self._metadata.get('buddies'):
-            buddies = simplejson.loads(self._metadata['buddies']).values()
+            buddies = json.loads(self._metadata['buddies']).values()
             vbox.pack_start(BuddyList(buddies), False, False, 0)
             return vbox
         else:
diff --git a/src/jarabe/journal/journalentrybundle.py b/src/jarabe/journal/journalentrybundle.py
index 87ae74b..fe910a3 100644
--- a/src/jarabe/journal/journalentrybundle.py
+++ b/src/jarabe/journal/journalentrybundle.py
@@ -18,7 +18,7 @@ import os
 import tempfile
 import shutil
 
-import simplejson
+import json
 import dbus
 
 from sugar3.bundle.bundle import Bundle, MalformedBundleException
@@ -76,7 +76,7 @@ class JournalEntryBundle(Bundle):
             json_data = f.read()
         finally:
             f.close()
-        return simplejson.loads(json_data)
+        return json.loads(json_data)
 
     def _read_preview(self, uid, bundle_dir):
         preview_path = os.path.join(bundle_dir, 'preview', uid)
diff --git a/src/jarabe/journal/listmodel.py b/src/jarabe/journal/listmodel.py
index 980db70..c6562bf 100644
--- a/src/jarabe/journal/listmodel.py
+++ b/src/jarabe/journal/listmodel.py
@@ -16,7 +16,7 @@
 
 import logging
 
-import simplejson
+import json
 from gi.repository import GObject
 from gi.repository import Gtk
 from gettext import gettext as _
@@ -176,8 +176,8 @@ class ListModel(GObject.GObject, Gtk.TreeModel, Gtk.TreeDragSource):
         buddies = []
         if metadata.get('buddies'):
             try:
-                buddies = simplejson.loads(metadata['buddies']).values()
-            except simplejson.decoder.JSONDecodeError, exception:
+                buddies = json.loads(metadata['buddies']).values()
+            except json.decoder.JSONDecodeError, exception:
                 logging.warning('Cannot decode buddies for %r: %s',
                                 metadata['uid'], exception)
 
diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py
index 0a5b354..0a37a78 100644
--- a/src/jarabe/journal/model.py
+++ b/src/jarabe/journal/model.py
@@ -25,7 +25,7 @@ import tempfile
 from stat import S_IFLNK, S_IFMT, S_IFDIR, S_IFREG
 import re
 from operator import itemgetter
-import simplejson
+import json
 from gettext import gettext as _
 
 from gi.repository import GObject
@@ -467,7 +467,7 @@ def _get_file_metadata_from_json(dir_path, filename, fetch_preview):
         return None
 
     try:
-        metadata = simplejson.load(open(metadata_path))
+        metadata = json.load(open(metadata_path))
     except (ValueError, EnvironmentError):
         os.unlink(metadata_path)
         if os.path.exists(preview_path):
@@ -727,7 +727,7 @@ def _write_entry_on_external_device(metadata, file_path):
         metadata_copy.pop('preview', None)
 
     try:
-        metadata_json = simplejson.dumps(metadata_copy)
+        metadata_json = json.dumps(metadata_copy)
     except (UnicodeDecodeError, EnvironmentError):
         logging.error('Could not convert metadata to json.')
     else:
diff --git a/src/jarabe/journal/volumestoolbar.py b/src/jarabe/journal/volumestoolbar.py
index 750aea5..d4210e9 100644
--- a/src/jarabe/journal/volumestoolbar.py
+++ b/src/jarabe/journal/volumestoolbar.py
@@ -27,7 +27,7 @@ from gi.repository import Gdk
 from gi.repository import GConf
 import cPickle
 import xapian
-import simplejson
+import json
 import tempfile
 import shutil
 
@@ -151,7 +151,7 @@ def _convert_entry(root, document):
                                  metadata_fname)
     if not os.path.exists(metadata_path):
         (fh, fn) = tempfile.mkstemp(dir=root)
-        os.write(fh, simplejson.dumps(metadata))
+        os.write(fh, json.dumps(metadata))
         os.close(fh)
         os.rename(fn, metadata_path)
 
diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
index 0c20b9f..85469b0 100644
--- a/src/jarabe/model/bundleregistry.py
+++ b/src/jarabe/model/bundleregistry.py
@@ -22,7 +22,7 @@ from gi.repository import GConf
 from gi.repository import GObject
 from gi.repository import GLib
 from gi.repository import Gio
-import simplejson
+import json
 
 from sugar3.bundle.activitybundle import ActivityBundle
 from sugar3.bundle.contentbundle import ContentBundle
@@ -131,7 +131,7 @@ class BundleRegistry(GObject.GObject):
     def _load_favorites(self):
         favorites_path = env.get_profile_path('favorite_activities')
         if os.path.exists(favorites_path):
-            favorites_data = simplejson.load(open(favorites_path))
+            favorites_data = json.load(open(favorites_path))
 
             favorite_bundles = favorites_data['favorites']
             if not isinstance(favorite_bundles, dict):
@@ -359,7 +359,7 @@ class BundleRegistry(GObject.GObject):
         path = env.get_profile_path('favorite_activities')
         favorites_data = {'defaults-mtime': self._last_defaults_mtime,
                           'favorites': self._favorite_bundles}
-        simplejson.dump(favorites_data, open(path, 'w'), indent=1)
+        json.dump(favorites_data, open(path, 'w'), indent=1)
 
     def is_installed(self, bundle):
         # TODO treat ContentBundle in special way
diff --git a/src/jarabe/model/invites.py b/src/jarabe/model/invites.py
index d2d1721..aa35c09 100644
--- a/src/jarabe/model/invites.py
+++ b/src/jarabe/model/invites.py
@@ -17,7 +17,7 @@
 
 import logging
 from functools import partial
-import simplejson
+import json
 
 from gi.repository import GObject
 import dbus
@@ -270,8 +270,8 @@ class Invites(GObject.GObject):
         connection_path = properties[CHANNEL_DISPATCH_OPERATION +
                                      '.Connection']
         connection_name = connection_path.replace('/', '.')[1:]
-        private_channel = simplejson.dumps([connection_name,
-                                            connection_path, channel_path])
+        private_channel = json.dumps([connection_name,
+                                      connection_path, channel_path])
         invite = PrivateInvite(dispatch_operation_path, handle, handler,
                                private_channel)
         self._dispatch_operations[dispatch_operation_path] = invite
-- 
1.8.1.4



More information about the Sugar-devel mailing list