Attachment 'formatter_text_docbook_minidom.patch'

Download

   1 diff -r e17387246649 MoinMoin/formatter/text_docbook.py
   2 --- a/MoinMoin/formatter/text_docbook.py	Mon Apr 06 12:31:18 2009 +0200
   3 +++ b/MoinMoin/formatter/text_docbook.py	Sun Apr 12 00:08:46 2009 +0200
   4 @@ -5,19 +5,18 @@
   5      @copyright: 2005,2008 by Mikko Virkkilä <mvirkkil@cc.hut.fi>
   6      @copyright: 2005 by MoinMoin:AlexanderSchremmer (small modifications)
   7      @copyright: 2005 by MoinMoin:Petr Pytelka <pyta@lightcomp.com> (small modifications)
   8 +    @copyright: 2009 by MoinMoin:ThomasWaldmann (make it work again, use stdlib xml instead 4suite-xml)
   9  
  10      @license: GNU GPL, see COPYING for details.
  11  """
  12  
  13  import os
  14  
  15 -from xml.dom import getDOMImplementation
  16 -from xml.dom.ext.reader import Sax
  17 -from xml.dom.ext import Node
  18 +from xml.dom import minidom, Node, getDOMImplementation
  19 +dom = getDOMImplementation()
  20  
  21  from MoinMoin.formatter import FormatterBase
  22  from MoinMoin import wikiutil
  23 -from MoinMoin.error import CompositeError
  24  from MoinMoin.action import AttachFile
  25  
  26  #For revision history
  27 @@ -25,15 +24,6 @@
  28  from MoinMoin import user
  29  
  30  
  31 -class InternalError(CompositeError):
  32 -    pass
  33 -
  34 -try:
  35 -    dom = getDOMImplementation("4DOM")
  36 -except ImportError:
  37 -    raise InternalError("You need to install 4suite to use the DocBook formatter.")
  38 -
  39 -
  40  class Formatter(FormatterBase):
  41      #TODO: How to handle revision history and other meta-info from included files?
  42      #      The problem is that we don't know what the original page is, since
  43 @@ -101,14 +91,8 @@
  44          return ""
  45  
  46      def endDocument(self):
  47 -        from xml.dom.ext import PrettyPrint, Print
  48 -        import StringIO
  49 -
  50 -        f = StringIO.StringIO()
  51 -        Print(self.doc, f)
  52 -        txt = f.getvalue()
  53 -        f.close()
  54 -
  55 +        toxml = self.doc.toxml # toprettyxml
  56 +        txt = toxml(encoding='utf-8')
  57          self.cur = None
  58          return txt
  59  
  60 @@ -419,7 +403,7 @@
  61          fname = wikiutil.taintfilename(filename)
  62          fpath = AttachFile.getFilename(self.request, pagename, fname)
  63          if not os.path.exists(fpath):
  64 -            return self.text("[attachment:%s]" % url)
  65 +            return self.text("{{attachment:%s}}" % url)
  66          else:
  67              return self.image(
  68                  src=AttachFile.getAttachUrl(pagename, filename,
  69 @@ -437,7 +421,7 @@
  70          filename = filename + ".png"
  71          fpath = AttachFile.getFilename(self.request, pagename, fname)
  72          if not os.path.exists(fpath):
  73 -            return self.text("[drawing:%s]" % url)
  74 +            return self.text("{{drawing:%s}}" % url)
  75          else:
  76              src = AttachFile.getAttachUrl(pagename, filename, self.request, addts=1)
  77              return self.image(alt=drawing, src=src, html_class="drawing")
  78 @@ -614,7 +598,7 @@
  79                  self.paragraph(0)
  80              text = FormatterBase.macro(self, macro_obj, name, args)
  81              if text.strip():
  82 -                self._copyExternalNodes(Sax.FromXml(text).documentElement.childNodes, exclude=excludes)
  83 +                self._copyExternalNodes(minidom.parseString(text).documentElement.childNodes, exclude=excludes)
  84              if was_in_para:
  85                  self.paragraph(1)
  86  
  87 @@ -623,7 +607,7 @@
  88              if text:
  89                  from xml.parsers.expat import ExpatError
  90                  try:
  91 -                    xml_dom = Sax.FromXml(text).documentElement.childNodes
  92 +                    xml_dom = minidom.parseString(text).documentElement.childNodes
  93                      self._copyExternalNodes(xml_dom, exclude=excludes)
  94                  except ExpatError:
  95                      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))

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-04-11 22:14:46, 3.6 KB) [[attachment:formatter_text_docbook_minidom.patch]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.