1.1 --- a/examples/Common/Form/__init__.py Tue Aug 31 18:28:09 2004 +0000
1.2 +++ b/examples/Common/Form/__init__.py Tue Aug 31 18:28:33 2004 +0000
1.3 @@ -21,14 +21,34 @@
1.4 content_type = trans.get_content_type()
1.5 if content_type:
1.6 content_type_str = content_type.content_type
1.7 + content_type_charset = content_type.charset
1.8 else:
1.9 content_type_str = None
1.10 + content_type_charset = None
1.11
1.12 - fields = trans.get_fields_from_body()
1.13 + # Optional encodings can be employed.
1.14 +
1.15 + fields_from_path = trans.get_fields_from_path()
1.16 +
1.17 + # Send the appropriate kind of response.
1.18
1.19 - # NOTE: Send the appropriate kind of response.
1.20 + if fields_from_path.has_key("charset"):
1.21 + charset = fields_from_path["charset"][0]
1.22 + trans.set_content_type(WebStack.Generic.ContentType("text/html", charset))
1.23 + elif content_type_charset:
1.24 + charset = content_type_charset
1.25 + trans.set_content_type(WebStack.Generic.ContentType("text/html", charset))
1.26 + else:
1.27 + charset = None
1.28 + trans.set_content_type(WebStack.Generic.ContentType("text/html"))
1.29
1.30 - trans.set_content_type(WebStack.Generic.ContentType("text/html"))
1.31 + # Handle charset issues.
1.32 +
1.33 + if charset:
1.34 + fields = trans.get_fields_from_body(charset)
1.35 + else:
1.36 + fields = trans.get_fields_from_body()
1.37 +
1.38 out = trans.get_response_stream()
1.39 out.write("""
1.40 <html>
1.41 @@ -55,12 +75,19 @@
1.42 </form>
1.43 <h2>Content Type</h2>
1.44 <p>%s</p>
1.45 + <h2>Charset</h2>
1.46 + <h3>From Content Type</h3>
1.47 + <p>%s</p>
1.48 + <h3>In Use</h3>
1.49 + <p>%s</p>
1.50 <h2>Fields from Body</h2>
1.51 <ul>%s</ul>
1.52 </body>
1.53 </html>
1.54 """ % (
1.55 content_type_str,
1.56 + content_type_charset,
1.57 + charset,
1.58 self._format_fields(fields)
1.59 ))
1.60