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

Function get_address

Lib/email/_header_value_parser.py:1996–2023  ·  view source on GitHub ↗

address = mailbox / group Note that counter-intuitively, an address can be either a single address or a list of addresses (a group). This is why the returned Address object has a 'mailboxes' attribute which treats a single address as a list of length one. When you need to differe

(value)

Source from the content-addressed store, hash-verified

1994 return group, value
1995
1996def get_address(value):
1997 """ address = mailbox / group
1998
1999 Note that counter-intuitively, an address can be either a single address or
2000 a list of addresses (a group). This is why the returned Address object has
2001 a 'mailboxes' attribute which treats a single address as a list of length
2002 one. When you need to differentiate between to two cases, extract the single
2003 element, which is either a mailbox or a group token.
2004
2005 """
2006 # The formal grammar isn't very helpful when parsing an address. mailbox
2007 # and group, especially when allowing for obsolete forms, start off very
2008 # similarly. It is only when you reach one of @, <, or : that you know
2009 # what you've got. So, we try each one in turn, starting with the more
2010 # likely of the two. We could perhaps make this more efficient by looking
2011 # for a phrase and then branching based on the next character, but that
2012 # would be a premature optimization.
2013 address = Address()
2014 try:
2015 token, value = get_group(value)
2016 except errors.HeaderParseError:
2017 try:
2018 token, value = get_mailbox(value)
2019 except errors.HeaderParseError:
2020 raise errors.HeaderParseError(
2021 "expected address but found '{}'".format(value))
2022 address.append(token)
2023 return address, value
2024
2025def get_address_list(value):
2026 """ address_list = (address *("," address)) / obs-addr-list

Callers 1

get_address_listFunction · 0.85

Calls 5

get_groupFunction · 0.85
get_mailboxFunction · 0.85
AddressClass · 0.70
formatMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…