mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
py3: make pdb output work
This commit is contained in:
parent
f32ea26bf1
commit
ab7e134a40
@ -67,8 +67,8 @@ class PdbHeaderReader(object):
|
|||||||
class PdbHeaderBuilder(object):
|
class PdbHeaderBuilder(object):
|
||||||
|
|
||||||
def __init__(self, identity, title):
|
def __init__(self, identity, title):
|
||||||
self.identity = identity.ljust(3, '\x00')[:8]
|
self.identity = identity.ljust(3, '\x00')[:8].encode('utf-8')
|
||||||
self.title = '%s\x00' % re.sub('[^-A-Za-z0-9 ]+', '_', title).ljust(31, '\x00')[:31].encode('ascii', 'replace')
|
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):
|
def build_header(self, section_lengths, out_stream):
|
||||||
'''
|
'''
|
||||||
@ -85,4 +85,4 @@ class PdbHeaderBuilder(object):
|
|||||||
for id, record in enumerate(section_lengths):
|
for id, record in enumerate(section_lengths):
|
||||||
out_stream.write(struct.pack('>LBBBB', long_type(offset), 0, 0, 0, 0))
|
out_stream.write(struct.pack('>LBBBB', long_type(offset), 0, 0, 0, 0))
|
||||||
offset += record
|
offset += record
|
||||||
out_stream.write('\x00\x00')
|
out_stream.write(b'\x00\x00')
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Writer content to palmdoc pdb file.
|
Writer content to palmdoc pdb file.
|
||||||
@ -57,13 +58,13 @@ class Writer(FormatWriter):
|
|||||||
txt_length = len(txt)
|
txt_length = len(txt)
|
||||||
|
|
||||||
txt_records = []
|
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])
|
txt_records.append(txt[i * MAX_RECORD_SIZE: (i * MAX_RECORD_SIZE) + MAX_RECORD_SIZE])
|
||||||
|
|
||||||
return txt_records, txt_length
|
return txt_records, txt_length
|
||||||
|
|
||||||
def _header_record(self, txt_length, record_count):
|
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', 2) # [0:2], PalmDoc compression. (1 = No compression).
|
||||||
record += struct.pack('>H', 0) # [2:4], Always 0.
|
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.
|
record += struct.pack('>L', 0) # [12-16], Current reading position, as an offset into the uncompressed text.
|
||||||
|
|
||||||
return record
|
return record
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user