def _parse_json_line(self, f, l_no):
'''
- read from a file and parses a json line and prints it on screen on error
+ Read line from file like object and process it as JSON.
'''
l = f.readline()
l_no += 1
try:
j = json.loads(l.decode('UTF-8'))
+ except UnicodeDecodeError as e:
+ if tuple (l [0:2]) == tarfile.GZ_MAGIC:
+ raise Exception \
+ ("error parsing line #%d as json: looks like a compressed file (%d B: [%s..])"
+ % (l_no, len (l), binascii.hexlify (l [:16]).decode ())) \
+ from e
+ raise Exception \
+ ("error parsing line #%d as json: not a text file (%d B: [%s..])"
+ % (l_no, len (l), binascii.hexlify (l [:16]).decode ())) \
+ from e
except ValueError as e:
raise Exception("error parsing this json line "
"(line number %d): %s" % (l_no, l))