forked from nlplab/brat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jsonwrap.py
36 lines (26 loc) · 1023 Bytes
/
jsonwrap.py
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
'''
json wrapper to be used instead of a direct call.
Author: Pontus Stenetorp <pontus is s u-tokyo ac jp>
Version: 2011-04-21
'''
from functools import partial
try:
from json import dumps as _lib_dumps
from json import loads as _lib_loads
except ImportError:
# We are on an older Python, use our included lib
from sys import path as sys_path
from os.path import join as path_join
from os.path import dirname
sys_path.append('../lib/simplejson-2.1.5')
from simplejson import dumps as _lib_dumps
from simplejson import loads as _lib_loads
# Wrap the loads and dumps to expect utf-8
lib_dumps = partial(_lib_dumps, encoding='utf-8')#, ensure_ascii=False)
lib_loads = partial(_lib_loads, encoding='utf-8')#, ensure_ascii=False)
#ensure_ascii[, check_circular[, allow_nan[, cls[, indent[, separators[, encoding
def dumps(dic):
return lib_dumps(dic, sort_keys=True, indent=2)
def loads(s):
return lib_loads(s)
# TODO: Unittest that tries the import, encoding etc.