Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove unnecessary encoding in the default filters, now that everythi…

…ng is a unicode object internally

There is no longer any value in having the filters return encoded str objects,
since they need to be decoded back to unicode before they can be combined with
the rest of the template text (which is managed as a unicode object).  This
patch maintains API compatibility but fundamentally changes the behavior of
some of the filters.  RawOrEncodedUnicode and EncodeUnicode should be
deprecated and removed from the API.

Signed-off-by: R. Tyler Ballance <tyler@monkeypox.org>
  • Loading branch information...
commit 4213bbe9856d9c33a35ed2d7d5dba1ca16472015 1 parent 87cb611
Mike Bonnet authored committed
Showing with 7 additions and 28 deletions.
  1. +7 −28 cheetah/Filters.py
35 cheetah/Filters.py
View
@@ -29,40 +29,19 @@ def filter(self, val, encoding=None, str=str, **kw):
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
- if val is None:
- return ''
- return str(val)
-
+EncodeUnicode = Filter
class Markdown(EncodeUnicode):
'''
Please sign in to comment.
Something went wrong with that request. Please try again.