1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-13 09:46:25 +00:00

kindlesplit: Python3 update

This commit is contained in:
Paweł Jastrzębski
2014-01-16 13:37:36 +01:00
parent 450076e6e8
commit f12361e7cf

View File

@@ -100,11 +100,11 @@ def nullsection(datain, secno): # make it zero-length without deleting it
datalst.append(struct.pack('>L', ofs) + struct.pack('>L', flgval))
lpad = zerosecstart - (first_pdb_record + 8*nsec)
if lpad > 0:
datalst.append('\0' * lpad)
datalst.append(b'\0' * lpad)
datalst.append(datain[zerosecstart: secstart])
datalst.append(datain[secend:])
dataout = "".join(str(datalst)[1:-1])
return dataout.encode('utf-8')
dataout = b"".join(datalst)
return dataout
def deletesectionrange(datain, firstsec, lastsec): # delete a range of sections
@@ -130,11 +130,11 @@ def deletesectionrange(datain, firstsec, lastsec): # delete a range of sections
datalst.append(struct.pack('>L', ofs) + struct.pack('>L', flgval))
lpad = newstart - (first_pdb_record + 8*(nsec - (lastsec - firstsec + 1)))
if lpad > 0:
datalst.append('\0' * lpad)
datalst.append(b'\0' * lpad)
datalst.append(datain[zerosecstart:firstsecstart])
datalst.append(datain[lastsecend:])
dataout = "".join(str(datalst)[1:-1])
return dataout.encode('utf-8')
dataout = b"".join(datalst)
return dataout
def insertsection(datain, secno, secdata): # insert a new section
@@ -160,18 +160,17 @@ def insertsection(datain, secno, secdata): # insert a new section
datalst.append(struct.pack('>L', ofs) + struct.pack('>L', flgval))
lpad = newstart - (first_pdb_record + 8*(nsec + 1))
if lpad > 0:
datalst.append('\0' * lpad)
datalst.append(b'\0' * lpad)
datalst.append(datain[zerosecstart:secstart])
datalst.append(secdata)
datalst.append(datain[secstart:])
dataout = "".join(str(datalst)[1:-1])
return dataout.encode('utf-8')
dataout = b"".join(datalst)
return dataout
def insertsectionrange(sectionsource, firstsec, lastsec, sectiontarget, targetsec): # insert a range of sections
dataout = sectiontarget
for idx in range(lastsec, firstsec-1, -1):
print(dataout)
dataout = insertsection(dataout, targetsec, readsection(sectionsource, idx))
return dataout
@@ -287,7 +286,7 @@ class mobi_split:
# datain_rec0 = del_exth(datain_rec0,534)
# don't remove the EXTH 125 KF8 Count of Resources, seems to be present in mobi6 files as well
# set the EXTH 129 KF8 Masthead / Cover Image string to the null string
datain_rec0 = write_exth(datain_rec0, 129, '')
datain_rec0 = write_exth(datain_rec0, 129, b'')
# don't remove the EXTH 131 KF8 Unidentified Count, seems to be present in mobi6 files as well
# Make sure we have an ASIN & cdeType set...