From ee4535c98ae74347e7072909d49dcf8a5e16ca7b Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Wed, 08 Oct 2008 15:28:32 +0000 Subject: Move to cjson and drop pyjson and simplejson --- (limited to 'src') diff --git a/src/jarabe/journal/collapsedentry.py b/src/jarabe/journal/collapsedentry.py index 235ac4c..c2cc9c8 100644 --- a/src/jarabe/journal/collapsedentry.py +++ b/src/jarabe/journal/collapsedentry.py @@ -20,7 +20,7 @@ from gettext import gettext as _ import gobject import gtk import hippo -import json +import cjson from sugar.graphics.icon import CanvasIcon from sugar.graphics.xocolor import XoColor @@ -165,9 +165,7 @@ class BaseCollapsedEntry(hippo.CanvasBox): def _decode_buddies(self): if self.jobject.metadata.has_key('buddies') and \ self.jobject.metadata['buddies']: - # json cannot read unicode strings - buddies_str = self.jobject.metadata['buddies'].encode('utf8') - buddies = json.read(buddies_str).values() + buddies = cjson.decode(self._jobject.metadata['buddies']).values() else: buddies = [] return buddies diff --git a/src/jarabe/journal/expandedentry.py b/src/jarabe/journal/expandedentry.py index 8957728..9f99d3a 100644 --- a/src/jarabe/journal/expandedentry.py +++ b/src/jarabe/journal/expandedentry.py @@ -22,7 +22,7 @@ import hippo import cairo import gobject import gtk -import json +import cjson from sugar.graphics import style from sugar.graphics.icon import CanvasIcon @@ -251,9 +251,7 @@ class ExpandedEntry(hippo.CanvasBox): if self._jobject.metadata.has_key('buddies') and \ self._jobject.metadata['buddies']: - # json cannot read unicode strings - buddies_str = self._jobject.metadata['buddies'].encode('utf8') - buddies = json.read(buddies_str).values() + buddies = cjson.decode(self._jobject.metadata['buddies']).values() vbox.append(BuddyList(buddies)) return vbox else: diff --git a/src/jarabe/journal/journalentrybundle.py b/src/jarabe/journal/journalentrybundle.py index 8862ca3..b3efe92 100644 --- a/src/jarabe/journal/journalentrybundle.py +++ b/src/jarabe/journal/journalentrybundle.py @@ -18,7 +18,7 @@ import os import tempfile import shutil -import json +import cjson import dbus from sugar.datastore import datastore @@ -72,12 +72,7 @@ class JournalEntryBundle(Bundle): if not os.path.exists(metadata_path): raise MalformedBundleException( 'Bundle must contain the file "_metadata.json"') - f = open(metadata_path, 'r') - try: - json_data = f.read() - finally: - f.close() - return json.read(json_data) + return cjson.decode(open(metadata_path, 'r').read()) def _read_preview(self, uid, bundle_dir): preview_path = os.path.join(bundle_dir, 'preview', uid) diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py index 5599b81..e760e58 100644 --- a/src/jarabe/model/bundleregistry.py +++ b/src/jarabe/model/bundleregistry.py @@ -19,7 +19,7 @@ import logging import traceback import gobject -import simplejson +import cjson from sugar.bundle.activitybundle import ActivityBundle from sugar.bundle.bundle import MalformedBundleException, \ @@ -87,7 +87,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 = cjson.decode(open(favorites_path).read()) favorite_bundles = favorites_data['favorites'] if not isinstance(favorite_bundles, dict): @@ -281,7 +281,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) + open(path, 'w').write(cjson.encode(favorites_data)) def is_installed(self, bundle): return self.get_activity(bundle.get_bundle_id()) is not None diff --git a/src/jarabe/model/owner.py b/src/jarabe/model/owner.py index 0218278..73beba8 100644 --- a/src/jarabe/model/owner.py +++ b/src/jarabe/model/owner.py @@ -17,7 +17,7 @@ import gobject import os -import simplejson +import cjson from telepathy.interfaces import CHANNEL_TYPE_TEXT @@ -97,7 +97,7 @@ class Owner(gobject.GObject): bundle_id = 'org.laptop.Chat' else: bundle_id = 'org.laptop.VideoChat' - tp_channel = simplejson.dumps([bus_name, connection, channel]) + tp_channel = cjson.encode([bus_name, connection, channel]) self._invites.add_private_invite(tp_channel, bundle_id) def _activity_disappeared_cb(self, pservice, activity): -- cgit v0.9.1