Ticket #1553: 0001-Revert-Move-to-cjson-and-drop-pyjson-and-simplejson.patch

File 0001-Revert-Move-to-cjson-and-drop-pyjson-and-simplejson.patch, 5.4 KB (added by dsd, 14 years ago)

patch

  • src/jarabe/journal/expandedentry.py

    From 97c978092da7f66db0f6f58782a7bee801fde5ac Mon Sep 17 00:00:00 2001
    From: Daniel Drake <dsd@laptop.org>
    Date: Wed, 18 Nov 2009 12:17:47 +0000
    Subject: [PATCH] Revert "Move to cjson and drop pyjson and simplejson"
    
    This reverts commit ee4535c98ae74347e7072909d49dcf8a5e16ca7b.
    
    cjson has a big bug dealing with slashes, this is a significant
    long-term bug and upstream has not been responsive other than
    acknowledging it. This bug breaks journal entry bundles.
    http://dev.sugarlabs.org/ticket/1553
    
    Thanks to Martin Langhoff for identifying and researching this issue
    ---
     src/jarabe/journal/expandedentry.py      |    6 ++++--
     src/jarabe/journal/journalentrybundle.py |    9 +++++++--
     src/jarabe/journal/listmodel.py          |    6 ++++--
     src/jarabe/model/bundleregistry.py       |    6 +++---
     src/jarabe/model/owner.py                |    4 ++--
     5 files changed, 20 insertions(+), 11 deletions(-)
    
    diff --git a/src/jarabe/journal/expandedentry.py b/src/jarabe/journal/expandedentry.py
    index 94d90ed..4463cac 100644
    a b import hippo 
    2323import cairo
    2424import gobject
    2525import gtk
    26 import cjson
     26import json
    2727
    2828from sugar.graphics import style
    2929from sugar.graphics.icon import CanvasIcon
    class ExpandedEntry(hippo.CanvasBox): 
    303303
    304304        if self._metadata.has_key('buddies') and \
    305305                self._metadata['buddies']:
    306             buddies = cjson.decode(self._metadata['buddies']).values()
     306            # json cannot read unicode strings
     307            buddies_str = self._metadata['buddies'].encode('utf8')
     308            buddies = json.read(buddies_str).values()
    307309            vbox.append(BuddyList(buddies))
    308310            return vbox
    309311        else:
  • src/jarabe/journal/journalentrybundle.py

    diff --git a/src/jarabe/journal/journalentrybundle.py b/src/jarabe/journal/journalentrybundle.py
    index ebe7ec3..a0bc935 100644
    a b import os 
    1818import tempfile
    1919import shutil
    2020
    21 import cjson
     21import json
    2222import dbus
    2323
    2424from sugar.bundle.bundle import Bundle, MalformedBundleException
    class JournalEntryBundle(Bundle): 
    7070        if not os.path.exists(metadata_path):
    7171            raise MalformedBundleException(
    7272                    'Bundle must contain the file "_metadata.json"')
    73         return cjson.decode(open(metadata_path, 'r').read())
     73        f = open(metadata_path, 'r')
     74        try:
     75            json_data = f.read()
     76        finally:
     77            f.close()
     78        return json.read(json_data)
    7479
    7580    def _read_preview(self, uid, bundle_dir):
    7681        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 32df853..bc53a9c 100644
    a b  
    1616
    1717import logging
    1818
    19 import cjson
     19import json
    2020import gobject
    2121import gtk
    2222
    class ListModel(gtk.GenericTreeModel, gtk.TreeDragSource): 
    144144        self._cached_row.append(int(metadata.get('progress', 100)))
    145145
    146146        if metadata.get('buddies', ''):
    147             buddies = cjson.decode(metadata['buddies']).values()
     147            # json cannot read unicode strings
     148            buddies_str = metadata['buddies'].encode('utf8')
     149            buddies = json.read(buddies_str).values()
    148150        else:
    149151            buddies = []
    150152
  • src/jarabe/model/bundleregistry.py

    diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
    index b754952..aa49c72 100644
    a b import traceback 
    2121
    2222import gobject
    2323import gio
    24 import cjson
     24import simplejson
    2525
    2626from sugar.bundle.activitybundle import ActivityBundle
    2727from sugar.bundle.contentbundle import ContentBundle
    class BundleRegistry(gobject.GObject): 
    107107    def _load_favorites(self):
    108108        favorites_path = env.get_profile_path('favorite_activities')
    109109        if os.path.exists(favorites_path):
    110             favorites_data = cjson.decode(open(favorites_path).read())
     110            favorites_data = simplejson.load(open(favorites_path))
    111111
    112112            favorite_bundles = favorites_data['favorites']
    113113            if not isinstance(favorite_bundles, dict):
    class BundleRegistry(gobject.GObject): 
    322322        path = env.get_profile_path('favorite_activities')
    323323        favorites_data = {'defaults-mtime': self._last_defaults_mtime,
    324324                          'favorites': self._favorite_bundles}
    325         open(path, 'w').write(cjson.encode(favorites_data))
     325        simplejson.dump(favorites_data, open(path, 'w'), indent=1)
    326326
    327327    def is_installed(self, bundle):
    328328        # TODO treat ContentBundle in special way
  • src/jarabe/model/owner.py

    diff --git a/src/jarabe/model/owner.py b/src/jarabe/model/owner.py
    index 2075f08..17996e6 100644
    a b  
    1717
    1818import gobject
    1919import os
    20 import cjson
    2120import gconf
     21import simplejson
    2222
    2323from telepathy.interfaces import CHANNEL_TYPE_TEXT
    2424
    class Owner(gobject.GObject): 
    9898            bundle_id = 'org.laptop.Chat'
    9999        else:
    100100            bundle_id = 'org.laptop.VideoChat'
    101         tp_channel = cjson.encode([bus_name, connection, channel])
     101        tp_channel = simplejson.dumps([bus_name, connection, channel])
    102102        self._invites.add_private_invite(tp_channel, bundle_id)
    103103
    104104    def _activity_disappeared_cb(self, pservice, activity):