# HG changeset patch # User paulb # Date 1093976913 0 # Node ID 2f2d24738478c6199d76130e1ba20cb3774bf5b9 # Parent dd031a30ecb5ff2bdeaba718d86ae9b7cde2ca9d [project @ 2004-08-31 18:28:33 by paulb] Added an extra path field in the form example to demonstrate character set issues. diff -r dd031a30ecb5 -r 2f2d24738478 examples/Common/Form/__init__.py --- a/examples/Common/Form/__init__.py Tue Aug 31 18:28:09 2004 +0000 +++ b/examples/Common/Form/__init__.py Tue Aug 31 18:28:33 2004 +0000 @@ -21,14 +21,34 @@ content_type = trans.get_content_type() if content_type: content_type_str = content_type.content_type + content_type_charset = content_type.charset else: content_type_str = None + content_type_charset = None - fields = trans.get_fields_from_body() + # Optional encodings can be employed. + + fields_from_path = trans.get_fields_from_path() + + # Send the appropriate kind of response. - # NOTE: Send the appropriate kind of response. + if fields_from_path.has_key("charset"): + charset = fields_from_path["charset"][0] + trans.set_content_type(WebStack.Generic.ContentType("text/html", charset)) + elif content_type_charset: + charset = content_type_charset + trans.set_content_type(WebStack.Generic.ContentType("text/html", charset)) + else: + charset = None + trans.set_content_type(WebStack.Generic.ContentType("text/html")) - trans.set_content_type(WebStack.Generic.ContentType("text/html")) + # Handle charset issues. + + if charset: + fields = trans.get_fields_from_body(charset) + else: + fields = trans.get_fields_from_body() + out = trans.get_response_stream() out.write(""" @@ -55,12 +75,19 @@

Content Type

%s

+

Charset

+

From Content Type

+

%s

+

In Use

+

%s

Fields from Body

""" % ( content_type_str, + content_type_charset, + charset, self._format_fields(fields) ))