This patch allows Webware to output unicode strings. Output is encoded by default in latin-1 but you can change that by calling self.setEncoding("utf-8") or something like that. --md@hudora.de --- WebKit/Page.py.orig Tue Oct 21 11:41:12 2003 +++ WebKit/Page.py Tue Oct 21 12:58:04 2003 @@ -15,6 +15,7 @@ They might also choose to override writeHTML() entirely. In awake(), the page sets self attributes, _transaction, _response and _request which subclasses should use as appropriate. For the purposes of output, the write() and writeln() convenience methods are provided. + Page Defaults to output in Latin-1 encoding, but other encodings can be chooesen by setEncoding() When developing a full-blown website, it's common to create a subclass of Page called SitePage which defines the common look and feel of the website and provides site-specific convenience methods. Then all other page classes inherit from SitePage. """ @@ -25,6 +26,7 @@ self._response = transaction.response() self._request = transaction.request() self._session = None # don't create unless needed + self.setEncoding() assert self._transaction is not None assert self._response is not None assert self._request is not None @@ -99,6 +101,12 @@ self._session = self._transaction.session() return self._session + def setEncoding(self, encoding = "latin-1"): + self._encoding = encoding + contenttype = self._response.header("Content-type", default="text/html") + if contenttype.find("; charset=") > -1: + contenttype = contenttype[:contenttype.find("; charset=")] + self._response.setHeader("Content-type", "%s; charset=%s" % (contenttype, encoding)) ## Generating results ## @@ -236,11 +244,11 @@ def write(self, *args): for arg in args: - self._response.write(str(arg)) + self._response.write(unicode(arg).encode(self._encoding)) def writeln(self, *args): for arg in args: - self._response.write(str(arg)) + self._response.write(unicode(arg).encode(self._encoding)) self._response.write('\n')