]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-128982: Substitute regular expression in `http.cookiejar.join_header_words` for...
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Wed, 26 Feb 2025 12:01:32 +0000 (13:01 +0100)
committerGitHub <noreply@github.com>
Wed, 26 Feb 2025 12:01:32 +0000 (13:01 +0100)
The function does not anymore rely on a regular expression
to find alphanumeric characters and underscores.

Lib/http/cookiejar.py
Misc/NEWS.d/next/Library/2025-01-18-11-40-11.gh-issue-128982.557lS5.rst [new file with mode: 0644]

index fb0fd2e97999af1af515a20d8d1f465677fb714e..4ebb1601b4dd82d333db30b16a1a22ddb3d82ff9 100644 (file)
@@ -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)
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 (file)
index 0000000..44b7a7b
--- /dev/null
@@ -0,0 +1,2 @@
+Improve the performance of :func:`!http.cookiejar.join_header_words` by up
+to 35%. Patch by Bénédikt Tran.