[Python-checkins] CVS: python/dist/src/Lib/xml/sax saxutils.py,1.14,1.14.6.1

Tim Peters tim_one@users.sourceforge.net
Fri, 20 Jul 2001 23:07:15 -0700


Update of /cvsroot/python/python/dist/src/Lib/xml/sax
In directory usw-pr-cvs1:/tmp/cvs-serv27169/descr/dist/src/Lib/xml/sax

Modified Files:
      Tag: descr-branch
	saxutils.py 
Log Message:
Merge of trunk delta date2001-07-17b to date2001-07-21.  See PLAN.txt.


Index: saxutils.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/sax/saxutils.py,v
retrieving revision 1.14
retrieving revision 1.14.6.1
diff -C2 -r1.14 -r1.14.6.1
*** saxutils.py	2000/12/16 01:45:11	1.14
--- saxutils.py	2001/07/21 06:07:13	1.14.6.1
***************
*** 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('"', "&quot;")
+         else:
+             data = "'%s'" % data
+     else:
+         data = '"%s"' % data
+     return data
+ 
  
  class XMLGenerator(handler.ContentHandler):