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


Python email.test方法代码示例

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


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

示例1: test_split_long_continuation

# 需要导入模块: import email [as 别名]
# 或者: from email import test [as 别名]
def test_split_long_continuation(self):
        eq = self.ndiffAssertEqual
        msg = email.message_from_string("""\
Subject: bug demonstration
\t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
\tmore text

test
""")
        sfp = StringIO()
        g = Generator(sfp)
        g.flatten(msg)
        eq(sfp.getvalue(), """\
Subject: bug demonstration
 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
 more text

test
""") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_email.py

示例2: test_whitespace_continuation_last_header

# 需要导入模块: import email [as 别名]
# 或者: from email import test [as 别名]
def test_whitespace_continuation_last_header(self):
        eq = self.assertEqual
        # Like the previous test, but the subject line is the last
        # header.
        msg = email.message_from_string("""\
From: aperson@dom.ain
To: bperson@dom.ain
Date: Mon, 8 Apr 2002 15:09:19 -0400
Message-ID: spam
Subject: the next line has a space on it
\x20

Here's the message body
""")
        eq(msg['subject'], 'the next line has a space on it\n ')
        eq(msg['message-id'], 'spam')
        eq(msg.get_payload(), "Here's the message body\n") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_email.py

示例3: test_mime_attachments_in_constructor

# 需要导入模块: import email [as 别名]
# 或者: from email import test [as 别名]
def test_mime_attachments_in_constructor(self):
        eq = self.assertEqual
        text1 = MIMEText('')
        text2 = MIMEText('')
        msg = MIMEMultipart(_subparts=(text1, text2))
        eq(len(msg.get_payload()), 2)
        eq(msg.get_payload(0), text1)
        eq(msg.get_payload(1), text2)



# A general test of parser->model->generator idempotency.  IOW, read a message
# in, parse it into a message object tree, then without touching the tree,
# regenerate the plain text.  The original text and the transformed text
# should be identical.  Note: that we ignore the Unix-From since that may
# contain a changed date. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_email_renamed.py

示例4: openfile

# 需要导入模块: import email [as 别名]
# 或者: from email import test [as 别名]
def openfile(filename, mode='r'):
    path = os.path.join(os.path.dirname(landmark), 'data', filename)
    return open(path, mode)



# Base test class 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_email.py

示例5: test_embedded_header_via_Header_rejected

# 需要导入模块: import email [as 别名]
# 或者: from email import test [as 别名]
def test_embedded_header_via_Header_rejected(self):
        msg = Message()
        msg['Dummy'] = Header('dummy\nX-Injected-Header: test')
        self.assertRaises(Errors.HeaderParseError, msg.as_string) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_email.py

示例6: test_embedded_header_via_string_rejected

# 需要导入模块: import email [as 别名]
# 或者: from email import test [as 别名]
def test_embedded_header_via_string_rejected(self):
        msg = Message()
        msg['Dummy'] = 'dummy\nX-Injected-Header: test'
        self.assertRaises(Errors.HeaderParseError, msg.as_string)


# Test the email.Encoders module 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_email.py

示例7: test_no_semis_header_splitter

# 需要导入模块: import email [as 别名]
# 或者: from email import test [as 别名]
def test_no_semis_header_splitter(self):
        eq = self.ndiffAssertEqual
        msg = Message()
        msg['From'] = 'test@dom.ain'
        msg['References'] = SPACE.join(['<%d@dom.ain>' % i for i in range(10)])
        msg.set_payload('Test')
        sfp = StringIO()
        g = Generator(sfp)
        g.flatten(msg)
        eq(sfp.getvalue(), """\
From: test@dom.ain
References: <0@dom.ain> <1@dom.ain> <2@dom.ain> <3@dom.ain> <4@dom.ain>
 <5@dom.ain> <6@dom.ain> <7@dom.ain> <8@dom.ain> <9@dom.ain>

Test""") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_email.py

示例8: setUp

# 需要导入模块: import email [as 别名]
# 或者: from email import test [as 别名]
def setUp(self):
        # Make sure we pick up the audiotest.au that lives in email/test/data.
        # In Python, there's an audiotest.au living in Lib/test but that isn't
        # included in some binary distros that don't include the test
        # package.  The trailing empty string on the .join() is significant
        # since findfile() will do a dirname().
        datadir = os.path.join(os.path.dirname(landmark), 'data', '')
        fp = open(findfile('audiotest.au', datadir), 'rb')
        try:
            self._audiodata = fp.read()
        finally:
            fp.close()
        self._au = MIMEAudio(self._audiodata) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_email.py

示例9: test_rfc2047_B_bad_padding

# 需要导入模块: import email [as 别名]
# 或者: from email import test [as 别名]
def test_rfc2047_B_bad_padding(self):
        s = '=?iso-8859-1?B?%s?='
        data = [                                # only test complete bytes
            ('dm==', 'v'), ('dm=', 'v'), ('dm', 'v'),
            ('dmk=', 'vi'), ('dmk', 'vi')
          ]
        for q, a in data:
            dh = decode_header(s % q)
            self.assertEqual(dh, [(a, 'iso-8859-1')]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_email.py

示例10: test_default_multipart_constructor

# 需要导入模块: import email [as 别名]
# 或者: from email import test [as 别名]
def test_default_multipart_constructor(self):
        msg = MIMEMultipart()
        self.assertTrue(msg.is_multipart())


# A general test of parser->model->generator idempotency.  IOW, read a message
# in, parse it into a message object tree, then without touching the tree,
# regenerate the plain text.  The original text and the transformed text
# should be identical.  Note: that we ignore the Unix-From since that may
# contain a changed date. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_email.py

示例11: test_message_from_string

# 需要导入模块: import email [as 别名]
# 或者: from email import test [as 别名]
def test_message_from_string(self):
        fp = openfile('msg_01.txt')
        try:
            text = fp.read()
        finally:
            fp.close()
        msg = email.message_from_string(text)
        s = StringIO()
        # Don't wrap/continue long headers since we're trying to test
        # idempotency.
        g = Generator(s, maxheaderlen=0)
        g.flatten(msg)
        self.assertEqual(text, s.getvalue()) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_email.py

示例12: test_message_from_file

# 需要导入模块: import email [as 别名]
# 或者: from email import test [as 别名]
def test_message_from_file(self):
        fp = openfile('msg_01.txt')
        try:
            text = fp.read()
            fp.seek(0)
            msg = email.message_from_file(fp)
            s = StringIO()
            # Don't wrap/continue long headers since we're trying to test
            # idempotency.
            g = Generator(s, maxheaderlen=0)
            g.flatten(msg)
            self.assertEqual(text, s.getvalue())
        finally:
            fp.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_email.py

示例13: test_idempotent

# 需要导入模块: import email [as 别名]
# 或者: from email import test [as 别名]
def test_idempotent(self):
        eq = self.assertEqual
        # Make sure us-ascii = no Unicode conversion
        c = Charset('us-ascii')
        s = 'Hello World!'
        sp = c.to_splittable(s)
        eq(s, c.from_splittable(sp))
        # test 8-bit idempotency with us-ascii
        s = '\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa'
        sp = c.to_splittable(s)
        eq(s, c.from_splittable(sp)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_email.py

示例14: test_explicit_maxlinelen

# 需要导入模块: import email [as 别名]
# 或者: from email import test [as 别名]
def test_explicit_maxlinelen(self):
        eq = self.ndiffAssertEqual
        hstr = 'A very long line that must get split to something other than at the 76th character boundary to test the non-default behavior'
        h = Header(hstr)
        eq(h.encode(), '''\
A very long line that must get split to something other than at the 76th
 character boundary to test the non-default behavior''')
        h = Header(hstr, header_name='Subject')
        eq(h.encode(), '''\
A very long line that must get split to something other than at the
 76th character boundary to test the non-default behavior''')
        h = Header(hstr, maxlinelen=1024, header_name='Subject')
        eq(h.encode(), hstr) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_email.py

示例15: test_set_param

# 需要导入模块: import email [as 别名]
# 或者: from email import test [as 别名]
def test_set_param(self):
        eq = self.assertEqual
        msg = Message()
        msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
                      charset='us-ascii')
        eq(msg.get_param('title'),
           ('us-ascii', '', 'This is even more ***fun*** isn\'t it!'))
        msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
                      charset='us-ascii', language='en')
        eq(msg.get_param('title'),
           ('us-ascii', 'en', 'This is even more ***fun*** isn\'t it!'))
        msg = self._msgobj('msg_01.txt')
        msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
                      charset='us-ascii', language='en')
        self.ndiffAssertEqual(msg.as_string(), """\
Return-Path: <bbb@zzz.org>
Delivered-To: bbb@zzz.org
Received: by mail.zzz.org (Postfix, from userid 889)
 id 27CEAD38CC; Fri,  4 May 2001 14:05:44 -0400 (EDT)
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
From: bbb@ddd.com (John X. Doe)
To: bbb@zzz.org
Subject: This is a test message
Date: Fri, 4 May 2001 14:05:44 -0400
Content-Type: text/plain; charset=us-ascii;
 title*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21"


Hi,

Do you like this message?

-Me
""") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:38,代码来源:test_email.py


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