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

Class DisplayName

Lib/email/_header_value_parser.py:573–618  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

571
572
573class DisplayName(Phrase):
574
575 token_type = 'display-name'
576 ew_combine_allowed = False
577
578 @property
579 def display_name(self):
580 res = TokenList(self)
581 if len(res) == 0:
582 return res.value
583 if res[0].token_type == 'cfws':
584 res.pop(0)
585 else:
586 if (isinstance(res[0], TokenList) and
587 res[0][0].token_type == 'cfws'):
588 res[0] = TokenList(res[0][1:])
589 if res[-1].token_type == 'cfws':
590 res.pop()
591 else:
592 if (isinstance(res[-1], TokenList) and
593 res[-1][-1].token_type == 'cfws'):
594 res[-1] = TokenList(res[-1][:-1])
595 return res.value
596
597 @property
598 def value(self):
599 quote = False
600 if self.defects:
601 quote = True
602 else:
603 for x in self:
604 if x.token_type == 'quoted-string':
605 quote = True
606 if len(self) != 0 and quote:
607 pre = post = ''
608 if (self[0].token_type == 'cfws' or
609 isinstance(self[0], TokenList) and
610 self[0][0].token_type == 'cfws'):
611 pre = ' '
612 if (self[-1].token_type == 'cfws' or
613 isinstance(self[-1], TokenList) and
614 self[-1][-1].token_type == 'cfws'):
615 post = ' '
616 return pre+quote_string(self.display_name)+post
617 else:
618 return super().value
619
620
621class LocalPart(TokenList):

Callers 1

get_display_nameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…