[Python-checkins] CVS: python/dist/src/Lib/xml/sax saxutils.py,1.14,1.15
Fred L. Drake
fdrake@users.sourceforge.net
Thu, 19 Jul 2001 09:10:17 -0700
Update of /cvsroot/python/python/dist/src/Lib/xml/sax
In directory usw-pr-cvs1:/tmp/cvs-serv3604/Lib/xml/sax
Modified Files:
saxutils.py
Log Message:
Added function xml.sax.saxutils.quoteattr().
This closes SF bug #440351. It should not be moved to Python 2.1.1.
Index: saxutils.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/sax/saxutils.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** saxutils.py 2000/12/16 01:45:11 1.14
--- saxutils.py 2001/07/19 16:10:15 1.15
***************
*** 28,31 ****
--- 28,52 ----
return data
+ def quoteattr(data, entities={}):
+ """Escape and quote an attribute value.
+
+ Escape &, <, and > in a string of data, then quote it for use as
+ an attribute value. The \" character will be escaped as well, if
+ necessary.
+
+ You can escape other strings of data by passing a dictionary as
+ the optional entities parameter. The keys and values must all be
+ strings; each key will be replaced with its corresponding value.
+ """
+ data = escape(data, entities)
+ if '"' in data:
+ if "'" in data:
+ data = '"%s"' % data.replace('"', """)
+ else:
+ data = "'%s'" % data
+ else:
+ data = '"%s"' % data
+ return data
+
class XMLGenerator(handler.ContentHandler):