當前位置: 首頁>>代碼示例>>Python>>正文


Python headerregistry.Address方法代碼示例

本文整理匯總了Python中email.headerregistry.Address方法的典型用法代碼示例。如果您正苦於以下問題:Python headerregistry.Address方法的具體用法?Python headerregistry.Address怎麽用?Python headerregistry.Address使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在email.headerregistry的用法示例。


在下文中一共展示了headerregistry.Address方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: sanitize_address

# 需要導入模塊: from email import headerregistry [as 別名]
# 或者: from email.headerregistry import Address [as 別名]
def sanitize_address(addr, encoding):
    """
    Format a pair of (name, address) or an email address string.
    """
    if not isinstance(addr, tuple):
        addr = parseaddr(force_text(addr))
    nm, addr = addr
    localpart, domain = None, None
    nm = Header(nm, encoding).encode()
    try:
        addr.encode('ascii')
    except UnicodeEncodeError:  # IDN or non-ascii in the local part
        localpart, domain = split_addr(addr, encoding)

    if six.PY2:
        # On Python 2, use the stdlib since `email.headerregistry` doesn't exist.
        from email.utils import formataddr
        if localpart and domain:
            addr = '@'.join([localpart, domain])
        return formataddr((nm, addr))

    # On Python 3, an `email.headerregistry.Address` object is used since
    # email.utils.formataddr() naively encodes the name as ascii (see #25986).
    from email.headerregistry import Address
    from email.errors import InvalidHeaderDefect, NonASCIILocalPartDefect

    if localpart and domain:
        address = Address(nm, username=localpart, domain=domain)
        return str(address)

    try:
        address = Address(nm, addr_spec=addr)
    except (InvalidHeaderDefect, NonASCIILocalPartDefect):
        localpart, domain = split_addr(addr, encoding)
        address = Address(nm, username=localpart, domain=domain)
    return str(address) 
開發者ID:KimJangHyeon,項目名稱:NarshaTech,代碼行數:38,代碼來源:message.py

示例2: test_addresses_types

# 需要導入模塊: from email import headerregistry [as 別名]
# 或者: from email.headerregistry import Address [as 別名]
def test_addresses_types(self):
        source = 'me <[email protected]>'
        h = self.make_header('to', source)
        self.assertIsInstance(h.addresses, tuple)
        self.assertIsInstance(h.addresses[0], Address) 
開發者ID:molebot,項目名稱:web_ctp,代碼行數:7,代碼來源:test_headerregistry.py

示例3: test_set_from_Address

# 需要導入模塊: from email import headerregistry [as 別名]
# 或者: from email.headerregistry import Address [as 別名]
def test_set_from_Address(self):
        h = self.make_header('to', Address('me', 'foo', 'example.com'))
        self.assertEqual(h, 'me <[email protected]>') 
開發者ID:molebot,項目名稱:web_ctp,代碼行數:5,代碼來源:test_headerregistry.py

示例4: test_set_from_Address_list

# 需要導入模塊: from email import headerregistry [as 別名]
# 或者: from email.headerregistry import Address [as 別名]
def test_set_from_Address_list(self):
        h = self.make_header('to', [Address('me', 'foo', 'example.com'),
                                    Address('you', 'bar', 'example.com')])
        self.assertEqual(h, 'me <[email protected]>, you <[email protected]>') 
開發者ID:molebot,項目名稱:web_ctp,代碼行數:6,代碼來源:test_headerregistry.py

示例5: test_set_from_Address_and_Group_list

# 需要導入模塊: from email import headerregistry [as 別名]
# 或者: from email.headerregistry import Address [as 別名]
def test_set_from_Address_and_Group_list(self):
        h = self.make_header('to', [Address('me', 'foo', 'example.com'),
                                    Group('bing', [Address('fiz', 'z', 'b.com'),
                                                   Address('zif', 'f', 'c.com')]),
                                    Address('you', 'bar', 'example.com')])
        self.assertEqual(h, 'me <[email protected]>, bing: fiz <[email protected]>, '
                            'zif <[email protected]>;, you <[email protected]>')
        self.assertEqual(h.fold(policy=policy.default.clone(max_line_length=40)),
                        'to: me <[email protected]>,\n'
                        ' bing: fiz <[email protected]>, zif <[email protected]>;,\n'
                        ' you <[email protected]>\n') 
開發者ID:molebot,項目名稱:web_ctp,代碼行數:13,代碼來源:test_headerregistry.py

示例6: test_set_from_Group_list

# 需要導入模塊: from email import headerregistry [as 別名]
# 或者: from email.headerregistry import Address [as 別名]
def test_set_from_Group_list(self):
        h = self.make_header('to', [Group('bing', [Address('fiz', 'z', 'b.com'),
                                                   Address('zif', 'f', 'c.com')])])
        self.assertEqual(h, 'bing: fiz <[email protected]>, zif <[email protected]>;') 
開發者ID:molebot,項目名稱:web_ctp,代碼行數:6,代碼來源:test_headerregistry.py

示例7: test_address_username_ro

