diff --git a/Lib/xml/sax/saxutils.py b/Lib/xml/sax/saxutils.py index c369f98fcfe..049e09cd35d 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("&", "&") - data = __dict_replace(data, {"<" : "<", - ">" : ">", - }) - return __dict_replace(data, entities) + data = data.replace(">", ">") + data = data.replace("<", "<") + if entities: + data = __dict_replace(data, entities) + return data def unescape(data, entities={}): """Unescape &, <, and > 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, {"<" : "<", - ">" : ">", - }) + data = data.replace("<", "<") + data = data.replace(">", ">") # must do ampersand last data = data.replace("&", "&") - return __dict_replace(data, entities) + if entities: + data = __dict_replace(data, entities) + return data def quoteattr(data, entities={}): """Escape and quote an attribute value.