diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index d044be24b6..03d45a3dad 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -759,6 +759,15 @@ class Manifest(object): return u'Item(id=%r, href=%r, media_type=%r)' \ % (self.id, self.href, self.media_type) + def _parse_xml(self, data): + try: + return etree.fromstring(data) + except etree.XMLSyntaxError, err: + if getattr(err, 'code', 0) == 26 or str(err).startswith('Entity'): + data = xml_to_unicode(data, strip_encoding_pats=True, + resolve_entities=True)[0] + return etree.fromstring(data) + def _parse_xhtml(self, data): self.oeb.log.debug('Parsing', self.href, '...') # Convert to Unicode and normalize line endings @@ -952,7 +961,7 @@ class Manifest(object): elif self.media_type.lower() in OEB_DOCS: data = self._parse_xhtml(data) elif self.media_type.lower()[-4:] in ('+xml', '/xml'): - data = etree.fromstring(data) + data = self._parse_xml(data) elif self.media_type.lower() in OEB_STYLES: data = self._parse_css(data) elif 'text' in self.media_type.lower(): diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index 15e12d315e..b4b8494c64 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -1873,13 +1873,19 @@ def main(args=sys.argv): return run_gui(opts, args, actions, listener, app) else: return run_gui(opts, args, actions, listener, app) + otherinstance = False try: listener = Listener(address=ADDRESS) - except socket.error: # Good si is correct - communicate(args) + except socket.error: # Good si is correct (on UNIX) + otherinstance = True else: + # On windows only singleinstance can be trusted + otherinstance = True if iswindows else False + if not otherinstance: return run_gui(opts, args, actions, listener, app) + communicate(args) + return 0