[Cheetahtemplate-discuss] Output filters and making data web-safe
Brought to you by:
rtyler,
tavis_rudd
From: <ir...@ms...> - 2001-10-31 19:42:47
|
I'm trying to makde database data web safe. That is, convert < to < > to > & to & I thought output filtering was the most appropriate place for this, so I tried to create a filter in Filters.py: class WebSafe(Filter): """Escape HTML entities in $placeholders. """ def filter(self, val, **kw): # The superclass converts 'val' to string, may do other # stuff. val = Filter.filter(self, val, **kw) val = cgi.escape(val) # Expand with additional transformations here. return val Then in my template: #filter WebSafe But when I run cheetah-compile, I get: eatDirective self.directiveEaters[directiveKey]() File "/local/opt/Python-2.1b1/lib/python2.2/site-packages/Cheetah/Parser.py", line 1496, in eatFilter self._templateObj._currentFilter = \ AttributeError: WebSafe instance has no attribute 'format' 1) What's wrong? 2) Is there a better way to make "lots of data" web safe? I could drill through all the lists and dictionaries and sanitize each value, but #filter seems more appropriate. I have an additional complication in that one field sometimes needs spaces converted to " ", but I'm handling that via: #set $prettyCountry = $country.replace(' ', ' ') -- -Mike (Iron) Orr, ir...@ms... (if mail problems: ms...@ji...) http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol |