From 2611a1c8f37e12926aced3f811e793e8606a1e17 Mon Sep 17 00:00:00 2001 From: Manuel QuiƱones Date: Tue, 27 Mar 2012 04:07:27 +0000 Subject: Remove unneded json wrapper Signed-off-by: Manuel QuiƱones --- diff --git a/paintwithme.py b/paintwithme.py index a0033ed..7c2464d 100644 --- a/paintwithme.py +++ b/paintwithme.py @@ -30,8 +30,6 @@ from sugar.presence.tubeconn import TubeConnection from toolbar import PaintToolbar from drawing import Drawing -# FIXME use json from standard lib -from utils import json_load, json_dump SERVICE = 'org.sugarlabs.PaintWithMeActivity' @@ -185,20 +183,20 @@ params=%r state=%d' % (id, initiator, type, service, params, state)) def send_new_drawing(self): """Send a new width, height to all players.""" - self.send_event('n|%s' % (json_dump(self._drawing.get_size()))) + self.send_event('n|%s' % (json.dumps(self._drawing.get_size()))) def _receive_new_drawing(self, payload): """Sharer can start a new drawing.""" - width, height = json_load(payload) + width, height = json.loads(payload) self._drawing.setup(width, height) def send_stroke(self, stroke_points, settings): """Send a new stroke to all the players.""" - self.send_event('p|%s' % (json_dump((stroke_points, settings)))) + self.send_event('p|%s' % (json.dumps((stroke_points, settings)))) def _receive_stroke(self, payload): """When a stroke is finished, everyone should show it.""" - stroke_points, settings = json_load(payload) + stroke_points, settings = json.loads(payload) self._drawing.remote_stroke(stroke_points, settings) def send_event(self, entry): diff --git a/utils.py b/utils.py deleted file mode 100644 index ffab831..0000000 --- a/utils.py +++ /dev/null @@ -1,53 +0,0 @@ -#Copyright (c) 2011 Walter Bender - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# You should have received a copy of the GNU General Public License -# along with this library; if not, write to the Free Software -# Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA - - -from StringIO import StringIO -try: - OLD_SUGAR_SYSTEM = False - import json - json.dumps - from json import load as jload - from json import dump as jdump -except (ImportError, AttributeError): - try: - import simplejson as json - from simplejson import load as jload - from simplejson import dump as jdump - except: - OLD_SUGAR_SYSTEM = True - - -def json_load(text): - """ Load JSON data using what ever resources are available. """ - if OLD_SUGAR_SYSTEM is True: - listdata = json.read(text) - else: - # strip out leading and trailing whitespace, nulls, and newlines - io = StringIO(text) - try: - listdata = jload(io) - except ValueError: - # assume that text is ascii list - listdata = text.split() - for i, value in enumerate(listdata): - listdata[i] = int(value) - return listdata - - -def json_dump(data): - """ Save data using available JSON tools. """ - if OLD_SUGAR_SYSTEM is True: - return json.write(data) - else: - _io = StringIO() - jdump(data, _io) - return _io.getvalue() -- cgit v0.9.1