#18020: improve html.escape speed by an order of magnitude. Patch by Matt Bryant.
This commit is contained in:
parent
071029fac6
commit
4603487dc9
|
@ -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 @@ def escape(s, quote=True):
|
|||
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
|
||||
|
|
|
@ -172,6 +172,7 @@ Dave Brueck
|
|||
Francisco Martín Brugué
|
||||
Ian Bruntlett
|
||||
Floris Bruynooghe
|
||||
Matt Bryant
|
||||
Stan Bubrouski
|
||||
Erik de Bueger
|
||||
Jan-Hein Bührman
|
||||
|
|
Loading…
Reference in New Issue