[library-web/new-website-style] [mallard] guard against broken xml in pages



commit dfd873fbac837cf5c8d92b8f91ed231c6bc04e4f
Author: Frédéric Péters <fpeters 0d be>
Date:   Sun Mar 27 08:20:04 2011 +0530

    [mallard] guard against broken xml in pages

 src/modtypes/mallard.py |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/src/modtypes/mallard.py b/src/modtypes/mallard.py
index f32c282..f0df1d2 100644
--- a/src/modtypes/mallard.py
+++ b/src/modtypes/mallard.py
@@ -36,6 +36,8 @@ try:
 except ImportError:
     html5lib = None
 
+import xml.parsers.expat
+
 import errors
 from base import DocModule
 
@@ -231,8 +233,15 @@ class MallardModule(DocModule):
                 xml_file = os.path.join(lang_dirname, doc_page)
                 if not os.path.exists(xml_file):
                     doc.languages.remove(lang)
+                    logging.warn('failed to find %s for lang %s, removing lang' % (xml_file, lang))
+                    continue
+                try:
+                    page = mallard_cache.add_page(xml_file)
+                except xml.parsers.expat.ExpatError:
+                    doc.languages.remove(lang)
+                    logging.warn('failed to add %s to mallarc cache file for lang %s, removing lang' % (
+                                            xml_file, lang))
                     continue
-                page = mallard_cache.add_page(xml_file)
                 if doc_page == 'index.page':
                     doc.title[lang] = page.link_title.text
             temporary = tempfile.NamedTemporaryFile()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]