diff options
Diffstat (limited to 'cheetah/Filters.py')
-rw-r--r-- | cheetah/Filters.py | 35 |
1 files changed, 7 insertions, 28 deletions
diff --git a/cheetah/Filters.py b/cheetah/Filters.py index dd65f28..d452439 100644 --- a/cheetah/Filters.py +++ b/cheetah/Filters.py @@ -29,40 +29,19 @@ class Filter(object): if val is None: return u'' if isinstance(val, unicode): - if encoding: - return val.encode(encoding) - else: - return val + # ignore the encoding and return the unicode object + return val else: try: - return str(val) - except UnicodeEncodeError: return unicode(val) - return u'' + except UnicodeDecodeError: + # we could put more fallbacks here, but we'll just pass the str + # on and let DummyTransaction worry about it + return str(val) RawOrEncodedUnicode = Filter -class EncodeUnicode(Filter): - def filter(self, val, - encoding='utf8', - str=str, - **kw): - """Encode Unicode strings, by default in UTF-8. - - >>> import Cheetah.Template - >>> t = Cheetah.Template.Template(''' - ... $myvar - ... ${myvar, encoding='utf16'} - ... ''', searchList=[{'myvar': u'Asni\xe8res'}], - ... filter='EncodeUnicode') - >>> print t - """ - if isinstance(val, unicode): - return val.encode(encoding) - if val is None: - return '' - return str(val) - +EncodeUnicode = Filter class Markdown(EncodeUnicode): ''' |