Fix unicode handling in old style UserProfiles

This commit is contained in:
Kovid Goyal 2008-05-29 23:25:38 -07:00
parent 80c2a125e7
commit efbc08ddf0

View File

@ -9,7 +9,7 @@ import tempfile, time, calendar, re, operator, atexit, shutil, os
from htmlentitydefs import name2codepoint from htmlentitydefs import name2codepoint
from email.utils import formatdate from email.utils import formatdate
from calibre import __appname__, iswindows, browser from calibre import __appname__, iswindows, browser, strftime
from calibre.ebooks.BeautifulSoup import BeautifulStoneSoup, NavigableString, CData, Tag from calibre.ebooks.BeautifulSoup import BeautifulStoneSoup, NavigableString, CData, Tag
@ -211,6 +211,9 @@ class DefaultProfile(object):
src = build_sub_index(category, articles[category]) src = build_sub_index(category, articles[category])
open(cfile, 'wb').write(src.encode(encoding)) open(cfile, 'wb').write(src.encode(encoding))
title = self.title
if not isinstance(title, unicode):
title = unicode(title, 'utf-8', 'replace')
src = u'''\ src = u'''\
<html> <html>
<body> <body>
@ -221,8 +224,8 @@ class DefaultProfile(object):
</ul> </ul>
</body> </body>
</html> </html>
'''%dict(date=time.strftime('%a, %d %B, %Y', time.localtime()), '''%dict(date=strftime('%a, %d %B, %Y'),
categories=clist, title=self.title) categories=clist, title=title)
index = os.path.join(self.temp_dir, 'index.html') index = os.path.join(self.temp_dir, 'index.html')
open(index, 'wb').write(src.encode(encoding)) open(index, 'wb').write(src.encode(encoding))