From 557f46fd47136946a375d0570d803c67e6fe8273 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 16 Oct 2011 17:20:04 +0530 Subject: [PATCH] Fix a regression that broke downloading certain periodicals for the Kindle. Fixes #875595 (Calibre- Unable to download news - UnicodeEncodeError) --- src/calibre/ebooks/mobi/writer2/serializer.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/mobi/writer2/serializer.py b/src/calibre/ebooks/mobi/writer2/serializer.py index eeef720144..041a9922cb 100644 --- a/src/calibre/ebooks/mobi/writer2/serializer.py +++ b/src/calibre/ebooks/mobi/writer2/serializer.py @@ -212,7 +212,11 @@ class Serializer(object): if tocref.klass == "periodical": buf.write('
') else: - buf.write('

'+tocref.title+'

') + t = tocref.title + if isinstance(t, unicode): + t = t.encode('utf-8') + buf.write('

' + +t+'

') buf.write('
    ') @@ -221,14 +225,17 @@ class Serializer(object): itemhref = tocitem.href if tocref.klass == 'periodical': # 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 # so we change the href. itemhref = re.sub(r'article_\d+/', '', itemhref) self.href_offsets[itemhref].append(buf.tell()) buf.write('0000000000') buf.write(' >') - buf.write(tocitem.title) + t = tocitem.title + if isinstance(t, unicode): + t = t.encode('utf-8') + buf.write(t) buf.write('') buf.write('
')