diff --git a/src/calibre/ebooks/pdb/header.py b/src/calibre/ebooks/pdb/header.py index 86ae4d3bcc..eb2a786dfd 100644 --- a/src/calibre/ebooks/pdb/header.py +++ b/src/calibre/ebooks/pdb/header.py @@ -67,8 +67,8 @@ class PdbHeaderReader(object): class PdbHeaderBuilder(object): def __init__(self, identity, title): - self.identity = identity.ljust(3, '\x00')[:8] - self.title = '%s\x00' % re.sub('[^-A-Za-z0-9 ]+', '_', title).ljust(31, '\x00')[:31].encode('ascii', 'replace') + 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') def build_header(self, section_lengths, out_stream): ''' @@ -85,4 +85,4 @@ class PdbHeaderBuilder(object): for id, record in enumerate(section_lengths): out_stream.write(struct.pack('>LBBBB', long_type(offset), 0, 0, 0, 0)) offset += record - out_stream.write('\x00\x00') + out_stream.write(b'\x00\x00') diff --git a/src/calibre/ebooks/pdb/palmdoc/writer.py b/src/calibre/ebooks/pdb/palmdoc/writer.py index 390329b124..13d69b451f 100644 --- a/src/calibre/ebooks/pdb/palmdoc/writer.py +++ b/src/calibre/ebooks/pdb/palmdoc/writer.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import division ''' Writer content to palmdoc pdb file. @@ -57,13 +58,13 @@ class Writer(FormatWriter): txt_length = len(txt) txt_records = [] - for i in range(0, (len(txt) / MAX_RECORD_SIZE) + 1): + for i in range(0, (len(txt) // MAX_RECORD_SIZE) + 1): txt_records.append(txt[i * MAX_RECORD_SIZE: (i * MAX_RECORD_SIZE) + MAX_RECORD_SIZE]) return txt_records, txt_length def _header_record(self, txt_length, record_count): - record = '' + record = b'' record += struct.pack('>H', 2) # [0:2], PalmDoc compression. (1 = No compression). record += struct.pack('>H', 0) # [2:4], Always 0. @@ -73,4 +74,3 @@ class Writer(FormatWriter): record += struct.pack('>L', 0) # [12-16], Current reading position, as an offset into the uncompressed text. return record -