MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / join_header_words

Function join_header_words

tools/python-3.11.9-amd64/Lib/http/cookiejar.py:434–457  ·  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

(lists)

Source from the content-addressed store, hash-verified

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

Callers 1

lwp_cookie_strFunction · 0.85

Calls 4

searchMethod · 0.45
subMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected