From 72b6c363ebf2cc8d49d59a54136d12fa909a8726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 16 Jan 2025 13:31:52 +0100 Subject: [PATCH 1/2] Improve the performance `http.cookiejar.join_header_words`. The function does not anymore rely on a regular expression to find alphanumeric characters and underscores. --- Lib/http/cookiejar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py index fb0fd2e97999af..4ebb1601b4dd82 100644 --- a/Lib/http/cookiejar.py +++ b/Lib/http/cookiejar.py @@ -448,7 +448,7 @@ def join_header_words(lists): attr = [] for k, v in pairs: if v is not None: - if not re.search(r"^\w+$", v): + if not v.isalnum() and '_' not in v: v = HEADER_JOIN_ESCAPE_RE.sub(r"\\\1", v) # escape " and \ v = '"%s"' % v k = "%s=%s" % (k, v) From 0bbced27a9b590e8a59b7a312412fdd637901e5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 18 Jan 2025 11:40:18 +0100 Subject: [PATCH 2/2] blurb --- .../next/Library/2025-01-18-11-40-11.gh-issue-128982.557lS5.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-01-18-11-40-11.gh-issue-128982.557lS5.rst diff --git a/Misc/NEWS.d/next/Library/2025-01-18-11-40-11.gh-issue-128982.557lS5.rst b/Misc/NEWS.d/next/Library/2025-01-18-11-40-11.gh-issue-128982.557lS5.rst new file mode 100644 index 00000000000000..44b7a7b537364c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-01-18-11-40-11.gh-issue-128982.557lS5.rst @@ -0,0 +1,2 @@ +Improve the performance of :func:`!http.cookiejar.join_header_words` by up +to 35%. Patch by Bénédikt Tran.