changeset 5883:cabef5f26ec5

remove 4suite dependency for docbook formatter, use minidom (included in python) TODO: the text_docbook formatter tests are still broken See http://moinmo.in/MoinMoinBugs/OldXMLPathIsMissing for more infos.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 16 Sep 2012 23:26:00 +0200
parents 5955979b0d53
children f6272199669a
files MoinMoin/config/multiconfig.py MoinMoin/formatter/_tests/test_formatter.py MoinMoin/formatter/text_docbook.py
diffstat 3 files changed, 16 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/config/multiconfig.py	Sun Sep 16 21:42:37 2012 +0200
+++ b/MoinMoin/config/multiconfig.py	Sun Sep 16 23:26:00 2012 +0200
@@ -332,14 +332,6 @@
             except ImportError:
                 self.chart_options = None
 
-        # "Render As Docbook" requires python-xml.
-        if 'RenderAsDocbook' not in self.actions_excluded:
-            try:
-                from xml.dom.ext.reader import Sax
-            except ImportError:
-                # this will also remove it from the actions menu:
-                self.actions_excluded.append('RenderAsDocbook')
-
         # 'setuid' special auth method auth method can log out
         self.auth_can_logout = ['setuid']
         self.auth_login_inputs = []
--- a/MoinMoin/formatter/_tests/test_formatter.py	Sun Sep 16 21:42:37 2012 +0200
+++ b/MoinMoin/formatter/_tests/test_formatter.py	Sun Sep 16 23:26:00 2012 +0200
@@ -27,22 +27,15 @@
 
     def testSyntaxReferenceDocBook(self):
         py.test.skip("docbook is broken")
+        f_name = 'text_docbook'
         try:
-            from xml.dom import getDOMImplementation
-            dom = getDOMImplementation("4DOM")
-        except ImportError:
-            # if we don't have 4suite installed, the docbook formatter would just raise an exception
-            py.test.skip("not testing docbook formatter because no 4suite installed")
+            formatter = wikiutil.importPlugin(self.request.cfg, "formatter", f_name, "Formatter")
+        except wikiutil.PluginAttributeError:
+            pass
         else:
-            f_name = 'text_docbook'
-            try:
-                formatter = wikiutil.importPlugin(self.request.cfg, "formatter", f_name, "Formatter")
-            except wikiutil.PluginAttributeError:
-                pass
-            else:
-                print "Formatting using %r" % formatter
-                self.formatPage("HelpOnMoinWikiSyntax", formatter)
-                print "Done."
+            print "Formatting using %r" % formatter
+            self.formatPage("HelpOnMoinWikiSyntax", formatter)
+            print "Done."
 
     def testSyntaxReferenceOthers(self):
         formatters = wikiutil.getPlugins("formatter", self.request.cfg)
@@ -86,12 +79,6 @@
                 assert id == origid
 
         formatters = wikiutil.getPlugins("formatter", self.request.cfg)
-        try:
-            from xml.dom import getDOMImplementation
-            dom = getDOMImplementation("4DOM")
-        except ImportError:
-            # if we don't have 4suite installed, the docbook formatter would just raise an exception
-            formatters.remove('text_docbook')
 
         testids = [
             r"tho/zeequeen&angu\za",
--- a/MoinMoin/formatter/text_docbook.py	Sun Sep 16 21:42:37 2012 +0200
+++ b/MoinMoin/formatter/text_docbook.py	Sun Sep 16 23:26:00 2012 +0200
@@ -5,19 +5,18 @@
     @copyright: 2005,2008 by Mikko Virkkilä <mvirkkil@cc.hut.fi>
     @copyright: 2005 by MoinMoin:AlexanderSchremmer (small modifications)
     @copyright: 2005 by MoinMoin:Petr Pytelka <pyta@lightcomp.com> (small modifications)
+    @copyright: 2009 by MoinMoin:ThomasWaldmann (make it work again, use stdlib xml instead 4suite-xml)
 
     @license: GNU GPL, see COPYING for details.
 """
 
 import os, re
 
-from xml.dom import getDOMImplementation
-from xml.dom.ext.reader import Sax
-from xml.dom.ext import Node
+from xml.dom import minidom, Node, getDOMImplementation
+dom = getDOMImplementation()
 
 from MoinMoin.formatter import FormatterBase
 from MoinMoin import wikiutil
-from MoinMoin.error import CompositeError
 from MoinMoin.action import AttachFile
 
 #For revision history
@@ -25,15 +24,6 @@
 from MoinMoin import user
 
 
-class InternalError(CompositeError):
-    pass
-
-try:
-    dom = getDOMImplementation("4DOM")
-except ImportError:
-    raise InternalError("You need to install 4suite to use the DocBook formatter.")
-
-
 class Formatter(FormatterBase):
     #TODO: How to handle revision history and other meta-info from included files?
     #      The problem is that we don't know what the original page is, since
@@ -101,14 +91,8 @@
         return ""
 
     def endDocument(self):
-        from xml.dom.ext import PrettyPrint, Print
-        import StringIO
-
-        f = StringIO.StringIO()
-        Print(self.doc, f)
-        txt = f.getvalue()
-        f.close()
-
+        toxml = self.doc.toxml  # toprettyxml
+        txt = toxml(encoding='utf-8')
         self.cur = None
         return txt
 
@@ -419,7 +403,7 @@
         fname = wikiutil.taintfilename(filename)
         fpath = AttachFile.getFilename(self.request, pagename, fname)
         if not os.path.exists(fpath):
-            return self.text("[attachment:%s]" % url)
+            return self.text("{{attachment:%s}}" % url)
         else:
             return self.image(
                 src=AttachFile.getAttachUrl(pagename, filename, self.request, addts=1),
@@ -436,7 +420,7 @@
         filename = filename + ".png"
         fpath = AttachFile.getFilename(self.request, pagename, fname)
         if not os.path.exists(fpath):
-            return self.text("[drawing:%s]" % url)
+            return self.text("{{drawing:%s}}" % url)
         else:
             src = AttachFile.getAttachUrl(pagename, filename, self.request, addts=1)
             return self.image(alt=drawing, src=src, html_class="drawing")
@@ -618,7 +602,7 @@
 
             text = FormatterBase.macro(self, macro_obj, name, macro_args)
             if text.strip():
-                self._copyExternalNodes(Sax.FromXml(text).documentElement.childNodes, exclude=excludes)
+                self._copyExternalNodes(minidom.parseString(text).documentElement.childNodes, exclude=excludes)
             if was_in_para:
                 self.paragraph(1)
 
@@ -627,7 +611,7 @@
             if text:
                 from xml.parsers.expat import ExpatError
                 try:
-                    xml_dom = Sax.FromXml(text).documentElement.childNodes
+                    xml_dom = minidom.parseString(text).documentElement.childNodes
                     self._copyExternalNodes(xml_dom, exclude=excludes)
                 except ExpatError:
                     self._emitComment("The macro %s caused an error and should be blacklisted. It returned the data '%s' which caused the docbook-formatter to choke. Please file a bug." % (name, text))