-
Notifications
You must be signed in to change notification settings - Fork 22
/
json.cjson.py.old
46 lines (39 loc) · 1.15 KB
/
json.cjson.py.old
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
JSON convenience routines.
We use python-cjson because it is far faster than simplejson on certain installs:
http://blog.metaoptimize.com/2009/03/22/fast-deserialization-in-python/
Note that cjson 1.0.5 is buggy:
http://blog.extracheese.org/2007/07/when-json-isnt-json.html
http://www.vazor.com/cjson.html
"""
import cjson
if cjson.__version__ != "1.0.6":
import sys
print >> sys.stderr, "WARNING: cjson < 1.0.6 is buggy (your version=%s)" % cjson.__version__
print >> sys.stderr, " http://blog.extracheese.org/2007/07/when-json-isnt-json.html"
print >> sys.stderr, " http://www.vazor.com/cjson.html"
encode = cjson.encode
decode = cjson.decode
loads = decode
dumps = encode
from common.file import myopen
def load(file):
"""
Load JSON from a stream.
"""
return decode(file.read())
def dump(file, object):
"""
Dump JSON to a stream.
"""
return file.write(encode(filename, object))
def loadfile(filename):
"""
Load JSON from a filename.
"""
return load(myopen(filename))
def dumpfile(filename, object):
"""
Dump JSON to a filename.
"""
return dump(myopen(filename, "wb"))