Mercurial > genshi > mirror
comparison doc/filters.txt @ 853:f33ecf3c319e trunk
Convert a bunch of print statements to py3k compatible syntax.
author | cmlenz |
---|---|
date | Tue, 10 Nov 2009 21:22:51 +0000 |
parents | 0fcb1c0d7c20 |
children | 84088f426c52 |
comparison
equal
deleted
inserted
replaced
852:07f4339fecb0 | 853:f33ecf3c319e |
---|---|
45 ... <input type="checkbox" name="remember" /> Remember me | 45 ... <input type="checkbox" name="remember" /> Remember me |
46 ... </label> | 46 ... </label> |
47 ... </p> | 47 ... </p> |
48 ... </form>""") | 48 ... </form>""") |
49 >>> filler = HTMLFormFiller(data=dict(username='john', remember=True)) | 49 >>> filler = HTMLFormFiller(data=dict(username='john', remember=True)) |
50 >>> print template.generate() | filler | 50 >>> print(template.generate() | filler) |
51 <form> | 51 <form> |
52 <p> | 52 <p> |
53 <label>User name: | 53 <label>User name: |
54 <input type="text" name="username" value="john"/> | 54 <input type="text" name="username" value="john"/> |
55 </label><br/> | 55 </label><br/> |
102 >>> html = HTML("""<div> | 102 >>> html = HTML("""<div> |
103 ... <p>Innocent looking text.</p> | 103 ... <p>Innocent looking text.</p> |
104 ... <script>alert("Danger: " + document.cookie)</script> | 104 ... <script>alert("Danger: " + document.cookie)</script> |
105 ... </div>""") | 105 ... </div>""") |
106 >>> sanitize = HTMLSanitizer() | 106 >>> sanitize = HTMLSanitizer() |
107 >>> print html | sanitize | 107 >>> print(html | sanitize) |
108 <div> | 108 <div> |
109 <p>Innocent looking text.</p> | 109 <p>Innocent looking text.</p> |
110 </div> | 110 </div> |
111 | 111 |
112 In this example, the ``<script>`` tag was removed from the output. | 112 In this example, the ``<script>`` tag was removed from the output. |
128 | 128 |
129 >>> html = HTML("""<div> | 129 >>> html = HTML("""<div> |
130 ... <br style="background: url(javascript:alert(document.cookie); color: #000" /> | 130 ... <br style="background: url(javascript:alert(document.cookie); color: #000" /> |
131 ... </div>""") | 131 ... </div>""") |
132 >>> sanitize = HTMLSanitizer(safe_attrs=HTMLSanitizer.SAFE_ATTRS | set(['style'])) | 132 >>> sanitize = HTMLSanitizer(safe_attrs=HTMLSanitizer.SAFE_ATTRS | set(['style'])) |
133 >>> print html | sanitize | 133 >>> print(html | sanitize) |
134 <div> | 134 <div> |
135 <br style="color: #000"/> | 135 <br style="color: #000"/> |
136 </div> | 136 </div> |
137 | 137 |
138 .. warning:: You should probably not rely on the ``style`` filtering, as | 138 .. warning:: You should probably not rely on the ``style`` filtering, as |
162 ... <body> | 162 ... <body> |
163 ... Some <em>body</em> text. | 163 ... Some <em>body</em> text. |
164 ... </body> | 164 ... </body> |
165 ... </html>''') | 165 ... </html>''') |
166 | 166 |
167 >>> print html | Transformer('body/em').map(unicode.upper, TEXT) \ | 167 >>> print(html | Transformer('body/em').map(unicode.upper, TEXT) |
168 ... .unwrap().wrap(tag.u).end() \ | 168 ... .unwrap().wrap(tag.u).end() |
169 ... .select('body/u') \ | 169 ... .select('body/u') |
170 ... .prepend('underlined ') | 170 ... .prepend('underlined ')) |
171 <html> | 171 <html> |
172 <head><title>Some Title</title></head> | 172 <head><title>Some Title</title></head> |
173 <body> | 173 <body> |
174 Some <u>underlined BODY</u> text. | 174 Some <u>underlined BODY</u> text. |
175 </body> | 175 </body> |
214 | 214 |
215 .. code-block:: pycon | 215 .. code-block:: pycon |
216 | 216 |
217 >>> xform = Transformer('body//em').map(unicode.upper, TEXT) \ | 217 >>> xform = Transformer('body//em').map(unicode.upper, TEXT) \ |
218 >>> xform = xform.apply(RenameTransformation('u')) | 218 >>> xform = xform.apply(RenameTransformation('u')) |
219 >>> print html | xform | 219 >>> print(html | xform) |
220 <html> | 220 <html> |
221 <head><title>Some Title</title></head> | 221 <head><title>Some Title</title></head> |
222 <body> | 222 <body> |
223 Some <u>BODY</u> text. | 223 Some <u>BODY</u> text. |
224 </body> | 224 </body> |