MCPcopy Index your code
hub / github.com/python/cpython / join_header_words

Function join_header_words

Lib/http/cookiejar.py:435–458  ·  view source on GitHub ↗

Do the inverse (almost) of the conversion done by split_header_words. Takes a list of lists of (key, value) pairs and produces a single header value. Attribute values are quoted if needed. >>> join_header_words([[("text/plain", None), ("charset", "iso-8859/1")]]) 'text/plain; char

(lists)

Source from the content-addressed store, hash-verified

433HEADER_JOIN_TOKEN_RE = re.compile(r"[!#$%&'*+\-.^_`|~0-9A-Za-z]+")
434HEADER_JOIN_ESCAPE_RE = re.compile(r"([\"\\])")
435def join_header_words(lists):
436 """Do the inverse (almost) of the conversion done by split_header_words.
437
438 Takes a list of lists of (key, value) pairs and produces a single header
439 value. Attribute values are quoted if needed.
440
441 >>> join_header_words([[("text/plain", None), ("charset", "iso-8859/1")]])
442 'text/plain; charset="iso-8859/1"'
443 >>> join_header_words([[("text/plain", None)], [("charset", "iso-8859/1")]])
444 'text/plain, charset="iso-8859/1"'
445
446 """
447 headers = []
448 for pairs in lists:
449 attr = []
450 for k, v in pairs:
451 if v is not None:
452 if not HEADER_JOIN_TOKEN_RE.fullmatch(v):
453 v = HEADER_JOIN_ESCAPE_RE.sub(r"\\\1", v) # escape " and \
454 v = '"%s"' % v
455 k = "%s=%s" % (k, v)
456 attr.append(k)
457 if attr: headers.append("; ".join(attr))
458 return ", ".join(headers)
459
460def strip_quotes(text):
461 if text.startswith('"'):

Callers 3

test_roundtripMethod · 0.90
lwp_cookie_strFunction · 0.85

Calls 3

subMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by 2

test_roundtripMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…