7 def epubcheck(filename):
 
  16     output = json.loads(p.stdout)
 
  17     epub = zipfile.ZipFile(filename)
 
  18     messages = output.get('messages', [])
 
  19     for message in messages:
 
  20         for loc in message.get('locations', []):
 
  21             if loc['path'].startswith('EPUB/part'):
 
  22                 with epub.open(loc['path']) as zfile:
 
  23                     text = zfile.read().decode('utf-8')
 
  24                 line = text.split('\n')[loc['line'] - 1][:loc['column'] - 1:]
 
  25                 debug = re.findall(r' data-debug="(\d+):(\d+)', line)
 
  28                     loc['wl_chunk'] = int(debug[0])
 
  29                     loc['wl_line'] = int(debug[1])