def getAttrStr(attrs):
 from xml.sax.saxutils import quoteattr
 s = ''
 for (attr, value) in attrs.items():
  if (not isinstance(value, basestring)):
   value = str(value)
  elif isinstance(value, unicode):
   value = value.encode('utf-8')
  s += (' %s=%s' % (attr, quoteattr(value)))
 return s

def getAttrStr ( attrs ) : from xml . sax . saxutils import quoteattr s = '' for ( attr , value ) in attrs . items ( ) : if ( not isinstance ( value , basestring ) ) : value = str ( value ) elif isinstance ( value , unicode ) : value = value . encode ( 'utf-8' ) s += ( ' %s=%s' % ( attr , quoteattr ( value ) ) ) 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 .