mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
gh-128982: Revert "#128982: Substitute regular expression in http.cookiejar.join_header_words for an efficient alternative (GH-128983)" and add tests (GH-130584)
* Revert "gh-128982: Substitute regular expression in `http.cookiejar.join_header_words` for an efficient alternative (GH-128983)"
This reverts commit 56e1900681.
* Add tests
This commit is contained in:
parent
56e1900681
commit
9e474a98af
3 changed files with 18 additions and 8 deletions
|
|
@ -448,7 +448,7 @@ def join_header_words(lists):
|
|||
attr = []
|
||||
for k, v in pairs:
|
||||
if v is not None:
|
||||
if not v.isalnum() and '_' not in v:
|
||||
if not re.search(r"^\w+$", v):
|
||||
v = HEADER_JOIN_ESCAPE_RE.sub(r"\\\1", v) # escape " and \
|
||||
v = '"%s"' % v
|
||||
k = "%s=%s" % (k, v)
|
||||
|
|
|
|||
|
|
@ -227,10 +227,19 @@ class HeaderTests(unittest.TestCase):
|
|||
self.assertEqual(parse_ns_headers([hdr]), expected)
|
||||
|
||||
def test_join_header_words(self):
|
||||
joined = join_header_words([[("foo", None), ("bar", "baz")]])
|
||||
self.assertEqual(joined, "foo; bar=baz")
|
||||
|
||||
self.assertEqual(join_header_words([[]]), "")
|
||||
for src, expected in [
|
||||
([[("foo", None), ("bar", "baz")]], "foo; bar=baz"),
|
||||
(([]), ""),
|
||||
(([[]]), ""),
|
||||
(([[("a", "_")]]), "a=_"),
|
||||
(([[("a", ";")]]), 'a=";"'),
|
||||
([[("n", None), ("foo", "foo;_")], [("bar", "foo_bar")]],
|
||||
'n; foo="foo;_", bar=foo_bar'),
|
||||
([[("n", "m"), ("foo", None)], [("bar", "foo_bar")]],
|
||||
'n=m; foo, bar=foo_bar'),
|
||||
]:
|
||||
with self.subTest(src=src):
|
||||
self.assertEqual(join_header_words(src), expected)
|
||||
|
||||
def test_split_header_words(self):
|
||||
tests = [
|
||||
|
|
@ -286,7 +295,10 @@ Got: '%s'
|
|||
'foo=bar; port="80,81"; discard, bar=baz'),
|
||||
|
||||
(r'Basic realm="\"foo\\\\bar\""',
|
||||
r'Basic; realm="\"foo\\\\bar\""')
|
||||
r'Basic; realm="\"foo\\\\bar\""'),
|
||||
|
||||
('n; foo="foo;_", bar=foo!_',
|
||||
'n; foo="foo;_", bar="foo!_"'),
|
||||
]
|
||||
|
||||
for arg, expect in tests:
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
Improve the performance of :func:`!http.cookiejar.join_header_words` by up
|
||||
to 35%. Patch by Bénédikt Tran.
|
||||
Loading…
Add table
Add a link
Reference in a new issue