/usr/lib/python2.7/dist-packages/cloudfiles/fjson.py is in python-cloudfiles 1.7.11-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | from tokenize import generate_tokens, STRING, NAME, OP
from cStringIO import StringIO
from re import compile, DOTALL
comments = compile(r'/\*.*\*/|//[^\r\n]*', DOTALL)
def _loads(string):
'''
Fairly competent json parser exploiting the python tokenizer and eval()
_loads(serialized_json) -> object
'''
try:
res = []
consts = {'true': True, 'false': False, 'null': None}
string = '(' + comments.sub('', string) + ')'
for type, val, _, _, _ in generate_tokens(StringIO(string).readline):
if (type == OP and val not in '[]{}:,()-') or \
(type == NAME and val not in consts):
raise AttributeError()
elif type == STRING:
res.append('u')
res.append(val.replace('\\/', '/'))
else:
res.append(val)
return eval(''.join(res), {}, consts)
except:
raise AttributeError()
# look for a real json parser first
try:
# 2.6 will have a json module in the stdlib
from json import loads as json_loads
except ImportError:
try:
# simplejson is popular and pretty good
from simplejson import loads as json_loads
# fall back on local parser otherwise
except ImportError:
json_loads = _loads
__all__ = ['json_loads']
|