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

Function get_word

Lib/email/_header_value_parser.py:1409–1441  ·  view source on GitHub ↗

word = atom / quoted-string Either atom or quoted-string may start with CFWS. We have to peel off this CFWS first to determine which type of word to parse. Afterward we splice the leading CFWS, if any, into the parsed sub-token. If neither an atom or a quoted-string is found befo

(value)

Source from the content-addressed store, hash-verified

1407 return dot_atom, value
1408
1409def get_word(value):
1410 """word = atom / quoted-string
1411
1412 Either atom or quoted-string may start with CFWS. We have to peel off this
1413 CFWS first to determine which type of word to parse. Afterward we splice
1414 the leading CFWS, if any, into the parsed sub-token.
1415
1416 If neither an atom or a quoted-string is found before the next special, a
1417 HeaderParseError is raised.
1418
1419 The token returned is either an Atom or a QuotedString, as appropriate.
1420 This means the 'word' level of the formal grammar is not represented in the
1421 parse tree; this is because having that extra layer when manipulating the
1422 parse tree is more confusing than it is helpful.
1423
1424 """
1425 if value[0] in CFWS_LEADER:
1426 leader, value = get_cfws(value)
1427 else:
1428 leader = None
1429 if not value:
1430 raise errors.HeaderParseError(
1431 "Expected 'atom' or 'quoted-string' but found nothing.")
1432 if value[0]=='"':
1433 token, value = get_quoted_string(value)
1434 elif value[0] in SPECIALS:
1435 raise errors.HeaderParseError("Expected 'atom' or 'quoted-string' "
1436 "but found '{}'".format(value))
1437 else:
1438 token, value = get_atom(value)
1439 if leader is not None:
1440 token[:0] = [leader]
1441 return token, value
1442
1443def get_phrase(value):
1444 """ phrase = 1*word / obs-phrase

Callers 3

get_phraseFunction · 0.85
get_local_partFunction · 0.85
get_obs_local_partFunction · 0.85

Calls 4

get_cfwsFunction · 0.85
get_quoted_stringFunction · 0.85
get_atomFunction · 0.85
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…