@register.filter
def strip_controls(s):
 control_trans = dict(((n, None) for n in xrange(32) if (n not in [10, 13])))
 rv = unicode(s).translate(control_trans)
 return (jinja2.Markup(rv) if isinstance(s, jinja2.Markup) else rv)

@ register . filter def strip_controls ( s ) : control_trans = dict ( ( ( n , None ) for n in xrange ( 32 ) if ( n not in [ 10 , 13 ] ) ) ) rv = unicode ( s ) . translate ( control_trans ) return ( jinja2 . Markup ( rv ) if isinstance ( s , jinja2 . Markup ) else rv )
strips control characters from a string .