Output headers for individual index records when debug dumping AZW3

This commit is contained in:
Kovid Goyal 2014-03-28 22:08:32 +05:30
parent eef92506fb
commit 12de61ac1d
2 changed files with 22 additions and 14 deletions

View File

@ -50,8 +50,12 @@ class Index(object):
def __init__(self, idx, records, codec):
self.table = self.cncx = self.header = self.records = None
self.index_headers = []
if idx != NULL_INDEX:
self.table, self.cncx, self.header = read_index(records, idx, codec)
if self.header is not None:
for i in xrange(idx + 1, idx + 1 + self.header['count']):
self.index_headers.append(parse_indx_header(records[i].raw))
def render(self):
ans = ['*'*10 + ' Index Header ' + '*'*10]
@ -60,6 +64,11 @@ class Index(object):
for field in INDEX_HEADER_FIELDS:
a('%-12s: %r'%(field, self.header[field]))
ans.extend(['', ''])
ans += ['*'*10 + ' Index Record Headers (%d records) ' % len(self.index_headers) + '*'*10]
for i, header in enumerate(self.index_headers):
ans += ['*'*10 + ' Index Record %d ' % i + '*'*10]
for field in INDEX_HEADER_FIELDS:
a('%-12s: %r'%(field, header[field]))
if self.cncx:
a('*'*10 + ' CNCX ' + '*'*10)
@ -194,5 +203,3 @@ class NCXIndex(Index):
last_child=refindx(e, 'childn'), title=e['text'],
pos_fid=e['pos_fid'], kind=e['kind'])
self.records.append(entry)

View File

@ -239,6 +239,7 @@ def parse_index_record(table, data, control_byte_count, tags, codec,
rec = rec[consumed:]
tag_map = get_tag_map(control_byte_count, tags, rec, strict=strict)
table[ident] = tag_map
return header
def read_index(sections, idx, codec):
table, cncx = OrderedDict(), CNCX([], codec)