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

Function parse_http_list

Lib/urllib/request.py:1411–1452  ·  view source on GitHub ↗

Parse lists as described by RFC 2068 Section 2. In particular, parse comma-separated lists where the elements of the list may include quoted-strings. A quoted-string could contain a comma. A non-quoted string could have quotes in the middle. Neither commas nor quotes count if the

(s)

Source from the content-addressed store, hash-verified

1409 return parsed
1410
1411def parse_http_list(s):
1412 """Parse lists as described by RFC 2068 Section 2.
1413
1414 In particular, parse comma-separated lists where the elements of
1415 the list may include quoted-strings. A quoted-string could
1416 contain a comma. A non-quoted string could have quotes in the
1417 middle. Neither commas nor quotes count if they are escaped.
1418 Only double-quotes count, not single-quotes.
1419 """
1420 res = []
1421 part = ''
1422
1423 escape = quote = False
1424 for cur in s:
1425 if escape:
1426 part += cur
1427 escape = False
1428 continue
1429 if quote:
1430 if cur == '\\':
1431 escape = True
1432 continue
1433 elif cur == '"':
1434 quote = False
1435 part += cur
1436 continue
1437
1438 if cur == ',':
1439 res.append(part)
1440 part = ''
1441 continue
1442
1443 if cur == '"':
1444 quote = True
1445
1446 part += cur
1447
1448 # append last part
1449 if part:
1450 res.append(part)
1451
1452 return [part.strip() for part in res]
1453
1454class FileHandler(BaseHandler):
1455 # names for the localhost

Callers 1

Calls 2

appendMethod · 0.45
stripMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…