annotate MoinMoin/parser/text_html.py @ 2286:01f05e74aa9c

Big PEP8 and whitespace cleanup
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 02 Jul 2007 23:33:20 +0200
parents bb2e053067fb
children ff39884957af
rev   line source
650
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
2 """
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
3 MoinMoin - HTML Parser
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
4
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 657
diff changeset
5 @copyright: 2006 MoinMoin:AlexanderSchremmer
650
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
6 @license: GNU GPL, see COPYING for details.
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
7 """
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
8
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
9 from MoinMoin.support.htmlmarkup import Markup
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
10 from HTMLParser import HTMLParseError
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
11
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
12 Dependencies = []
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
13
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
14 class Parser:
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
15 """
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
16 Sends HTML code after filtering it.
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
17 """
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
18
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
19 extensions = ['.htm', '.html']
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
20 Dependencies = Dependencies
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
21
650
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
22 def __init__(self, raw, request, **kw):
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
23 self.raw = raw
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
24 self.request = request
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
25
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
26 def format(self, formatter):
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
27 """ Send the text. """
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
28 try:
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
29 self.request.write(formatter.rawHTML(Markup(self.raw).sanitize()))
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
30 except HTMLParseError, e:
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
31 self.request.write(formatter.sysmsg(1) +
651
7f11b74d0506 Fixed string quoting in html parser, added CHANGES entry.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 650
diff changeset
32 formatter.text(u'HTML parsing error: %s in "%s"' % (e.msg,
650
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
33 self.raw.splitlines()[e.lineno - 1].strip())) +
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
34 formatter.sysmsg(0))