From 7d2ee84a937588381233c50b3e3632e326b1358e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
Date: Thu, 15 Nov 2012 16:27:22 -0300
Subject: [PATCH shell 3/3] Move from simplejson to standard library json - SL
#3816
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
---
src/jarabe/journal/expandedentry.py | 4 ++--
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, 18 insertions(+), 18 deletions(-)
diff --git a/src/jarabe/journal/expandedentry.py b/src/jarabe/journal/expandedentry.py
index bf34632..b8c340a 100644
a
|
b
|
from gi.repository import GObject |
25 | 25 | import glib |
26 | 26 | from gi.repository import Gtk |
27 | 27 | from gi.repository import Gdk |
28 | | import simplejson |
| 28 | import json |
29 | 29 | |
30 | 30 | from sugar3.graphics import style |
31 | 31 | from sugar3.graphics.xocolor import XoColor |
… |
… |
class ExpandedEntry(Gtk.EventBox): |
311 | 311 | vbox.pack_start(halign, False, False, 0) |
312 | 312 | |
313 | 313 | if self._metadata.get('buddies'): |
314 | | buddies = simplejson.loads(self._metadata['buddies']).values() |
| 314 | buddies = json.loads(self._metadata['buddies']).values() |
315 | 315 | vbox.pack_start(BuddyList(buddies), False, False, 0) |
316 | 316 | return vbox |
317 | 317 | else: |
diff --git a/src/jarabe/journal/journalentrybundle.py b/src/jarabe/journal/journalentrybundle.py
index 87ae74b..fe910a3 100644
a
|
b
|
import os |
18 | 18 | import tempfile |
19 | 19 | import shutil |
20 | 20 | |
21 | | import simplejson |
| 21 | import json |
22 | 22 | import dbus |
23 | 23 | |
24 | 24 | from sugar3.bundle.bundle import Bundle, MalformedBundleException |
… |
… |
class JournalEntryBundle(Bundle): |
76 | 76 | json_data = f.read() |
77 | 77 | finally: |
78 | 78 | f.close() |
79 | | return simplejson.loads(json_data) |
| 79 | return json.loads(json_data) |
80 | 80 | |
81 | 81 | def _read_preview(self, uid, bundle_dir): |
82 | 82 | preview_path = os.path.join(bundle_dir, 'preview', uid) |
diff --git a/src/jarabe/journal/listmodel.py b/src/jarabe/journal/listmodel.py
index b98d01c..53f28b8 100644
a
|
b
|
|
16 | 16 | |
17 | 17 | import logging |
18 | 18 | |
19 | | import simplejson |
| 19 | import json |
20 | 20 | from gi.repository import GObject |
21 | 21 | from gi.repository import Gtk |
22 | 22 | from gettext import gettext as _ |
… |
… |
class ListModel(GObject.GObject, Gtk.TreeModel, Gtk.TreeDragSource): |
176 | 176 | buddies = [] |
177 | 177 | if metadata.get('buddies'): |
178 | 178 | try: |
179 | | buddies = simplejson.loads(metadata['buddies']).values() |
180 | | except simplejson.decoder.JSONDecodeError, exception: |
| 179 | buddies = json.loads(metadata['buddies']).values() |
| 180 | except json.decoder.JSONDecodeError, exception: |
181 | 181 | logging.warning('Cannot decode buddies for %r: %s', |
182 | 182 | metadata['uid'], exception) |
183 | 183 | |
diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py
index 0a5b354..0a37a78 100644
a
|
b
|
import tempfile |
25 | 25 | from stat import S_IFLNK, S_IFMT, S_IFDIR, S_IFREG |
26 | 26 | import re |
27 | 27 | from operator import itemgetter |
28 | | import simplejson |
| 28 | import json |
29 | 29 | from gettext import gettext as _ |
30 | 30 | |
31 | 31 | from gi.repository import GObject |
… |
… |
def _get_file_metadata_from_json(dir_path, filename, fetch_preview): |
467 | 467 | return None |
468 | 468 | |
469 | 469 | try: |
470 | | metadata = simplejson.load(open(metadata_path)) |
| 470 | metadata = json.load(open(metadata_path)) |
471 | 471 | except (ValueError, EnvironmentError): |
472 | 472 | os.unlink(metadata_path) |
473 | 473 | if os.path.exists(preview_path): |
… |
… |
def _write_entry_on_external_device(metadata, file_path): |
727 | 727 | metadata_copy.pop('preview', None) |
728 | 728 | |
729 | 729 | try: |
730 | | metadata_json = simplejson.dumps(metadata_copy) |
| 730 | metadata_json = json.dumps(metadata_copy) |
731 | 731 | except (UnicodeDecodeError, EnvironmentError): |
732 | 732 | logging.error('Could not convert metadata to json.') |
733 | 733 | else: |
diff --git a/src/jarabe/journal/volumestoolbar.py b/src/jarabe/journal/volumestoolbar.py
index 1fc368e..70d6178 100644
a
|
b
|
from gi.repository import Gdk |
27 | 27 | from gi.repository import GConf |
28 | 28 | import cPickle |
29 | 29 | import xapian |
30 | | import simplejson |
| 30 | import json |
31 | 31 | import tempfile |
32 | 32 | import shutil |
33 | 33 | |
… |
… |
def _convert_entry(root, document): |
151 | 151 | metadata_fname) |
152 | 152 | if not os.path.exists(metadata_path): |
153 | 153 | (fh, fn) = tempfile.mkstemp(dir=root) |
154 | | os.write(fh, simplejson.dumps(metadata)) |
| 154 | os.write(fh, json.dumps(metadata)) |
155 | 155 | os.close(fh) |
156 | 156 | os.rename(fn, metadata_path) |
157 | 157 | |
diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
index e441122..9ac2e42 100644
a
|
b
|
import logging |
21 | 21 | from gi.repository import GConf |
22 | 22 | from gi.repository import GObject |
23 | 23 | from gi.repository import Gio |
24 | | import simplejson |
| 24 | import json |
25 | 25 | |
26 | 26 | from sugar3.bundle.activitybundle import ActivityBundle |
27 | 27 | from sugar3.bundle.contentbundle import ContentBundle |
… |
… |
class BundleRegistry(GObject.GObject): |
127 | 127 | def _load_favorites(self): |
128 | 128 | favorites_path = env.get_profile_path('favorite_activities') |
129 | 129 | if os.path.exists(favorites_path): |
130 | | favorites_data = simplejson.load(open(favorites_path)) |
| 130 | favorites_data = json.load(open(favorites_path)) |
131 | 131 | |
132 | 132 | favorite_bundles = favorites_data['favorites'] |
133 | 133 | if not isinstance(favorite_bundles, dict): |
… |
… |
class BundleRegistry(GObject.GObject): |
355 | 355 | path = env.get_profile_path('favorite_activities') |
356 | 356 | favorites_data = {'defaults-mtime': self._last_defaults_mtime, |
357 | 357 | 'favorites': self._favorite_bundles} |
358 | | simplejson.dump(favorites_data, open(path, 'w'), indent=1) |
| 358 | json.dump(favorites_data, open(path, 'w'), indent=1) |
359 | 359 | |
360 | 360 | def is_installed(self, bundle): |
361 | 361 | # 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
|
b
|
|
17 | 17 | |
18 | 18 | import logging |
19 | 19 | from functools import partial |
20 | | import simplejson |
| 20 | import json |
21 | 21 | |
22 | 22 | from gi.repository import GObject |
23 | 23 | import dbus |
… |
… |
class Invites(GObject.GObject): |
270 | 270 | connection_path = properties[CHANNEL_DISPATCH_OPERATION + |
271 | 271 | '.Connection'] |
272 | 272 | connection_name = connection_path.replace('/', '.')[1:] |
273 | | private_channel = simplejson.dumps([connection_name, |
274 | | connection_path, channel_path]) |
| 273 | private_channel = json.dumps([connection_name, |
| 274 | connection_path, channel_path]) |
275 | 275 | invite = PrivateInvite(dispatch_operation_path, handle, handler, |
276 | 276 | private_channel) |
277 | 277 | self._dispatch_operations[dispatch_operation_path] = invite |