#NEWLINE# def sanitize( text , permitted_tags = [ 'a' , 'b' , 'blockquote' , 'br/' , 'i' , 'li' , 'ol' , 'ul' , 'p' , 'cite' , 'code' , 'pre' , 'img/' , 'h1' , 'h2' , 'h3' , 'h4' , 'h5' , 'h6' , 'table' , 'tbody' , 'thead' , 'tfoot' , 'tr' , 'td' , 'div' , 'strong' , 'span' ] , allowed_attributes = { #NEWLINE# #INDENT# 'a' : [ 'href' , 'title' ] , #NEWLINE# 'img' : [ 'src' , 'alt' ] , #NEWLINE# 'blockquote' : [ 'type' ] , #NEWLINE# 'td' : [ 'colspan' ] , #NEWLINE# #UNINDENT# } , escape = True ) : #NEWLINE# #INDENT# if ( not isinstance ( text , basestring ) ) : #NEWLINE# #INDENT# return str ( text ) #NEWLINE# #UNINDENT# return XssCleaner ( permitted_tags = permitted_tags , allowed_attributes = allowed_attributes ) . strip ( text , escape )