~ubuntu-branches/ubuntu/hardy/moin/hardy-security

« back to all changes in this revision

Viewing changes to MoinMoin/formatter/dom_xml.py

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-05-14 15:55:15 UTC
  • mfrom: (0.4.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070514155515-apl4srcch40h9fcx
Tags: 1.5.7-3ubuntu1
* Merge from debian unstable, remaining changes:
  - 11000_show_traceback_toggle.patch: allow for 'show_traceback=0' in
    Moin configurations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
    @license: GNU GPL, see COPYING for details.
7
7
"""
8
8
 
 
9
line_anchors = True
 
10
 
9
11
from xml.dom import minidom
10
12
from MoinMoin.formatter.base import FormatterBase
11
13
 
20
22
        while navigational elements (HTML page header/footer) and the like
21
23
        can be printed directly without violating output abstraction.
22
24
    """
23
 
 
24
25
    hardspace = ' '
25
26
 
 
27
    # those tags will be automatically reopened if they were auto-closed due to
 
28
    # an enclosing tag being closed:
26
29
    format_tags = ['b', 'em', 'highlight', 'sup', 'sub', 'strike', 'code', 'u']
27
30
 
28
 
    unbreakables = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6',
29
 
                    'p', 'ol', 'ul', 'li', 'pre', 'a',
30
 
                    'table', 'td', 'tr']
31
 
 
 
31
    # those tags want a <p> around them:
32
32
    need_p = [] # format_tags[:]
33
33
    need_p.extend(['ol', 'a', 'pagelink', 'interwiki', 'macro']) # XXX add more
34
34
 
 
35
    # those tags inhibit auto-generation of a <p> after them:
35
36
    no_p_after = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'ol', 'ul', 'pre',
36
37
                  'small', 'big', 'table', 'td', 'tr', 'dt',
37
38
                  'codearea', 'codeline', 'codetoken',
38
39
                  'sysmesg']
39
40
 
 
41
    # if key tag is opened, auto-close all tags in value list if they are open
40
42
    close_on_open = {
41
43
        'h1': ['p'],
42
44
        'li': ['li'],
47
49
    for i in xrange(2, 7):
48
50
        close_on_open['h%i' % i] = close_on_open['h1']
49
51
 
50
 
    close_on_open = {} # XXX
51
 
 
 
52
    # if key tag is closed, auto-close all tags in value list if they are open
52
53
    close_on_close = {
53
54
        'table': ['td', 'tr'],
54
 
        'td': ['tr'],
 
55
        'td': ['tr'], # XXX WTF?
55
56
        'tr': ['td'],
56
57
        'ol': ['li'],
57
58
        'ul': ['li'],
58
59
        }
59
 
    close_on_close = {} # XXX
 
60
    
 
61
    # FIXME - this overrides the values defined above - FIXME XXX
 
62
    close_on_open = {}
 
63
    close_on_close = {}
60
64
 
61
65
    def __init__(self, request, **kw):
62
 
        self.request = request
63
 
        self._ = request.getText
 
66
        FormatterBase.__init__(self, request, **kw)
64
67
 
65
 
        self._store_pagelinks = kw.get('store_pagelinks', 0)
66
 
        self._highlight_re = None
67
 
        self.pagelinks = []
68
 
        self.in_p = 0
69
 
        self.in_pre = 0
70
68
        self.document = minidom.Document()
71
69
        self.document.documentElement = self.document.createElement('xml')
72
70
        self.position = self.document.documentElement
81
79
        @param tag: tag name, string
82
80
        @param attrs: attributes keywords, ascii or unicode
83
81
        """
 
82
        if tag == 'p':
 
83
            FormatterBase.paragraph(self, 1)
84
84
        self.tag_stack.append((tag, attrs))
85
85
        node = self.document.createElement(tag)
86
86
        for name, value in attrs.items():
95
95
            must be the last opened tag!!!
96
96
        """
97
97
        if tag == 'p':
98
 
            self.in_p = 0 # XXX
 
98
            FormatterBase.paragraph(self, 0)
99
99
        if self.tag_stack[-1][0] != tag:
100
 
            raise ValueError, "<%s> expected <%s> given" % (self.tag_stack[-1][0], tag)
 
100
            raise ValueError, "closing of <%s> expected, but <%s> closed" % (self.tag_stack[-1][0], tag)
101
101
        self.position = self.position.parentNode
102
102
        return self.tag_stack.pop()
103
103
 
123
123
        if on:
124
124
            close_on_open = self.close_on_open.get(tag, [])
125
125
            tags_to_reopen = []
126
 
            while 1:
 
126
            while True:
127
127
                last_tag = self.tag_stack[-1][0]
128
128
                if last_tag in close_on_open:
129
129
                    self._close_tag(last_tag)
154
154
                elif last_tag in self.format_tags:
155
155
                    tags_to_reopen.append(self._close_tag(last_tag))
156
156
                else:
157
 
                    print self.tag_stack
 
157
                    self.request.write("tag_stack: %r\n" % self.tag_stack)
158
158
                    self.request.write(self.document.documentElement.toprettyxml(" "))
159
 
                    raise ValueError, "<%s> expected <%s> given" % (last_tag, tag)
 
159
                    raise ValueError, "closing of <%s> expected, but <%s> closed" % (last_tag, tag)
160
160
            self._close_tag(tag)
161
161
            tags_to_reopen.reverse()
162
162
            for tag_name, args in tags_to_reopen:
171
171
                return
172
172
        if self.in_p:
173
173
            return
174
 
        self.in_p = 1
175
174
        self._open_tag('p', type=str(opening_tag))
176
175
 
177
176
    def sysmsg(self, on, **kw):
178
177
        """ Emit a system message (embed it into the page).
179
178
 
180
 
            Normally used to indicate disabled options, or invalid
181
 
            markup.
 
179
            Normally used to indicate disabled options, or invalid markup.
182
180
        """
183
181
        return self._set_tag('sysmesg', on, **kw)
184
182
 
220
218
                self.text('\n'.join(lines)) +
221
219
                self._set_tag('processor', False))
222
220
 
223
 
    def dynamic_content(self, parser, callback, arg_list=[], arg_dict={},
224
 
                        returns_content=1):
 
221
    def dynamic_content(self, parser, callback, arg_list=[], arg_dict={}, returns_content=1):
225
222
        content = parser[callback](*arg_list, **arg_dict)
226
223
        if returns_content:
227
224
            return content
234
231
            kw['class'] = str(css)
235
232
        return self._set_tag('a', on, **kw)
236
233
 
237
 
    def attachment_link(self, on, url='', **kw):
 
234
    def attachment_link(self, url, text, **kw):
238
235
        kw['href'] = url
239
 
        return self._set_tag('attachment', on, **kw)
 
236
        kw['type'] = 'link'
 
237
        return self._set_tag('attachment', 1, **kw) + self.text(text) + self._set_tag('attachment', 0, **kw)
240
238
    
241
239
    def attachment_image(self, url, **kw):
242
240
        kw['href'] = url
330
328
    def anchorlink(self, on, name, **kw):
331
329
        return self.url(on, "#" + name, **kw)
332
330
 
 
331
    def line_anchordef(self, lineno):
 
332
        if line_anchors:
 
333
            return self.anchordef("line-%d" % lineno)
 
334
        else:
 
335
            return ''
 
336
 
333
337
    def underline(self, on, **kw):
334
338
        return self._set_tag('u', on)
335
339