Mercurial > genshi > mirror
comparison markup/filters.py @ 113:d10fbba1d5e0 trunk
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
author | cmlenz |
---|---|
date | Mon, 31 Jul 2006 23:00:06 +0000 |
parents | 08d77c7725e2 |
children | 10279d2eeec9 |
comparison
equal
deleted
inserted
replaced
112:5f9af749341c | 113:d10fbba1d5e0 |
---|---|
18 frozenset | 18 frozenset |
19 except NameError: | 19 except NameError: |
20 from sets import ImmutableSet as frozenset | 20 from sets import ImmutableSet as frozenset |
21 import re | 21 import re |
22 | 22 |
23 from markup.core import Attributes, Markup, Namespace, escape | 23 from markup.core import Attributes, Markup, Namespace, escape, stripentities |
24 from markup.core import END, END_NS, START, START_NS, TEXT | 24 from markup.core import END, END_NS, START, START_NS, TEXT |
25 from markup.path import Path | 25 from markup.path import Path |
26 | 26 |
27 __all__ = ['IncludeFilter', 'WhitespaceFilter', 'HTMLSanitizer'] | 27 __all__ = ['IncludeFilter', 'WhitespaceFilter', 'HTMLSanitizer'] |
28 | 28 |
128 trim_trailing_space('', | 128 trim_trailing_space('', |
129 mjoin(textbuf, escape_quotes=False)))) | 129 mjoin(textbuf, escape_quotes=False)))) |
130 del textbuf[:] | 130 del textbuf[:] |
131 yield TEXT, output, pos | 131 yield TEXT, output, pos |
132 else: | 132 else: |
133 output = escape(collapse_lines('\n', | 133 output = Markup(collapse_lines('\n', |
134 trim_trailing_space('', | 134 trim_trailing_space('', |
135 textbuf.pop())), quotes=False) | 135 escape(textbuf.pop(), quotes=False)))) |
136 yield TEXT, output, pos | 136 yield TEXT, output, pos |
137 if kind is not None: | 137 if kind is not None: |
138 yield kind, data, pos | 138 yield kind, data, pos |
139 | 139 |
140 | 140 |
180 waiting_for = tag | 180 waiting_for = tag |
181 continue | 181 continue |
182 | 182 |
183 new_attrib = [] | 183 new_attrib = [] |
184 for attr, value in attrib: | 184 for attr, value in attrib: |
185 value = stripentities(value) | |
185 if attr not in self._SAFE_ATTRS: | 186 if attr not in self._SAFE_ATTRS: |
186 continue | 187 continue |
187 elif attr in self._URI_ATTRS: | 188 elif attr in self._URI_ATTRS: |
188 # Don't allow URI schemes such as "javascript:" | 189 # Don't allow URI schemes such as "javascript:" |
189 if self._get_scheme(value) not in self._SAFE_SCHEMES: | 190 if self._get_scheme(value) not in self._SAFE_SCHEMES: |