summaryrefslogtreecommitdiffstats
path: root/Lib/xml/sax
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2002-10-28 17:29:01 (GMT)
committerFred Drake <fdrake@acm.org>2002-10-28 17:29:01 (GMT)
commitf55222d98fd08c469a447ee18c2922b763794fa2 (patch)
treeb4554ad0423fd54caf523ba75520d6900e386754 /Lib/xml/sax
parent15941e6a632d0203a7e4dc843f22b994e1f20e68 (diff)
downloadcpython-f55222d98fd08c469a447ee18c2922b763794fa2.zip
cpython-f55222d98fd08c469a447ee18c2922b763794fa2.tar.gz
cpython-f55222d98fd08c469a447ee18c2922b763794fa2.tar.bz2
Avoid calling __dict_replace() if we don't need to -- the call is much
more expensive than just doing to work needed, and these things seem to always turn into a bottleneck eventually.
Diffstat (limited to 'Lib/xml/sax')
-rw-r--r--Lib/xml/sax/saxutils.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/Lib/xml/sax/saxutils.py b/Lib/xml/sax/saxutils.py
index c369f98..049e09c 100644
--- a/Lib/xml/sax/saxutils.py
+++ b/Lib/xml/sax/saxutils.py
@@ -28,10 +28,11 @@ def escape(data, entities={}):
# must do ampersand first
data = data.replace("&", "&amp;")
- data = __dict_replace(data, {"<" : "&lt;",
- ">" : "&gt;",
- })
- return __dict_replace(data, entities)
+ data = data.replace(">", "&gt;")
+ data = data.replace("<", "&lt;")
+ if entities:
+ data = __dict_replace(data, entities)
+ return data
def unescape(data, entities={}):
"""Unescape &amp;, &lt;, and &gt; in a string of data.
@@ -40,12 +41,13 @@ def unescape(data, entities={}):
the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value.
"""
- data = __dict_replace(data, {"&lt;" : "<",
- "&gt;" : ">",
- })
+ data = data.replace("&lt;", "<")
+ data = data.replace("&gt;", ">")
# must do ampersand last
data = data.replace("&amp;", "&")
- return __dict_replace(data, entities)
+ if entities:
+ data = __dict_replace(data, entities)
+ return data
def quoteattr(data, entities={}):
"""Escape and quote an attribute value.