1.1 --- a/docs/encodings.html Wed Aug 24 18:50:32 2005 +0000
1.2 +++ b/docs/encodings.html Wed Aug 24 21:33:04 2005 +0000
1.3 @@ -1,18 +1,16 @@
1.4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1.5 -<html xmlns="http://www.w3.org/1999/xhtml">
1.6 -<head>
1.7 - <title>Character Encodings</title>
1.8 - <meta name="generator"
1.9 - content="amaya 8.1a, see http://www.w3.org/Amaya/" />
1.10 - <link href="styles.css" rel="stylesheet" type="text/css" />
1.11 -</head>
1.12 +<html xmlns="http://www.w3.org/1999/xhtml"><head>
1.13 +
1.14 + <title>Character Encodings</title><meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" />
1.15 + <link href="styles.css" rel="stylesheet" type="text/css" /></head>
1.16 +
1.17 <body>
1.18 <h1>Character Encodings</h1>
1.19 <p>When writing applications with WebStack, you should try and use
1.20 Python's Unicode objects as much as possible. However, there are a
1.21 number of places where plain Python strings can be involved:</p>
1.22 <ul>
1.23 - <li><a href="parameters.html">Inspecting request parameters</a></li>
1.24 + <li><a href="parameters-headers.html">Inspecting query strings</a></li>
1.25 <li><a href="responses.html">Sending output in a response</a></li>
1.26 <li><a href="parameters.html">Receiving uploaded content</a></li>
1.27 <li><a href="state.html">Accessing cookie information</a></li>
1.28 @@ -49,8 +47,7 @@
1.29 <li>Convert textual content to Unicode as soon as possible (see below
1.30 for choosing encodings).</li>
1.31 <li>If you must include hard-coded messages in your application code,
1.32 -make sure to specify the encoding using the <a
1.33 - href="http://www.python.org/peps/pep-0263.html">standard declaration</a>
1.34 +make sure to specify the encoding using the <a href="http://www.python.org/peps/pep-0263.html">standard declaration</a>
1.35 at the top of your source file.</li>
1.36 <li>Remember that the standard library <code>codecs</code>
1.37 module contains useful functions to access streams as if Unicode
1.38 @@ -76,16 +73,13 @@
1.39 Here is an outline of code which does this:</p>
1.40 <pre>from WebStack.Generic import ContentType<br /><br />class MyResource:<br /><br /> encoding = "utf-8" # We decide on "utf-8" as our chosen<br /> # encoding.<br /> def respond(self, trans):<br /> [Do various things.]<br /><br /> fields = trans.get_fields_from_body(encoding=self.encoding) # Explicitly use the encoding.<br /><br /> [Do other things with the Unicode values from the fields.]<br /><br /> trans.set_content_type(ContentType("text/html", self.encoding)) # The output Web page uses the encoding.<br /><br /> [Produce the response, making sure that self.encoding is used to convert Unicode to raw strings.]</pre>
1.41 <h3>Tell Encodings to Other Components</h3>
1.42 -<p>When using other components to generate content (see <a
1.43 - href="integrating.html">"Integrating with Other Systems"</a>), it may
1.44 +<p>When using other components to generate content (see <a href="integrating.html">"Integrating with Other Systems"</a>), it may
1.45 be the case that such components will just write the generated content
1.46 straight to a normal stream (rather than one wrapped by a <code>codecs</code>
1.47 module function). In such cases, it is likely that for textual content
1.48 such as XML or related formats (XHTML, SVG, HTML) you will need to
1.49 instruct the component to use your chosen encoding; for example:</p>
1.50 <pre> # In the respond method, xml_document is an xml.dom.minidom.Document object...<br /> xml_document.toxml(self.encoding)</pre>
1.51 -<p>This will then generate the appropriate characters in the output <span
1.52 - style="font-style: italic;">and</span> specify the correct encoding
1.53 +<p>This will then generate the appropriate characters in the output <span style="font-style: italic;">and</span> specify the correct encoding
1.54 for the XML document.</p>
1.55 -</body>
1.56 -</html>
1.57 +</body></html>
1.58 \ No newline at end of file