def xmlattrstr(attrs):
 from xml.sax.saxutils import quoteattr
 s = ''
 names = attrs.keys()
 names.sort()
 for name in names:
  s += (' %s=%s' % (name, quoteattr(str(attrs[name]))))
 return s

def xmlattrstr ( attrs ) : from xml . sax . saxutils import quoteattr s = '' names = attrs . keys ( ) names . sort ( ) for name in names : s += ( ' %s=%s' % ( name , quoteattr ( str ( attrs [ name ] ) ) ) ) return s
construct an xml-safe attribute string from the given attributes "attrs" is a dictionary of attributes the returned attribute string includes a leading space .