From 36b52e8b2d40b6a09c08ac7f8695e08266e60219 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 13 Aug 2011 10:58:52 -0600 Subject: [PATCH] Catalog generation: Fix error creating epub/mobi catalogs on non UTF-8 windows systems when the metadata contained non ASCII characters --- src/calibre/library/catalog.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/calibre/library/catalog.py b/src/calibre/library/catalog.py index 3bbbd54926..5ea8b4b49f 100644 --- a/src/calibre/library/catalog.py +++ b/src/calibre/library/catalog.py @@ -10,7 +10,7 @@ from xml.sax.saxutils import escape from lxml import etree from types import StringType, UnicodeType -from calibre import prints, prepare_string_for_xml, strftime +from calibre import (prints, prepare_string_for_xml, strftime, force_unicode) from calibre.constants import preferred_encoding, DEBUG from calibre.customize import CatalogPlugin from calibre.customize.conversion import OptionRecommendation, DummyReporter @@ -1083,15 +1083,11 @@ class EPUB_MOBI(CatalogPlugin): self.__totalSteps += incremental_jobs # Load section list templates - templates = [] - with open(P('catalog/section_list_templates.py'), 'r') as f: - for line in f: - t = re.match("(by_.+_template)",line) - if t: - templates.append(t.group(1)) - execfile(P('catalog/section_list_templates.py'), locals()) - for t in templates: - setattr(self,t,eval(t)) + templates = {} + execfile(P('catalog/section_list_templates.py'), templates) + for name, template in templates.iteritems(): + if name.startswith('by_') and name.endswith('_template'): + setattr(self, name, force_unicode(template, 'utf-8')) # Accessors if True: