gh-128982: Substitute regular expression in http.cookiejar.join_header_words for an efficient alternative (GH-128983)

The function does not anymore rely on a regular expression
to find alphanumeric characters and underscores.
This commit is contained in:
Bénédikt Tran 2025-02-26 13:01:32 +01:00 committed by GitHub
parent 64ccbbbf36
commit 56e1900681
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 1 deletions

View 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)

View file

@ -0,0 +1,2 @@
Improve the performance of :func:`!http.cookiejar.join_header_words` by up
to 35%. Patch by Bénédikt Tran.