Ticket #3816: 0003-Move-from-simplejson-to-standard-library-json-SL-381.patch

File 0003-Move-from-simplejson-to-standard-library-json-SL-381.patch, 7.5 KB (added by manuq, 11 years ago)

Patch for sugar component

  • src/jarabe/journal/expandedentry.py

    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 
    2525import glib
    2626from gi.repository import Gtk
    2727from gi.repository import Gdk
    28 import simplejson
     28import json
    2929
    3030from sugar3.graphics import style
    3131from sugar3.graphics.xocolor import XoColor
    class ExpandedEntry(Gtk.EventBox): 
    311311        vbox.pack_start(halign, False, False, 0)
    312312
    313313        if self._metadata.get('buddies'):
    314             buddies = simplejson.loads(self._metadata['buddies']).values()
     314            buddies = json.loads(self._metadata['buddies']).values()
    315315            vbox.pack_start(BuddyList(buddies), False, False, 0)
    316316            return vbox
    317317        else:
  • src/jarabe/journal/journalentrybundle.py

    diff --git a/src/jarabe/journal/journalentrybundle.py b/src/jarabe/journal/journalentrybundle.py
    index 87ae74b..fe910a3 100644
    a b import os 
    1818import tempfile
    1919import shutil
    2020
    21 import simplejson
     21import json
    2222import dbus
    2323
    2424from sugar3.bundle.bundle import Bundle, MalformedBundleException
    class JournalEntryBundle(Bundle): 
    7676            json_data = f.read()
    7777        finally:
    7878            f.close()
    79         return simplejson.loads(json_data)
     79        return json.loads(json_data)
    8080
    8181    def _read_preview(self, uid, bundle_dir):
    8282        preview_path = os.path.join(bundle_dir, 'preview', uid)
  • src/jarabe/journal/listmodel.py

    diff --git a/src/jarabe/journal/listmodel.py b/src/jarabe/journal/listmodel.py
    index b98d01c..53f28b8 100644
    a b  
    1616
    1717import logging
    1818
    19 import simplejson
     19import json
    2020from gi.repository import GObject
    2121from gi.repository import Gtk
    2222from gettext import gettext as _
    class ListModel(GObject.GObject, Gtk.TreeModel, Gtk.TreeDragSource): 
    176176        buddies = []
    177177        if metadata.get('buddies'):
    178178            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:
    181181                logging.warning('Cannot decode buddies for %r: %s',
    182182                                metadata['uid'], exception)
    183183
  • src/jarabe/journal/model.py

    diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py
    index 0a5b354..0a37a78 100644
    a b import tempfile 
    2525from stat import S_IFLNK, S_IFMT, S_IFDIR, S_IFREG
    2626import re
    2727from operator import itemgetter
    28 import simplejson
     28import json
    2929from gettext import gettext as _
    3030
    3131from gi.repository import GObject
    def _get_file_metadata_from_json(dir_path, filename, fetch_preview): 
    467467        return None
    468468
    469469    try:
    470         metadata = simplejson.load(open(metadata_path))
     470        metadata = json.load(open(metadata_path))
    471471    except (ValueError, EnvironmentError):
    472472        os.unlink(metadata_path)
    473473        if os.path.exists(preview_path):
    def _write_entry_on_external_device(metadata, file_path): 
    727727        metadata_copy.pop('preview', None)
    728728
    729729    try:
    730         metadata_json = simplejson.dumps(metadata_copy)
     730        metadata_json = json.dumps(metadata_copy)
    731731    except (UnicodeDecodeError, EnvironmentError):
    732732        logging.error('Could not convert metadata to json.')
    733733    else:
  • src/jarabe/journal/volumestoolbar.py

    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 
    2727from gi.repository import GConf
    2828import cPickle
    2929import xapian
    30 import simplejson
     30import json
    3131import tempfile
    3232import shutil
    3333
    def _convert_entry(root, document): 
    151151                                 metadata_fname)
    152152    if not os.path.exists(metadata_path):
    153153        (fh, fn) = tempfile.mkstemp(dir=root)
    154         os.write(fh, simplejson.dumps(metadata))
     154        os.write(fh, json.dumps(metadata))
    155155        os.close(fh)
    156156        os.rename(fn, metadata_path)
    157157
  • src/jarabe/model/bundleregistry.py

    diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
    index e441122..9ac2e42 100644
    a b import logging 
    2121from gi.repository import GConf
    2222from gi.repository import GObject
    2323from gi.repository import Gio
    24 import simplejson
     24import json
    2525
    2626from sugar3.bundle.activitybundle import ActivityBundle
    2727from sugar3.bundle.contentbundle import ContentBundle
    class BundleRegistry(GObject.GObject): 
    127127    def _load_favorites(self):
    128128        favorites_path = env.get_profile_path('favorite_activities')
    129129        if os.path.exists(favorites_path):
    130             favorites_data = simplejson.load(open(favorites_path))
     130            favorites_data = json.load(open(favorites_path))
    131131
    132132            favorite_bundles = favorites_data['favorites']
    133133            if not isinstance(favorite_bundles, dict):
    class BundleRegistry(GObject.GObject): 
    355355        path = env.get_profile_path('favorite_activities')
    356356        favorites_data = {'defaults-mtime': self._last_defaults_mtime,
    357357                          'favorites': self._favorite_bundles}
    358         simplejson.dump(favorites_data, open(path, 'w'), indent=1)
     358        json.dump(favorites_data, open(path, 'w'), indent=1)
    359359
    360360    def is_installed(self, bundle):
    361361        # TODO treat ContentBundle in special way
  • src/jarabe/model/invites.py

    diff --git a/src/jarabe/model/invites.py b/src/jarabe/model/invites.py
    index d2d1721..aa35c09 100644
    a b  
    1717
    1818import logging
    1919from functools import partial
    20 import simplejson
     20import json
    2121
    2222from gi.repository import GObject
    2323import dbus
    class Invites(GObject.GObject): 
    270270        connection_path = properties[CHANNEL_DISPATCH_OPERATION +
    271271                                     '.Connection']
    272272        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])
    275275        invite = PrivateInvite(dispatch_operation_path, handle, handler,
    276276                               private_channel)
    277277        self._dispatch_operations[dispatch_operation_path] = invite