1.1 --- a/docs/encodings.html Wed Aug 24 21:58:49 2005 +0000
1.2 +++ b/docs/encodings.html Wed Aug 24 21:59:01 2005 +0000
1.3 @@ -3,7 +3,6 @@
1.4
1.5 <title>Character Encodings</title><meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" />
1.6 <link href="styles.css" rel="stylesheet" type="text/css" /></head>
1.7 -
1.8 <body>
1.9 <h1>Character Encodings</h1>
1.10 <p>When writing applications with WebStack, you should try and use
1.11 @@ -53,7 +52,7 @@
1.12 module contains useful functions to access streams as if Unicode
1.13 objects were being transmitted; for example:</li>
1.14 </ul>
1.15 -<pre>import codecs<br /><br />class MyResource:<br /><br /> encoding = "utf-8"<br /><br /> def respond(self, trans):<br /> stream = trans.get_request_stream() # only reads strings<br /> unicode_stream = codecs.getreader(self.encoding)(stream) # reads Unicode objects<br /><br /> [Some activity...]<br /><br /> out = trans.get_response_stream() # only writes strings<br /> unicode_out = codecs.getwriter(self.encoding)(out) # writes Unicode objects</pre>
1.16 +<pre>import codecs<br /><br />class MyResource:<br /><br /> encoding = "utf-8"<br /><br /> def respond(self, trans):<br /> stream = trans.get_request_stream() # only reads strings<br /> unicode_stream = codecs.getreader(self.encoding)(stream) # reads Unicode objects<br /><br /> [Some activity...]<br /><br /> out = trans.get_response_stream() # writes strings and Unicode objects<br /></pre>
1.17 <h3>Use Strings for Binary Content</h3>
1.18 <p>If you are reading and writing binary content, Unicode objects are
1.19 inappropriate. Make sure to open files in binary mode, where necessary.</p>