From 0245678092d92afc4f3bbd7427c83b782bce03cf Mon Sep 17 00:00:00 2001 From: Keith Philpott Date: Fri, 10 Oct 2025 23:02:44 -0700 Subject: [PATCH] faster html.escape --- Lib/html/__init__.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Lib/html/__init__.py b/Lib/html/__init__.py index 1543460ca33b0a..51fdc1d9a840a4 100644 --- a/Lib/html/__init__.py +++ b/Lib/html/__init__.py @@ -16,12 +16,13 @@ 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(">", ">") + s = ( + s.replace("&", "&") # Must be done first! + .replace("<", "<") + .replace(">", ">") + ) if quote: - s = s.replace('"', """) - s = s.replace('\'', "'") + return s.replace('"', """).replace('\'', "'") return s