2011-10-12 10:19:57 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
2014-09-30 19:04:46 +00:00
|
|
|
from __future__ import with_statement, print_function
|
2011-10-12 10:19:57 +00:00
|
|
|
|
2014-09-30 19:04:46 +00:00
|
|
|
from .js import minify
|
|
|
|
from .utils import json
|
2011-10-12 10:19:57 +00:00
|
|
|
|
|
|
|
|
2011-10-12 10:26:26 +00:00
|
|
|
def load(f):
|
|
|
|
return loads(f.read())
|
2011-10-12 10:19:57 +00:00
|
|
|
|
|
|
|
def loads(source):
|
2012-05-04 18:28:48 +00:00
|
|
|
try:
|
|
|
|
minified = minify(source)
|
|
|
|
return json.loads(minified)
|
2014-09-30 19:04:46 +00:00
|
|
|
except json.JSONDecodeError as e:
|
2012-05-04 18:28:48 +00:00
|
|
|
s = minified.split('\n')
|
|
|
|
context = s[e.lineno-1][max(0, e.colno-1):e.colno+30]
|
|
|
|
msg = e.msg + ' at ' + context
|
|
|
|
raise json.JSONDecodeError(msg, minified, e.pos)
|