handle all strings as unicode for compatibility with Cheetah 2.2.x (also backward-compatible with 2.0.x)
This commit is contained in:
parent
a66e628f10
commit
7e999d1480
2 changed files with 32 additions and 21 deletions
|
|
@ -1,3 +1,4 @@
|
|||
#encoding utf-8
|
||||
#import koji
|
||||
#import random
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
|
|
@ -5,25 +6,25 @@
|
|||
|
||||
#def greeting()
|
||||
#set $greetings = ('hello', 'hi', 'yo', "what's up", "g'day", 'back to work',
|
||||
'bonjour',
|
||||
'hallo',
|
||||
'ciao',
|
||||
'hola',
|
||||
'olá',
|
||||
'dobrý den',
|
||||
'zdravstvuite',
|
||||
'góðan daginn',
|
||||
'hej',
|
||||
'grüezi',
|
||||
'céad míle fáilte',
|
||||
'hylô',
|
||||
'bună ziua',
|
||||
'jó napot',
|
||||
'dobre dan',
|
||||
'你好',
|
||||
'こんにちは',
|
||||
'नमस्कार',
|
||||
'안녕하세요')
|
||||
'bonjour',
|
||||
'hallo',
|
||||
'ciao',
|
||||
'hola',
|
||||
u'olá',
|
||||
u'dobrý den',
|
||||
u'zdravstvuite',
|
||||
u'góðan daginn',
|
||||
'hej',
|
||||
u'grüezi',
|
||||
u'céad míle fáilte',
|
||||
u'hylô',
|
||||
u'bună ziua',
|
||||
u'jó napot',
|
||||
'dobre dan',
|
||||
u'你好',
|
||||
u'こんにちは',
|
||||
u'नमस्कार',
|
||||
u'안녕하세요')
|
||||
#echo $random.choice($greetings)##slurp
|
||||
#end def
|
||||
|
||||
|
|
|
|||
|
|
@ -31,8 +31,18 @@ def _initValues(req, title='Build System Info', pageID='summary'):
|
|||
|
||||
return values
|
||||
|
||||
class DecodeUTF8(Cheetah.Filters.Filter):
|
||||
def filter(self, *args, **kw):
|
||||
"""Convert all strs to unicode objects"""
|
||||
result = super(DecodeUTF8, self).filter(*args, **kw)
|
||||
if isinstance(result, unicode):
|
||||
pass
|
||||
else:
|
||||
result = result.decode('utf-8', 'replace')
|
||||
return result
|
||||
|
||||
# Escape ampersands so the output can be valid XHTML
|
||||
class XHTMLFilter(Cheetah.Filters.EncodeUnicode):
|
||||
class XHTMLFilter(DecodeUTF8):
|
||||
def filter(self, *args, **kw):
|
||||
result = super(XHTMLFilter, self).filter(*args, **kw)
|
||||
result = result.replace('&', '&')
|
||||
|
|
@ -59,7 +69,7 @@ def _genHTML(req, fileName):
|
|||
tmpl_class = Cheetah.Template.Template.compile(file=fileName)
|
||||
TEMPLATES[fileName] = tmpl_class
|
||||
tmpl_inst = tmpl_class(namespaces=[req._values], filter=XHTMLFilter)
|
||||
return str(tmpl_inst)
|
||||
return tmpl_inst.respond().encode('utf-8', 'replace')
|
||||
|
||||
def _truncTime():
|
||||
now = datetime.datetime.now()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue