2011-10-12 10:19:57 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
2016-08-23 16:12:46 +00:00
|
|
|
from __future__ import print_function
|
2011-10-12 10:19:57 +00:00
|
|
|
|
2015-11-12 12:01:29 +00:00
|
|
|
import re
|
|
|
|
|
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)
|
2015-11-12 12:01:29 +00:00
|
|
|
except ValueError as e:
|
|
|
|
msg = e.message if hasattr(e, 'message') else str(e)
|
|
|
|
lineno = None
|
|
|
|
colno = None
|
|
|
|
try:
|
|
|
|
m = re.search(r'line (\d+) column (\d+)', msg)
|
|
|
|
if m:
|
2016-06-08 13:32:46 +00:00
|
|
|
(lineno, colno) = [int(n) for n in m.groups()]
|
2015-11-12 12:01:29 +00:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
if lineno and colno:
|
|
|
|
s = minified.split('\n')
|
|
|
|
context = s[lineno-1][max(0, colno-30):colno+30]
|
2016-06-08 13:32:46 +00:00
|
|
|
msg += ' at:\n\n %s\n %s\033[1m^\033[0m' % (context, ' ' * (colno - max(0, colno-30) - 2))
|
2015-11-12 12:01:29 +00:00
|
|
|
raise ValueError(msg)
|