Fix template bugs introduced by using + instead of '%s'

This commit is contained in:
Charles Haley 2010-09-22 20:56:08 +01:00
parent bd8a206219
commit f280cc956f
2 changed files with 5 additions and 4 deletions

View File

@ -43,9 +43,9 @@ class SafeFormat(string.Formatter):
ign, v = mi.format_field(key, series_with_index=False)
if v is None:
return ''
if v is '':
if v == '':
return ''
return prefix + v + suffix
return prefix + unicode(v) + suffix
except:
return key

View File

@ -101,7 +101,8 @@ def preprocess_template(template):
template = template.decode(preferred_encoding, 'replace')
return template
template_value_re = re.compile(r'^([^\|]*(?=\|))(?:\|?)([^\|]*)(?:\|?)((?<=\|).*?)$')
template_value_re = re.compile(r'^([^\|]*(?=\|))(?:\|?)([^\|]*)(?:\|?)((?<=\|).*?)$',
flags= re.UNICODE)
def explode_string_template_value(key):
try:
@ -120,7 +121,7 @@ class SafeFormat(string.Formatter):
try:
prefix, key, suffix = explode_string_template_value(key)
if kwargs[key]:
return prefix + kwargs[key] + suffix
return prefix + unicode(kwargs[key]) + suffix
return ''
except:
return ''