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


Python Utils.parseaddr方法代碼示例

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


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

示例1: test_parseaddr_preserves_quoted_pairs_in_addresses

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import parseaddr [as 別名]
def test_parseaddr_preserves_quoted_pairs_in_addresses(self):
        # issue 10005.  Note that in the third test the second pair of
        # backslashes is not actually a quoted pair because it is not inside a
        # comment or quoted string: the address being parsed has a quoted
        # string containing a quoted backslash, followed by 'example' and two
        # backslashes, followed by another quoted string containing a space and
        # the word 'example'.  parseaddr copies those two backslashes
        # literally.  Per rfc5322 this is not technically correct since a \ may
        # not appear in an address outside of a quoted string.  It is probably
        # a sensible Postel interpretation, though.
        eq = self.assertEqual
        eq(Utils.parseaddr('""example" example"@example.com'),
          ('', '""example" example"@example.com'))
        eq(Utils.parseaddr('"\\"example\\" example"@example.com'),
          ('', '"\\"example\\" example"@example.com'))
        eq(Utils.parseaddr('"\\\\"example\\\\" example"@example.com'),
          ('', '"\\\\"example\\\\" example"@example.com')) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:19,代碼來源:test_email.py

示例2: sanitize_address

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import parseaddr [as 別名]
def sanitize_address(addr, encoding):
    if isinstance(addr, basestring):
        addr = parseaddr(force_unicode(addr))
    nm, addr = addr
    nm = str(Header(nm, encoding))
    try:
        addr = addr.encode('ascii')
    except UnicodeEncodeError:  # IDN
        if u'@' in addr:
            localpart, domain = addr.split(u'@', 1)
            localpart = str(Header(localpart, encoding))
            domain = domain.encode('idna')
            addr = '@'.join([localpart, domain])
        else:
            addr = str(Header(addr, encoding))
    return formataddr((nm, addr)) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:18,代碼來源:message.py

示例3: test_parseaddr_empty

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import parseaddr [as 別名]
def test_parseaddr_empty(self):
        self.assertEqual(Utils.parseaddr('<>'), ('', ''))
        self.assertEqual(Utils.formataddr(Utils.parseaddr('<>')), '') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:5,代碼來源:test_email.py

示例4: test_parseaddr_multiple_domains

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import parseaddr [as 別名]
def test_parseaddr_multiple_domains(self):
        self.assertEqual(
            Utils.parseaddr('a@b@c'),
            ('', '')
        )
        self.assertEqual(
            Utils.parseaddr('a@b.c@c'),
            ('', '')
        )
        self.assertEqual(
            Utils.parseaddr('a@172.17.0.1@c'),
            ('', '')
        ) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:15,代碼來源:test_email.py

示例5: test_escape_dump

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import parseaddr [as 別名]
def test_escape_dump(self):
        self.assertEqual(
            Utils.formataddr(('A (Very) Silly Person', 'person@dom.ain')),
            r'"A \(Very\) Silly Person" <person@dom.ain>')
        a = r'A \(Special\) Person'
        b = 'person@dom.ain'
        self.assertEqual(Utils.parseaddr(Utils.formataddr((a, b))), (a, b)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:test_email.py

示例6: test_escape_backslashes

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import parseaddr [as 別名]
def test_escape_backslashes(self):
        self.assertEqual(
            Utils.formataddr(('Arthur \Backslash\ Foobar', 'person@dom.ain')),
            r'"Arthur \\Backslash\\ Foobar" <person@dom.ain>')
        a = r'Arthur \Backslash\ Foobar'
        b = 'person@dom.ain'
        self.assertEqual(Utils.parseaddr(Utils.formataddr((a, b))), (a, b)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:test_email.py

示例7: test_name_with_dot

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import parseaddr [as 別名]
def test_name_with_dot(self):
        x = 'John X. Doe <jxd@example.com>'
        y = '"John X. Doe" <jxd@example.com>'
        a, b = ('John X. Doe', 'jxd@example.com')
        self.assertEqual(Utils.parseaddr(x), (a, b))
        self.assertEqual(Utils.parseaddr(y), (a, b))
        # formataddr() quotes the name if there's a dot in it
        self.assertEqual(Utils.formataddr((a, b)), y) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_email.py

示例8: test_multiline_from_comment

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import parseaddr [as 別名]
def test_multiline_from_comment(self):
        x = """\
Foo
\tBar <foo@example.com>"""
        self.assertEqual(Utils.parseaddr(x), ('Foo Bar', 'foo@example.com')) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_email.py

示例9: multi_addrs

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import parseaddr [as 別名]
def multi_addrs(self, header):
        """return a list of 2-uple (name, address) for the given address (which
        is exepected to be an header containing address such as from, to, cc...)
        """
        persons = []
        for person in self.get_all(header, ()):
            name, mail = parseaddr(person)
            persons.append((name, mail))
        return persons 
開發者ID:jlachowski,項目名稱:clonedigger,代碼行數:11,代碼來源:umessage.py


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