Details

Applies to
moin 1.9.1
Purpose

Fix bug with include macro and DocBook Formatter

Description

The patch will make working DocBook Formatter on a page using Include macro.

Author

ValentinJaniaut

Patch

   1 diff -r 784aeb024774 MoinMoin/formatter/text_docbook.py
   2 --- a/MoinMoin/formatter/text_docbook.py	Thu Feb 11 15:01:43 2010 +0100
   3 +++ b/MoinMoin/formatter/text_docbook.py	Wed Feb 17 17:22:55 2010 +0100
   4 @@ -9,7 +9,7 @@
   5      @license: GNU GPL, see COPYING for details.
   6  """
   7  
   8 -import os
   9 +import os, re
  10  
  11  from xml.dom import getDOMImplementation
  12  from xml.dom.ext.reader import Sax
  13 @@ -611,7 +611,13 @@
  14              was_in_para = self.cur.nodeName == "para"
  15              if was_in_para:
  16                  self.paragraph(0)
  17 -            text = FormatterBase.macro(self, macro_obj, name, args)
  18 +
  19 +            #Regular Expression to match editlink arg
  20 +            _arg_editlink = r'(,\s*(?P<editlink>editlink))?'
  21 +            #And remove it
  22 +            macro_args = re.sub(_arg_editlink, '', args)
  23 +
  24 +            text = FormatterBase.macro(self, macro_obj, name, macro_args)
  25              if text.strip():
  26                  self._copyExternalNodes(Sax.FromXml(text).documentElement.childNodes, exclude=excludes)
  27              if was_in_para:
text_docbook.diff

Discussion

With the 1.9.1 version of MoinMoin, I cannot export a page into a DocBook document if there is Include macro on this page. I got the following error when trying to export such of page :

2010-02-12 17:59:15,134 ERROR MoinMoin.macro:132 Macro Include (page: 'LO41/Rapport') raised an exception:
Traceback (most recent call last):
  File "/home/valeuf/dev/DevMoin/MoinMoin/macro/__init__.py", line 122, in execute
    return execute(self, args)
  File "/home/valeuf/dev/DevMoin/MoinMoin/macro/Include.py", line 225, in execute
    inc_page.link_to(request, '[%s]' % (inc_name, ), css_class="include-page-link"),
  File "/home/valeuf/dev/DevMoin/MoinMoin/Page.py", line 806, in link_to
    link = self.link_to_raw(request, text, querystr, anchor, **kw)
  File "/home/valeuf/dev/DevMoin/MoinMoin/Page.py", line 774, in link_to_raw
    formatter=getattr(self, 'formatter', None), **kw)
  File "/home/valeuf/dev/DevMoin/MoinMoin/wikiutil.py", line 2378, in link_tag
    formatter.rawHTML(text) +
  File "/home/valeuf/dev/DevMoin/MoinMoin/formatter/text_docbook.py", line 376, in url
    return self._handleNode("ulink", on, attributes=(('url', url), ))
  File "/home/valeuf/dev/DevMoin/MoinMoin/formatter/text_docbook.py", line 656, in _handleNode
    if len(attributes) > 0:
AttributeError: 'NoneType' object has no attribute 'appendChild'

The problem is coming from the editlink option. So the solution I found is to delete this option when calling the macro execute function from docbook formatter. (Anyway we do not want link to edit page in our DocBook document). This is done by the enclosed patch.

I suspect that this bug also happens in moin 1.8(.7), please check.

I tested today with a fresh clone from moin 1.8.7 repository. With python 2.6 and MoinMoin out of the box, I got :

      /home/valeuf/dev/MoinMoin1.8.7/MoinMoin/formatter/text_docbook.py in _handleNode (self=<MoinMoin.formatter.text_docbook.Formatter instance at 0x90e766c>, name='ulink', on=1, attributes=(('url', 'http://127.0.0.1:8080/LO41/Rapport/Conception'),))
         1. 653 if on:
         2. 654 node = self.doc.createElement(name)
         3. 655 self.cur.appendChild(node)
         4. 656 if len(attributes) > 0:
         5. 657 for name, value in attributes:
          * self = <MoinMoin.formatter.text_docbook.Formatter instance at 0x90e766c>
          * self.cur = None
          * self.cur.appendChild undefined
          * node = <Element Node at 902a76c: Name='ulink' with 0 attributes and 0 children>

AttributeError

'NoneType' object has no attribute 'appendChild'

    * args = ("'NoneType' object has no attribute 'appendChild'",)
    * message = "'NoneType' object has no attribute 'appendChild'"

System Details

    * Date: Fri, 26 Feb 2010 09:52:57 +0000
    * Platform: Linux aristote 2.6.32-ARCH #1 SMP PREEMPT Thu Jan 7 22:19:56 UTC 2010 i686
    * Python: Python 2.6.4 (/usr/bin/python2.6)
    * MoinMoin: Release 1.8.7 (release)

I had a look about this. Actually, for a reason I cannot explain yet, the system try to make a link for the include macro, however self.cur points to None which cause a bug in the _handleNode method. So it seems that it is not safe to use self.cur in _handleMethod.

I thought I will add a condition to avoid to add a link if self.cur points to None. However, I think it is not a good approach and it is better to check why this happen.

By the way, applying the patch for the Include Macro fix the problem. So here is the same patch for 1.8.7 :

   1 diff -r c68058eaa6be MoinMoin/formatter/text_docbook.py
   2 --- a/MoinMoin/formatter/text_docbook.py	Thu Feb 25 16:52:28 2010 +0100
   3 +++ b/MoinMoin/formatter/text_docbook.py	Fri Mar 12 11:17:20 2010 +0100
   4 @@ -9,7 +9,7 @@
   5      @license: GNU GPL, see COPYING for details.
   6  """
   7  
   8 -import os
   9 +import os,re
  10  
  11  from xml.dom import getDOMImplementation
  12  from xml.dom.ext.reader import Sax
  13 @@ -612,7 +612,13 @@
  14              was_in_para = self.cur.nodeName == "para"
  15              if was_in_para:
  16                  self.paragraph(0)
  17 -            text = FormatterBase.macro(self, macro_obj, name, args)
  18 +            
  19 +            #Regular Expression to match editlink arg
  20 +            _arg_editlink = r'(,\s*(?P<editlink>editlink))?'
  21 +            #And remove it
  22 +            macro_args = re.sub(_arg_editlink, '', args)
  23 +        
  24 +            text = FormatterBase.macro(self, macro_obj, name, macro_args)
  25              if text.strip():
  26                  self._copyExternalNodes(Sax.FromXml(text).documentElement.childNodes, exclude=excludes)
  27              if was_in_para:
docbook_patch_1.8.7.diff

Revision History

Feb 17 : Change the function to delete the editlink form the argument. The previous version was not working correctly in different situtation. (Especially with such of situation : "<<(FooBar editlink, ,editlink)>>"

Plan


CategoryMoinMoinPatch CategoryMoinMoinBugFixed

MoinMoin: MoinMoinPatch/IncludeMacroWithDocBookFormatter (last edited 2010-03-13 21:47:09 by ThomasWaldmann)