def _escape(value):
 if isinstance(value, (list, tuple)):
  value = u','.join(value)
 elif isinstance(value, (date, datetime)):
  value = value.isoformat()
 elif isinstance(value, bool):
  value = str(value).lower()
 if isinstance(value, string_types):
  try:
   return value.encode(u'utf-8')
  except UnicodeDecodeError:
   pass
 return str(value)

def _escape ( value ) : if isinstance ( value , ( list , tuple ) ) : value = u',' . join ( value ) elif isinstance ( value , ( date , datetime ) ) : value = value . isoformat ( ) elif isinstance ( value , bool ) : value = str ( value ) . lower ( ) if isinstance ( value , string_types ) : try : return value . encode ( u'utf-8' ) except UnicodeDecodeError : pass return str ( value )
basic html escaping .