Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils.py')
-rw-r--r--utils.py49
1 files changed, 17 insertions, 32 deletions
diff --git a/utils.py b/utils.py
index ffab831..81a76f8 100644
--- a/utils.py
+++ b/utils.py
@@ -1,4 +1,4 @@
-#Copyright (c) 2011 Walter Bender
+#Copyright (c) 2011,12 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
@@ -11,43 +11,28 @@
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
+import json
+json.dumps
+from json import load as jload
+from json import dump as jdump
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)
+ # 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()
+ _io = StringIO()
+ jdump(data, _io)
+ return _io.getvalue()