# 需要導入模塊: from email import headerregistry [as 別名]
# 或者: from email.headerregistry import Address [as 別名]
def test_address_username_ro(self):
        self._test_attr_ro(Address('foo', 'bar', 'baz'), 'username') 
開發者ID:molebot,項目名稱:web_ctp,代碼行數:4,代碼來源:test_headerregistry.py

示例8: test_address_domain_ro

# 需要導入模塊: from email import headerregistry [as 別名]
# 或者: from email.headerregistry import Address [as 別名]
def test_address_domain_ro(self):
        self._test_attr_ro(Address('foo', 'bar', 'baz'), 'domain') 
開發者ID:molebot,項目名稱:web_ctp,代碼行數:4,代碼來源:test_headerregistry.py

示例9: test_address_from_username_domain

# 需要導入模塊: from email import headerregistry [as 別名]
# 或者: from email.headerregistry import Address [as 別名]
def test_address_from_username_domain(self):
        a = Address('foo', 'bar', 'baz')
        self.assertEqual(a.display_name, 'foo')
        self.assertEqual(a.username, 'bar')
        self.assertEqual(a.domain, 'baz')
        self.assertEqual(a.addr_spec, '[email protected]')
        self.assertEqual(str(a), 'foo <[email protected]>') 
開發者ID:molebot,項目名稱:web_ctp,代碼行數:9,代碼來源:test_headerregistry.py

示例10: test_address_from_addr_spec

# 需要導入模塊: from email import headerregistry [as 別名]
# 或者: from email.headerregistry import Address [as 別名]
def test_address_from_addr_spec(self):
        a = Address('foo', addr_spec='[email protected]')
        self.assertEqual(a.display_name, 'foo')
        self.assertEqual(a.username, 'bar')
        self.assertEqual(a.domain, 'baz')
        self.assertEqual(a.addr_spec, '[email protected]')
        self.assertEqual(str(a), 'foo <[email protected]>') 
開發者ID:molebot,項目名稱:web_ctp,代碼行數:9,代碼來源:test_headerregistry.py

示例11: test_address_with_no_display_name

# 需要導入模塊: from email import headerregistry [as 別名]
# 或者: from email.headerregistry import Address [as 別名]
def test_address_with_no_display_name(self):
        a = Address(addr_spec='[email protected]')
        self.assertEqual(a.display_name, '')
        self.assertEqual(a.username, 'bar')
        self.assertEqual(a.domain, 'baz')
        self.assertEqual(a.addr_spec, '[email protected]')
        self.assertEqual(str(a), '[email protected]') 
開發者ID:molebot,項目名稱:web_ctp,代碼行數:9,代碼來源:test_headerregistry.py

示例12: test_domain_only

# 需要導入模塊: from email import headerregistry [as 別名]
# 或者: from email.headerregistry import Address [as 別名]
def test_domain_only(self):
        # This isn't really a valid address.
        a = Address(domain='buzz')
        self.assertEqual(a.display_name, '')
        self.assertEqual(a.username, '')
        self.assertEqual(a.domain, 'buzz')
        self.assertEqual(a.addr_spec, '@buzz')
        self.assertEqual(str(a), '@buzz') 
開發者ID:molebot,項目名稱:web_ctp,代碼行數:10,代碼來源:test_headerregistry.py

示例13: test_username_only

# 需要導入模塊: from email import headerregistry [as 別名]
# 或者: from email.headerregistry import Address [as 別名]
def test_username_only(self):
        # This isn't really a valid address.
        a = Address(username='buzz')
        self.assertEqual(a.display_name, '')
        self.assertEqual(a.username, 'buzz')
        self.assertEqual(a.domain, '')
        self.assertEqual(a.addr_spec, 'buzz')
        self.assertEqual(str(a), 'buzz') 
開發者ID:molebot,項目名稱:web_ctp,代碼行數:10,代碼來源:test_headerregistry.py

示例14: test_display_name_only

# 需要導入模塊: from email import headerregistry [as 別名]
# 或者: from email.headerregistry import Address [as 別名]
def test_display_name_only(self):
        a = Address('buzz')
        self.assertEqual(a.display_name, 'buzz')
        self.assertEqual(a.username, '')
        self.assertEqual(a.domain, '')
        self.assertEqual(a.addr_spec, '<>')
        self.assertEqual(str(a), 'buzz <>') 
開發者ID:molebot,項目名稱:web_ctp,代碼行數:9,代碼來源:test_headerregistry.py

示例15: test_quoting

# 需要導入模塊: from email import headerregistry [as 別名]
# 或者: from email.headerregistry import Address [as 別名]
def test_quoting(self):
        # Ideally we'd check every special individually, but I'm not up for
        # writing that many tests.
        a = Address('Sara J.', 'bad name', 'example.com')
        self.assertEqual(a.display_name, 'Sara J.')
        self.assertEqual(a.username, 'bad name')
        self.assertEqual(a.domain, 'example.com')
        self.assertEqual(a.addr_spec, '"bad name"@example.com')
        self.assertEqual(str(a), '"Sara J." <"bad name"@example.com>') 
開發者ID:molebot,項目名稱:web_ctp,代碼行數:11,代碼來源:test_headerregistry.py


注:本文中的email.headerregistry.Address方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。