From 21c84615dea4e4b4b44760ff60212f03fcb4c727 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 3 May 2012 17:56:20 +0530 Subject: [PATCH] CHM Input: Handle files with deeply nested markup and non html files listed at the start of the manifest. Fixes #993607 (chm to mobi conversion crashes with "maximum recursion depth exceeded") --- src/calibre/ebooks/chm/reader.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/chm/reader.py b/src/calibre/ebooks/chm/reader.py index fc7d865265..056b180fd3 100644 --- a/src/calibre/ebooks/chm/reader.py +++ b/src/calibre/ebooks/chm/reader.py @@ -155,7 +155,10 @@ class CHMReader(CHMFile): self.hhc_path = f break if self.hhc_path not in files and files: - self.hhc_path = files[0] + for f in files: + if f.partition('.')[-1].lower() in {'html', 'htm'}: + self.hhc_path = f + break if self.hhc_path == '.hhc' and self.hhc_path not in files: from calibre import walk @@ -241,7 +244,10 @@ class CHMReader(CHMFile): except: pass # do not prettify, it would reformat the
 tags!
-        return str(soup)
+        try:
+            return str(soup)
+        except RuntimeError:
+            return data
 
     def Contents(self):
         if self._contents is not None: