Attachment 'no-pythonxml.patch'

Download

   1 # This patch is for MoinMoin 1.9
   2 #   Copyright 2009, Franklin Piat - License GPLv2 or Later
   3 #   Copyright 2009, Stefano Zacchiroli
   4 --- text_docbook.py.orig	2009-10-06 23:10:41.000000000 +0200
   5 +++ text_docbook.py	2009-10-08 23:08:59.000000000 +0200
   6 @@ -12,8 +12,11 @@
   7  import os
   8  
   9  from xml.dom import getDOMImplementation
  10 -from xml.dom.ext.reader import Sax
  11 -from xml.dom.ext import Node
  12 +try:
  13 +    from Ft.Xml.Domlette import NonvalidatingReader as Reader
  14 +except ImportError:
  15 +    raise InternalError("You need to install 4suite to use the DocBook formatter.")
  16 +from xml.dom import Node
  17  
  18  from MoinMoin.formatter import FormatterBase
  19  from MoinMoin import wikiutil
  20 @@ -28,10 +31,7 @@
  21  class InternalError(CompositeError):
  22      pass
  23  
  24 -try:
  25 -    dom = getDOMImplementation("4DOM")
  26 -except ImportError:
  27 -    raise InternalError("You need to install 4suite to use the DocBook formatter.")
  28 +dom = getDOMImplementation()
  29  
  30  
  31  class Formatter(FormatterBase):
  32 @@ -72,15 +72,15 @@
  33          self.cur = None
  34  
  35      def startDocument(self, pagename):
  36 -        self.doc = dom.createDocument(None, self.doctype, dom.createDocumentType(
  37 -            self.doctype, "-//OASIS//DTD DocBook XML V4.4//EN",
  38 -            "http://www.docbook.org/xml/4.4/docbookx.dtd"))
  39 +        self.doc = dom.createDocument(None, unicode(self.doctype), dom.createDocumentType(
  40 +            unicode(self.doctype), u"-//OASIS//DTD DocBook XML V4.4//EN",
  41 +            u"http://www.docbook.org/xml/4.4/docbookx.dtd"))
  42  
  43          self.title = pagename
  44          self.root = self.doc.documentElement
  45  
  46          if not self.include_kludge and self.doctype == "article":
  47 -            info = self.doc.createElement("articleinfo")
  48 +            info = self.doc.createElement(u"articleinfo")
  49              self.root.appendChild(info)
  50              self._addTitleElement(self.title, targetNode=info)
  51              self._addRevisionHistory(targetNode=info)
  52 @@ -101,7 +101,7 @@
  53          return ""
  54  
  55      def endDocument(self):
  56 -        from xml.dom.ext import PrettyPrint, Print
  57 +        from Ft.Xml.Domlette import PrettyPrint, Print
  58          import StringIO
  59  
  60          f = StringIO.StringIO()
  61 @@ -125,7 +125,7 @@
  62                  self.cur.lastChild.nodeValue = self.cur.lastChild.nodeValue + srcText
  63              else:
  64                  # We create a new cdata section
  65 -                self.cur.appendChild(self.doc.createCDATASection(srcText))
  66 +                self.cur.appendChild(self.doc.createCDATASection(unicode(srcText)))
  67  
  68          elif self.cur.nodeName in self.wrap_text_in_para:
  69              """
  70 @@ -133,13 +133,13 @@
  71              and not create a new one. Another question is if we should add a space?
  72              """
  73              if self.cur.lastChild is not None and self.cur.lastChild.nodeName == 'para':
  74 -                self.cur.lastChild.appendChild(self.doc.createTextNode(srcText))
  75 +                self.cur.lastChild.appendChild(self.doc.createTextNode(unicode(srcText)))
  76              else:
  77                  self.paragraph(1)
  78                  self.text(text)
  79                  self.paragraph(0)
  80          else:
  81 -            self.cur.appendChild(self.doc.createTextNode(srcText))
  82 +            self.cur.appendChild(self.doc.createTextNode(unicode(srcText)))
  83          return ""
  84  
  85      def heading(self, on, depth, **kw):
  86 @@ -159,11 +159,11 @@
  87                      if self.cur.nodeName == "section":
  88                          self.cur = self.cur.parentNode
  89  
  90 -            section = self.doc.createElement("section")
  91 +            section = self.doc.createElement(u"section")
  92              self.cur.appendChild(section)
  93              self.cur = section
  94  
  95 -            title = self.doc.createElement("title")
  96 +            title = self.doc.createElement(u"title")
  97              self.cur.appendChild(title)
  98              self.cur = title
  99              self.curdepth = depth
 100 @@ -446,22 +446,22 @@
 101      def image(self, src=None, **kw):
 102          if src:
 103              kw['src'] = src
 104 -        media = self.doc.createElement('inlinemediaobject')
 105 +        media = self.doc.createElement(u"inlinemediaobject")
 106  
 107 -        imagewrap = self.doc.createElement('imageobject')
 108 +        imagewrap = self.doc.createElement(u"imageobject")
 109          media.appendChild(imagewrap)
 110  
 111 -        image = self.doc.createElement('imagedata')
 112 +        image = self.doc.createElement(u"imagedata")
 113          if kw.has_key('src'):
 114              src = kw['src']
 115              if src.startswith("/"):
 116                  # convert to absolute path:
 117                  src = self.request.url_root + src
 118 -            image.setAttribute('fileref', src)
 119 +            image.setAttribute(u"fileref", unicode(src))
 120          if kw.has_key('width'):
 121 -            image.setAttribute('width', str(kw['width']))
 122 +            image.setAttribute(u"width", unicode(kw['width']))
 123          if kw.has_key('height'):
 124 -            image.setAttribute('depth', str(kw['height']))
 125 +            image.setAttribute(u"depth", unicode(kw['height']))
 126          imagewrap.appendChild(image)
 127  
 128          # Look for any suitable title, order is important.
 129 @@ -471,7 +471,7 @@
 130                  title = kw[a]
 131                  break
 132          if title:
 133 -            txtcontainer = self.doc.createElement('textobject')
 134 +            txtcontainer = self.doc.createElement(u"textobject")
 135              self._addTextElem(txtcontainer, "phrase", title)
 136              media.appendChild(txtcontainer)
 137  
 138 @@ -480,7 +480,7 @@
 139  
 140      def transclusion(self, on, **kw):
 141          # TODO, see text_html formatter
 142 -        self._emitComment('transclusion is not implemented in DocBook formatter')
 143 +        self._emitComment(u"transclusion is not implemented in DocBook formatter")
 144          return ""
 145  
 146      def transclusion_param(self, **kw):
 147 @@ -543,7 +543,7 @@
 148  
 149      def code_line(self, on):
 150          if on:
 151 -            self.cur.appendChild(self.doc.createTextNode('\n'))
 152 +            self.cur.appendChild(self.doc.createTextNode(u"\n"))
 153          return ''
 154  
 155      def code_token(self, on, tok_type):
 156 @@ -603,7 +603,7 @@
 157              self._emitComment("The macro %s doesn't work with the DocBook formatter." % name)
 158  
 159          elif name == "FootNote":
 160 -            footnote = self.doc.createElement('footnote')
 161 +            footnote = self.doc.createElement(u"footnote")
 162              self._addTextElem(footnote, "para", str(args))
 163              self.cur.appendChild(footnote)
 164  
 165 @@ -613,7 +613,7 @@
 166                  self.paragraph(0)
 167              text = FormatterBase.macro(self, macro_obj, name, args)
 168              if text.strip():
 169 -                self._copyExternalNodes(Sax.FromXml(text).documentElement.childNodes, exclude=excludes)
 170 +                self._copyExternalNodes(Reader.parseString(text).documentElement.childNodes, exclude=excludes)
 171              if was_in_para:
 172                  self.paragraph(1)
 173  
 174 @@ -622,7 +622,7 @@
 175              if text:
 176                  from xml.parsers.expat import ExpatError
 177                  try:
 178 -                    xml_dom = Sax.FromXml(text).documentElement.childNodes
 179 +                    xml_dom = Reader.parseString(text).documentElement.childNodes
 180                      self._copyExternalNodes(xml_dom, exclude=excludes)
 181                  except ExpatError:
 182                      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))
 183 @@ -646,15 +646,15 @@
 184  
 185      def _emitComment(self, text):
 186          text = text.replace("--", "- -") # There cannot be "--" in XML comment
 187 -        self.cur.appendChild(self.doc.createComment(text))
 188 +        self.cur.appendChild(self.doc.createComment(unicode(text)))
 189  
 190      def _handleNode(self, name, on, attributes=()):
 191          if on:
 192 -            node = self.doc.createElement(name)
 193 +            node = self.doc.createElement(unicode(name))
 194              self.cur.appendChild(node)
 195              if len(attributes) > 0:
 196                  for name, value in attributes:
 197 -                    node.setAttribute(name, value)
 198 +                    node.setAttribute(unicode(name), unicode(value))
 199              self.cur = node
 200          else:
 201              """
 202 @@ -744,8 +744,8 @@
 203          with the nodeValue of text. The new element is then added as a child
 204          to the element target.
 205          """
 206 -        newElement = self.doc.createElement(elemName)
 207 -        newElement.appendChild(self.doc.createTextNode(text))
 208 +        newElement = self.doc.createElement(unicode(elemName))
 209 +        newElement.appendChild(self.doc.createTextNode(unicode(text)))
 210          target.appendChild(newElement)
 211  
 212  
 213 @@ -769,14 +769,14 @@
 214          log = editlog.EditLog(self.request, rootpagename=self.title)
 215          user_cache = {}
 216  
 217 -        history = self.doc.createElement("revhistory")
 218 +        history = self.doc.createElement(u"revhistory")
 219  
 220          # read in the complete log of this page
 221          for line in log.reverse():
 222              if not line.action in ('SAVE', 'SAVENEW', 'SAVE/REVERT', 'SAVE/RENAME', ):
 223                  #Let's ignore adding of attachments
 224                  continue
 225 -            revision = self.doc.createElement("revision")
 226 +            revision = self.doc.createElement(u"revision")
 227  
 228              # Revision number (without preceeding zeros)
 229              self._addTextElem(revision, "revnumber", line.rev.lstrip('0'))
 230 @@ -953,19 +953,19 @@
 231          self.formatter = formatter
 232          self.doc = doc
 233  
 234 -        self.tableNode = self.doc.createElement('informaltable')
 235 +        self.tableNode = self.doc.createElement(u"informaltable")
 236          parent.appendChild(self.tableNode)
 237          self.colWidths = {}
 238 -        self.tgroup = self.doc.createElement('tgroup')
 239 +        self.tgroup = self.doc.createElement(u"tgroup")
 240          # Bug in yelp, the two lines below don't affect rendering
 241 -        #self.tgroup.setAttribute('rowsep', '1')
 242 -        #self.tgroup.setAttribute('colsep', '1')
 243 +        #self.tgroup.setAttribute(u"rowsep", u"1")
 244 +        #self.tgroup.setAttribute(u"colsep", u"1")
 245          self.curColumn = 0
 246          self.maxColumn = 0
 247          self.row = None
 248          self.tableNode.appendChild(self.tgroup)
 249  
 250 -        self.tbody = self.doc.createElement('tbody') # Note: This gets appended in finalizeTable
 251 +        self.tbody = self.doc.createElement(u"tbody") # Note: This gets appended in finalizeTable
 252  
 253      def finalizeTable(self):
 254          """Calculates the final width of the whole table and the width of each
 255 @@ -976,21 +976,21 @@
 256          A lot of the information is gathered from the style attributes passed
 257          to the functions
 258          """
 259 -        self.tgroup.setAttribute('cols', str(self.maxColumn))
 260 +        self.tgroup.setAttribute(u"cols", unicode(self.maxColumn))
 261          for colnr in range(0, self.maxColumn):
 262 -            colspecElem = self.doc.createElement('colspec')
 263 -            colspecElem.setAttribute('colname', 'col_%s' % str(colnr))
 264 +            colspecElem = self.doc.createElement(u"colspec")
 265 +            colspecElem.setAttribute(u"colname", u"col_%s" % unicode(colnr))
 266              if self.colWidths.has_key(str(colnr)) and self.colWidths[str(colnr)] != "1*":
 267 -                colspecElem.setAttribute('colwidth', self.colWidths[str(colnr)])
 268 +                colspecElem.setAttribute(u"colwidth", unicode(self.colWidths[str(colnr)]))
 269              self.tgroup.appendChild(colspecElem)
 270          self.tgroup.appendChild(self.tbody)
 271          return self.tableNode.parentNode
 272  
 273      def addRow(self, argsdict={}):
 274          self.curColumn = 0
 275 -        self.row = self.doc.createElement('row')
 276 +        self.row = self.doc.createElement(u"row")
 277          # Bug in yelp, doesn't affect the outcome.
 278 -        self.row.setAttribute("rowsep", "1") #Rows should have lines between them
 279 +        self.row.setAttribute(u"rowsep", u"1") #Rows should have lines between them
 280          self.tbody.appendChild(self.row)
 281          return self.row
 282  
 283 @@ -998,9 +998,9 @@
 284          if 'style' in argsdict:
 285              argsdict.update(self.formatter._convertStylesToDict(argsdict['style'].strip('"')))
 286  
 287 -        cell = self.doc.createElement('entry')
 288 -        cell.setAttribute('rowsep', '1')
 289 -        cell.setAttribute('colsep', '1')
 290 +        cell = self.doc.createElement(u"entry")
 291 +        cell.setAttribute(u"rowsep", u"1")
 292 +        cell.setAttribute(u"colsep", u"1")
 293  
 294          self.row.appendChild(cell)
 295          self._handleSimpleCellAttributes(cell, argsdict)
 296 @@ -1027,8 +1027,8 @@
 297              return 1
 298          assert(element.nodeName == "entry")
 299          extracols = int(argsdict['colspan'].strip('"')) - 1
 300 -        element.setAttribute('namest', "col_" + str(self.curColumn))
 301 -        element.setAttribute('nameend', "col_" + str(self.curColumn + extracols))
 302 +        element.setAttribute(u"namest", u"col_" + unicode(self.curColumn))
 303 +        element.setAttribute(u"nameend", u"col_" + unicode(self.curColumn + extracols))
 304          return 1 + extracols
 305  
 306      def _handleSimpleCellAttributes(self, element, argsdict={}):
 307 @@ -1042,12 +1042,12 @@
 308  
 309          if argsdict.has_key('rowspan'):
 310              extrarows = int(argsdict['rowspan'].strip('"')) - 1
 311 -            element.setAttribute('morerows', str(extrarows))
 312 +            element.setAttribute(u"morerows", unicode(extrarows))
 313  
 314          if argsdict.has_key('align'):
 315              value = argsdict['align'].strip('"')
 316              if value in safe_values_for['align']:
 317 -                element.setAttribute('align', value)
 318 +                element.setAttribute(u"align", unicode(value))
 319              else:
 320                  self.formatter._emitComment("Alignment %s not supported" % value)
 321                  pass
 322 @@ -1055,7 +1055,7 @@
 323          if argsdict.has_key('valign'):
 324              value = argsdict['valign'].strip('"')
 325              if value in safe_values_for['valign']:
 326 -                element.setAttribute('valign', value)
 327 +                element.setAttribute(u"valign", unicode(value))
 328              else:
 329                  self.formatter._emitComment("Vertical alignment %s not supported" % value)
 330                  pass

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-10-08 21:38:37, 13.7 KB) [[attachment:no-pythonxml.patch]]
  • [get | view] (2009-10-11 15:23:15, 14.2 KB) [[attachment:no-pythonxml_with_4suite_v1.1.patch]]
  • [get | view] (2009-10-11 17:10:41, 14.2 KB) [[attachment:no-pythonxml_with_4suite_v1.1a.patch]]
  • [get | view] (2009-10-10 20:33:56, 14.2 KB) [[attachment:no-pythonxml_with_minidom+BeautifulSoup_v1.patch]]
 All files | Selected Files: delete move to page copy to page

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