Commit e32221ca authored by Fred Drake's avatar Fred Drake

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.
parent 19bdf3a7
...@@ -28,10 +28,11 @@ def escape(data, entities={}): ...@@ -28,10 +28,11 @@ def escape(data, entities={}):
# must do ampersand first # must do ampersand first
data = data.replace("&", "&") data = data.replace("&", "&")
data = __dict_replace(data, {"<" : "&lt;", data = data.replace(">", "&gt;")
">" : "&gt;", data = data.replace("<", "&lt;")
}) if entities:
return __dict_replace(data, entities) data = __dict_replace(data, entities)
return data
def unescape(data, entities={}): def unescape(data, entities={}):
"""Unescape &amp;, &lt;, and &gt; in a string of data. """Unescape &amp;, &lt;, and &gt; in a string of data.
...@@ -40,12 +41,13 @@ def unescape(data, entities={}): ...@@ -40,12 +41,13 @@ def unescape(data, entities={}):
the optional entities parameter. The keys and values must all be the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value. strings; each key will be replaced with its corresponding value.
""" """
data = __dict_replace(data, {"&lt;" : "<", data = data.replace("&lt;", "<")
"&gt;" : ">", data = data.replace("&gt;", ">")
})
# must do ampersand last # must do ampersand last
data = data.replace("&amp;", "&") data = data.replace("&amp;", "&")
return __dict_replace(data, entities) if entities:
data = __dict_replace(data, entities)
return data
def quoteattr(data, entities={}): def quoteattr(data, entities={}):
"""Escape and quote an attribute value. """Escape and quote an attribute value.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment