Fix for Python 3

This commit is contained in:
Aldo Bleeker 2021-09-12 17:14:51 +02:00
parent 4d8b5cfa33
commit 4bab58e0fa
2 changed files with 16 additions and 4 deletions

View file

@ -473,8 +473,12 @@ class DocParser(object):
if (link > 0): if (link > 0):
linktype = self.link_type[link-1] linktype = self.link_type[link-1]
title = self.link_title[link-1] title = self.link_title[link-1]
if isinstance(title, bytes):
if (title == b"") or (parares.rfind(title.decode('utf-8')) < 0): if (title == b"") or (parares.rfind(title.decode('utf-8')) < 0):
title=parares[lstart:].encode('utf-8') title=parares[lstart:].encode('utf-8')
else:
if (title == "") or (parares.rfind(title) < 0):
title=parares[lstart:]
if linktype == 'external' : if linktype == 'external' :
linkhref = self.link_href[link-1] linkhref = self.link_href[link-1]
linkhtml = '<a href="%s">' % linkhref linkhtml = '<a href="%s">' % linkhref
@ -485,9 +489,15 @@ class DocParser(object):
else : else :
# just link to the current page # just link to the current page
linkhtml = '<a href="#' + self.id + '">' linkhtml = '<a href="#' + self.id + '">'
if isinstance(title, bytes):
linkhtml += title.decode('utf-8') linkhtml += title.decode('utf-8')
else:
linkhtml += title
linkhtml += '</a>' linkhtml += '</a>'
if isinstance(title, bytes):
pos = parares.rfind(title.decode('utf-8')) pos = parares.rfind(title.decode('utf-8'))
else:
pos = parares.rfind(title)
if pos >= 0: if pos >= 0:
parares = parares[0:pos] + linkhtml + parares[pos+len(title):] parares = parares[0:pos] + linkhtml + parares[pos+len(title):]
else : else :

View file

@ -345,6 +345,8 @@ class TopazBook:
for pid in pidlst: for pid in pidlst:
# use 8 digit pids here # use 8 digit pids here
pid = pid[0:8] pid = pid[0:8]
if isinstance(pid, str):
pid = pid.encode('utf-8')
print("Trying: {0}".format(pid)) print("Trying: {0}".format(pid))
bookKeys = [] bookKeys = []
data = keydata data = keydata