From ad0dfc68792f61f0ec21b18114c27932872c3d7f Mon Sep 17 00:00:00 2001 From: Frederik Kriewitz Date: Wed, 4 Jun 2014 13:36:13 +0000 Subject: [PATCH 1/3] Fix render() encoding Fixes exceptions like this: ERROR in CGI: Traceback (most recent call last): File "/var/www/html/ulg.py", line 785, in handler.index(**params) File "/var/www/html/ulg.py", line 722, in index print self.renderULGIndex() UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 6254: ordinal not in range(128) --- ulg.py | 10 +++++----- ulgmodel.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ulg.py b/ulg.py index e2c776b..6ea5102 100755 --- a/ulg.py +++ b/ulg.py @@ -546,7 +546,7 @@ class ULGCgi: default_commandid=commandid, default_sessionid=sessionid, getFormURL=self.decorator_helper.getRuncommandURL - ).render('html', doctype='html') + ).render('html', doctype='html', encoding='utf-8') def renderULGAction(self,routerid=0,commandid=0,sessionid=None,**moreparams): @@ -638,7 +638,7 @@ class ULGCgi: getFormURL=self.decorator_helper.getRuncommandURL, resrange=str(session.getRange()), resrangeb=getRangeStepURLs(session,self.decorator_helper), - ).render('html', doctype='html') + ).render('html', doctype='html', encoding='utf-8') def renderULGError(self,sessionid=None,**params): template = self.loader.load(defaults.index_template_file) @@ -658,7 +658,7 @@ class ULGCgi: result=Markup(result_text) if(result_text) else None, refresh=0, getFormURL=self.decorator_helper.getRuncommandURL - ).render('html', doctype='html') + ).render('html', doctype='html', encoding='utf-8') def renderULGDebug(self,**params): template = self.loader.load(defaults.index_template_file) @@ -677,7 +677,7 @@ class ULGCgi: result=Markup(result_text) if(result_text) else None, refresh=0, getFormURL=self.decorator_helper.getRuncommandURL() - ).render('html', doctype='html') + ).render('html', doctype='html', encoding='utf-8') def getULGSpecialContent(self,sessionid,**params): @@ -711,7 +711,7 @@ class ULGCgi: return template.generate(result=Markup(res), url=url, url_caption=urlc, - ).render('html', doctype='html') + ).render('html', doctype='html', encoding='utf-8') def index(self, **params): diff --git a/ulgmodel.py b/ulgmodel.py index 2553fac..d4bd5c9 100644 --- a/ulgmodel.py +++ b/ulgmodel.py @@ -138,7 +138,7 @@ class TableDecorator(object): table_headline=Markup(self.table_headline) if self.table_headline else '', before=Markup(self.before) if self.before else '', after=Markup(self.after) if self.after else '', - ).render('html') + ).render('html', encoding='utf-8') class TextParameter(object): -- 1.9.1