WebStack

Annotated examples/Common/Unicode/__init__.py

407:3d0fda3123e2
2005-07-18 paulb [project @ 2005-07-18 21:11:51 by paulb] Added additional documentation to make configuration of the login redirect resource more obvious.
paulb@220 1
#!/usr/bin/env python
paulb@220 2
paulb@220 3
"A test of Unicode writing."
paulb@220 4
paulb@220 5
import WebStack.Generic
paulb@220 6
paulb@220 7
class UnicodeResource:
paulb@220 8
paulb@220 9
    "A Unicode test resource."
paulb@220 10
paulb@220 11
    def respond(self, trans):
paulb@223 12
        trans.set_content_type(WebStack.Generic.ContentType("text/html", "utf-8"))
paulb@220 13
paulb@220 14
        # Define a Unicode sequence.
paulb@220 15
paulb@220 16
        l = []
paulb@220 17
        for i in range(0, 4096, 64):
paulb@220 18
            l.append("<tr>")
paulb@220 19
            l.append("<th>%s</th>" % i)
paulb@220 20
            for j in range(i, i+64):
paulb@220 21
                l.append("<td>%s</td>" % unichr(j))
paulb@220 22
            l.append("<tr>\n")
paulb@220 23
        s = "".join(l)
paulb@220 24
paulb@220 25
        # Write the Unicode to the response.
paulb@220 26
paulb@220 27
        out = trans.get_response_stream()
paulb@220 28
        out.write("""
paulb@220 29
<html>
paulb@220 30
  <head>
paulb@220 31
    <title>Unicode Example</title>
paulb@220 32
  </head>
paulb@220 33
  <body>
paulb@220 34
    <table>
paulb@220 35
      %s
paulb@220 36
    </table>
paulb@220 37
  </body>
paulb@220 38
</html>
paulb@220 39
""" % s)
paulb@220 40
paulb@220 41
# vim: tabstop=4 expandtab shiftwidth=4