def _quoteattr(data, entities={}):
 entities['\n'] = '&#10;'
 entities['\r'] = '&#12;'
 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 [ '\n' ] = '&#10;' entities [ '\r' ] = '&#12;' 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 .