mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3 compat: Fix PDB ereader output broken in calibre 5
Fixes #1954889 [Error when converting to pdb ereader](https://bugs.launchpad.net/calibre/+bug/1954889)
This commit is contained in:
parent
2c6a73534a
commit
0a9778caa3
@ -67,7 +67,7 @@ class Writer(FormatWriter):
|
||||
|
||||
lengths = [len(i) if i not in images else len(i[0]) + len(i[1]) for i in sections]
|
||||
|
||||
pdbHeaderBuilder = PdbHeaderBuilder(IDENTITY, metadata[0].partition('\x00')[0])
|
||||
pdbHeaderBuilder = PdbHeaderBuilder(IDENTITY, metadata[0].partition(b'\x00')[0])
|
||||
pdbHeaderBuilder.build_header(lengths, out_stream)
|
||||
|
||||
for item in sections:
|
||||
|
@ -70,7 +70,9 @@ class PdbHeaderBuilder:
|
||||
|
||||
def __init__(self, identity, title):
|
||||
self.identity = identity.ljust(3, '\x00')[:8].encode('utf-8')
|
||||
self.title = b'%s\x00' % re.sub('[^-A-Za-z0-9 ]+', '_', title).ljust(31, '\x00')[:31].encode('ascii', 'replace')
|
||||
if isinstance(title, str):
|
||||
title = title.encode('ascii', 'replace')
|
||||
self.title = b'%s\x00' % re.sub(b'[^-A-Za-z0-9 ]+', b'_', title).ljust(31, b'\x00')[:31]
|
||||
|
||||
def build_header(self, section_lengths, out_stream):
|
||||
'''
|
||||
|
Loading…
x
Reference in New Issue
Block a user