def quoteattr(data, entities={}):
 entities = entities.copy()
 entities.update({'\n': '&#10;', '\r': '&#13;', ' DCTB ': '&#9;'})
 data = escape(data, entities)
 if ('"' in data):
  if ("'" in data):
   data = ('"%s"' % data.replace('"', '&quot;'))
  else:
   data = ("'%s'" % data)
 else:
  data = ('"%s"' % data)
 return data

def quoteattr ( data , entities = { } ) : entities = entities . copy ( ) entities . update ( { '\n' : '&#10;' , '\r' : '&#13;' , ' DCTB ' : '&#9;' } ) data = escape ( data , entities ) if ( '"' in data ) : if ( "'" in data ) : data = ( '"%s"' % data . replace ( '"' , '&quot;' ) ) else : data = ( "'%s'" % data ) else : data = ( '"%s"' % data ) return data
escape and quote an attribute value .