当前位置: 首页>>代码示例>>Python>>正文


Python Utils.formataddr方法代码示例

本文整理汇总了Python中email.Utils.formataddr方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.formataddr方法的具体用法?Python Utils.formataddr怎么用?Python Utils.formataddr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在email.Utils的用法示例。


在下文中一共展示了Utils.formataddr方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: addr_header_encode

# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formataddr [as 别名]
def addr_header_encode(text, header_name=None):
    """Encode and line-wrap the value of an email header field containing
    email addresses."""

    # Convert to unicode, if required.
    if not isinstance(text, unicode):
        text = unicode(text, "utf-8")

    text = ", ".join(
        formataddr((header_encode(name), emailaddr))
        for name, emailaddr in getaddresses([text])
    )

    if is_ascii(text):
        charset = "ascii"
    else:
        charset = "utf-8"

    return Header(
        text, header_name=header_name, charset=Charset(charset)
    ).encode() 
开发者ID:Pagure,项目名称:pagure,代码行数:23,代码来源:git_multimail_upstream.py

示例2: sanitize_address

# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formataddr [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: set_recipients

# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formataddr [as 别名]
def set_recipients(self, name, value):
        self.unset_all(name)
        for pair in getaddresses([value]):
            self.add(name, formataddr(pair)) 
开发者ID:Pagure,项目名称:pagure,代码行数:6,代码来源:git_multimail_upstream.py

示例4: get_fromaddr

# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formataddr [as 别名]
def get_fromaddr(self, change=None):
        config = Config("user")
        fromname = config.get("name", default="")
        fromemail = config.get("email", default="")
        if fromemail:
            return formataddr([fromname, fromemail])
        return self.get_sender() 
开发者ID:Pagure,项目名称:pagure,代码行数:9,代码来源:git_multimail_upstream.py

示例5: test_parseaddr_empty

# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formataddr [as 别名]
def test_parseaddr_empty(self):
        self.assertEqual(Utils.parseaddr('<>'), ('', ''))
        self.assertEqual(Utils.formataddr(Utils.parseaddr('<>')), '') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_email.py

示例6: test_noquote_dump

# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formataddr [as 别名]
def test_noquote_dump(self):
        self.assertEqual(
            Utils.formataddr(('A Silly Person', 'person@dom.ain')),
            'A Silly Person <person@dom.ain>') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_email.py

示例7: test_escape_dump

# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formataddr [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

示例8: test_escape_backslashes

# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formataddr [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

示例9: test_name_with_dot

# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formataddr [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


注:本文中的email.Utils.formataddr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。