| 612 | |
| 613 | |
| 614 | class LocalPart(TokenList): |
| 615 | |
| 616 | token_type = 'local-part' |
| 617 | as_ew_allowed = False |
| 618 | |
| 619 | @property |
| 620 | def value(self): |
| 621 | if self[0].token_type == "quoted-string": |
| 622 | return self[0].quoted_value |
| 623 | else: |
| 624 | return self[0].value |
| 625 | |
| 626 | @property |
| 627 | def local_part(self): |
| 628 | # Strip whitespace from front, back, and around dots. |
| 629 | res = [DOT] |
| 630 | last = DOT |
| 631 | last_is_tl = False |
| 632 | for tok in self[0] + [DOT]: |
| 633 | if tok.token_type == 'cfws': |
| 634 | continue |
| 635 | if (last_is_tl and tok.token_type == 'dot' and |
| 636 | last[-1].token_type == 'cfws'): |
| 637 | res[-1] = TokenList(last[:-1]) |
| 638 | is_tl = isinstance(tok, TokenList) |
| 639 | if (is_tl and last.token_type == 'dot' and |
| 640 | tok[0].token_type == 'cfws'): |
| 641 | res.append(TokenList(tok[1:])) |
| 642 | else: |
| 643 | res.append(tok) |
| 644 | last = res[-1] |
| 645 | last_is_tl = is_tl |
| 646 | res = TokenList(res[1:-1]) |
| 647 | return res.value |
| 648 | |
| 649 | |
| 650 | class DomainLiteral(TokenList): |