diff options
author | Manuel Quiñones <manuq@laptop.org> | 2012-03-27 04:07:27 (GMT) |
---|---|---|
committer | Manuel Quiñones <manuq@laptop.org> | 2012-03-27 04:07:27 (GMT) |
commit | 2611a1c8f37e12926aced3f811e793e8606a1e17 (patch) | |
tree | b804c744655534a5c60d89476cd4db7bbe1565da | |
parent | 264f4db5a1618b6ab6017c9d1c71e66dffc6f54a (diff) |
Remove unneded json wrapper
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
-rw-r--r-- | paintwithme.py | 10 | ||||
-rw-r--r-- | utils.py | 53 |
2 files changed, 4 insertions, 59 deletions
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() |