Fix #2907 (Calibre throws an error when trying to convert a free ebook that comes with BN eReader.)

This commit is contained in:
Kovid Goyal 2009-07-22 17:30:58 -06:00
parent db747c1a92
commit 04423d46d5
2 changed files with 11 additions and 1 deletions

View File

@ -384,6 +384,15 @@ def entity_to_unicode(match, exceptions=[], encoding='cp1252'):
except KeyError: except KeyError:
return '&'+ent+';' return '&'+ent+';'
_ent_pat = re.compile(r'&(\S+);')
def prepare_string_for_xml(raw, attribute=False):
raw = _ent_pat.sub(entity_to_unicode, raw)
raw = raw.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
if attribute:
raw = raw.replace('"', '&quot;').replace("'", '&apos;')
return raw
if isosx: if isosx:
fdir = os.path.expanduser('~/.fonts') fdir = os.path.expanduser('~/.fonts')
try: try:

View File

@ -12,7 +12,7 @@ from urllib import unquote
from calibre.customize.conversion import OutputFormatPlugin from calibre.customize.conversion import OutputFormatPlugin
from calibre.ptempfile import TemporaryDirectory from calibre.ptempfile import TemporaryDirectory
from calibre.constants import __appname__, __version__ from calibre.constants import __appname__, __version__
from calibre import strftime, guess_type from calibre import strftime, guess_type, prepare_string_for_xml
from calibre.customize.conversion import OptionRecommendation from calibre.customize.conversion import OptionRecommendation
from lxml import etree from lxml import etree
@ -210,6 +210,7 @@ class EPUBOutput(OutputFormatPlugin):
id, href = self.oeb.manifest.generate('calibre-logo', id, href = self.oeb.manifest.generate('calibre-logo',
'calibre-logo.png') 'calibre-logo.png')
self.oeb.manifest.add(id, href, 'image/png', data=img_data) self.oeb.manifest.add(id, href, 'image/png', data=img_data)
title, author = map(prepare_string_for_xml, (title, author))
html = self.TITLEPAGE%dict(title=title, author=author, html = self.TITLEPAGE%dict(title=title, author=author,
date=strftime('%d %b, %Y'), date=strftime('%d %b, %Y'),
app=__appname__ +' '+__version__, app=__appname__ +' '+__version__,