~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/dispatch/request.py

  • Committer: mattgiuca
  • Date: 2008-02-03 11:50:53 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:389
dispatch/request.py:
    Previous fix which encoded all strings as UTF-8 broke writing of binary
    strings (would throw an exception for values >127).
    Added a check - only Unicode strings get encoded as UTF-8. Regular strings
    stay clean.

Show diffs side-by-side

added added

removed removed

Lines of Context:
224
224
 
225
225
        if not self.headers_written:
226
226
            self.__writeheaders()
227
 
        self.apache_req.write(string.encode('utf8'), flush)
 
227
        if isinstance(string, unicode):
 
228
            # Encode unicode strings as UTF-8
 
229
            # (Otherwise cannot handle being written to a bytestream)
 
230
            self.apache_req.write(string.encode('utf8'), flush)
 
231
        else:
 
232
            # 8-bit clean strings just get written directly.
 
233
            # This includes binary strings.
 
234
            self.apache_req.write(string, flush)
228
235
 
229
236
    def flush(self):
230
237
        """Flushes the output buffer."""