From: <mdo...@us...> - 2003-10-26 09:05:55
|
Update of /cvsroot/webware-sandbox/Sandbox/mdornseif In directory sc8-pr-cvs1:/tmp/cvs-serv12343 Added Files: UnicodePage.py __init__.py index.txt Log Message: initial import --- NEW FILE: UnicodePage.py --- """UnicodePage tries to be compatible with WebKit's Page in all aspects but adds support for sending non-ASCII output to the client. Internally all data is represented as Python Unicode Strings. When send to the client headers are set apropriately and data is send withe charset utf-8 by default. You also could change the charset used by caling self.setEncoding(encoding). When changing the content-type be careful to keep the charset. --...@hu... """ from Page import Page class UnicodePage(Page): """ An implementation of Page supporting Unicode/utf-8 output. """ ## Transactions ## def awake(self, transaction): Page.awake(self, transaction) self.setEncoding("utf-8") def setEncoding(self, encoding = "latin-1"): """Set the encoding used when sending the Page to the client.""" 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)) ## Writing ## def write(self, *args): for arg in args: self._response.write(unicode(arg).encode(self._encoding)) def writeln(self, *args): for arg in args: self._response.write(unicode(arg).encode(self._encoding)) self._response.write('\n') --- NEW FILE: __init__.py --- # --- NEW FILE: index.txt --- UnicodePage - Using Unicode for outputting |