# HG changeset patch # User paulb # Date 1093628259 0 # Node ID fd2546f503ea8a985492292e2ef479460c1d59c7 # Parent b1aa24d4c8cb8c619438daaa9e60cb05afea8d70 [project @ 2004-08-27 17:37:39 by paulb] Fixed usage of the output stream to handle Unicode writing. diff -r b1aa24d4c8cb -r fd2546f503ea WebStack/Zope.py --- a/WebStack/Zope.py Thu Aug 26 23:12:57 2004 +0000 +++ b/WebStack/Zope.py Fri Aug 27 17:37:39 2004 +0000 @@ -9,6 +9,7 @@ import Generic from Helpers import Environment from Helpers.Request import Cookie +from Helpers.Response import ConvertingStream class Transaction(Generic.Transaction): @@ -24,6 +25,10 @@ self.request = request self.response = request.RESPONSE + + # Attributes which may be changed later. + + self.content_type = None self.user = None # Request-related methods. @@ -229,9 +234,13 @@ Returns the response stream for the transaction. """ - # This yields a writable object. + # Unicode can upset this operation. Using either the specified charset, + # the same charset as that used in the request, or a default encoding. - return self.response + encoding = self.get_content_type().charset or "utf-8" + if self.content_type: + encoding = self.content_type.charset or encoding + return ConvertingStream(self.response, encoding) def get_response_code(self): @@ -265,6 +274,7 @@ Sets the 'content_type' for the response. """ + self.content_type = content_type self.response.setHeader("Content-Type", self.format_content_type(content_type)) # Higher level response-related methods.