Fix a regression that broke downloading certain periodicals for the Kindle. Fixes #875595 (Calibre- Unable to download news - UnicodeEncodeError)

This commit is contained in:
Kovid Goyal 2011-10-16 17:20:04 +05:30
parent 12fffc051e
commit 557f46fd47

View File

@ -212,7 +212,11 @@ class Serializer(object):
if tocref.klass == "periodical": if tocref.klass == "periodical":
buf.write('<div> <div height="1em"></div>') buf.write('<div> <div height="1em"></div>')
else: else:
buf.write('<div></div> <div> <h2 height="1em"><font size="+2"><b>'+tocref.title+'</b></font></h2> <div height="1em"></div>') t = tocref.title
if isinstance(t, unicode):
t = t.encode('utf-8')
buf.write('<div></div> <div> <h2 height="1em"><font size="+2"><b>'
+t+'</b></font></h2> <div height="1em"></div>')
buf.write('<ul>') buf.write('<ul>')
@ -221,14 +225,17 @@ class Serializer(object):
itemhref = tocitem.href itemhref = tocitem.href
if tocref.klass == 'periodical': if tocref.klass == 'periodical':
# This is a section node. # This is a section node.
# For periodical toca, the section urls are like r'feed_\d+/index.html' # For periodical tocs, the section urls are like r'feed_\d+/index.html'
# We dont want to point to the start of the first article # We dont want to point to the start of the first article
# so we change the href. # so we change the href.
itemhref = re.sub(r'article_\d+/', '', itemhref) itemhref = re.sub(r'article_\d+/', '', itemhref)
self.href_offsets[itemhref].append(buf.tell()) self.href_offsets[itemhref].append(buf.tell())
buf.write('0000000000') buf.write('0000000000')
buf.write(' ><font size="+1" color="blue"><b><u>') buf.write(' ><font size="+1" color="blue"><b><u>')
buf.write(tocitem.title) t = tocitem.title
if isinstance(t, unicode):
t = t.encode('utf-8')
buf.write(t)
buf.write('</u></b></font></a></li>') buf.write('</u></b></font></a></li>')
buf.write('</ul><div height="1em"></div></div><mbp:pagebreak />') buf.write('</ul><div height="1em"></div></div><mbp:pagebreak />')