diff -r e392f1b88fff Lib/html/__init__.py --- a/Lib/html/__init__.py Mon May 20 10:28:48 2013 -0700 +++ b/Lib/html/__init__.py Mon May 20 18:55:09 2013 -0400 @@ -2,11 +2,6 @@ General functions for HTML manipulation. """ - -_escape_map = {ord('&'): '&', ord('<'): '<', ord('>'): '>'} -_escape_map_full = {ord('&'): '&', ord('<'): '<', ord('>'): '>', - ord('"'): '"', ord('\''): '''} - # NB: this is a candidate for a bytes/string polymorphic interface def escape(s, quote=True): @@ -16,6 +11,10 @@ characters, both double quote (") and single quote (') characters are also translated. """ + s = s.replace("&", "&") # Must be done first! + s = s.replace("<", "<") + s = s.replace(">", ">") if quote: - return s.translate(_escape_map_full) - return s.translate(_escape_map) + s = s.replace('"', """) + s = s.replace('\'', "'") + return s