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)
| 1407 | return dot_atom, value |
| 1408 | |
| 1409 | def 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 | |
| 1443 | def get_phrase(value): |
| 1444 | """ phrase = 1*word / obs-phrase |
no test coverage detected
searching dependent graphs…