Skip to content

Commit 56e1900

Browse files
authored
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.
1 parent 64ccbbb commit 56e1900

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

Lib/http/cookiejar.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ def join_header_words(lists):
448448
attr = []
449449
for k, v in pairs:
450450
if v is not None:
451-
if not re.search(r"^\w+$", v):
451+
if not v.isalnum() and '_' not in v:
452452
v = HEADER_JOIN_ESCAPE_RE.sub(r"\\\1", v) # escape " and \
453453
v = '"%s"' % v
454454
k = "%s=%s" % (k, v)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Improve the performance of :func:`!http.cookiejar.join_header_words` by up
2+
to 35%. Patch by Bénédikt Tran.

0 commit comments

Comments
 (0)