本文整理匯總了Python中email.Parser方法的典型用法代碼示例。如果您正苦於以下問題:Python email.Parser方法的具體用法?Python email.Parser怎麽用?Python email.Parser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類email
的用法示例。
在下文中一共展示了email.Parser方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_empty_multipart_idempotent
# 需要導入模塊: import email [as 別名]
# 或者: from email import Parser [as 別名]
def test_empty_multipart_idempotent(self):
text = """\
Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: aperson@dom.ain
From: bperson@dom.ain
--BOUNDARY
--BOUNDARY--
"""
msg = Parser().parsestr(text)
self.ndiffAssertEqual(text, msg.as_string())
示例2: test_boundary_without_trailing_newline
# 需要導入模塊: import email [as 別名]
# 或者: from email import Parser [as 別名]
def test_boundary_without_trailing_newline(self):
m = Parser().parsestr("""\
Content-Type: multipart/mixed; boundary="===============0012394164=="
MIME-Version: 1.0
--===============0012394164==
Content-Type: image/file1.jpg
MIME-Version: 1.0
Content-Transfer-Encoding: base64
YXNkZg==
--===============0012394164==--""")
self.assertEqual(m.get_payload(0).get_payload(), 'YXNkZg==')
# Test some badly formatted messages
示例3: test__all__
# 需要導入模塊: import email [as 別名]
# 或者: from email import Parser [as 別名]
def test__all__(self):
module = __import__('email')
all = module.__all__
all.sort()
self.assertEqual(all, [
# Old names
'Charset', 'Encoders', 'Errors', 'Generator',
'Header', 'Iterators', 'MIMEAudio', 'MIMEBase',
'MIMEImage', 'MIMEMessage', 'MIMEMultipart',
'MIMENonMultipart', 'MIMEText', 'Message',
'Parser', 'Utils', 'base64MIME',
# new names
'base64mime', 'charset', 'encoders', 'errors', 'generator',
'header', 'iterators', 'message', 'message_from_file',
'message_from_string', 'mime', 'parser',
'quopriMIME', 'quoprimime', 'utils',
])
示例4: test_boundary_without_trailing_newline
# 需要導入模塊: import email [as 別名]
# 或者: from email import Parser [as 別名]
def test_boundary_without_trailing_newline(self):
m = Parser().parsestr("""\
Content-Type: multipart/mixed; boundary="===============0012394164=="
MIME-Version: 1.0
--===============0012394164==
Content-Type: image/file1.jpg
MIME-Version: 1.0
Content-Transfer-Encoding: base64
YXNkZg==
--===============0012394164==--""")
self.assertEquals(m.get_payload(0).get_payload(), 'YXNkZg==')
# Test some badly formatted messages
示例5: test_message_rfc822_only
# 需要導入模塊: import email [as 別名]
# 或者: from email import Parser [as 別名]
def test_message_rfc822_only(self):
# Issue 7970: message/rfc822 not in multipart parsed by
# HeaderParser caused an exception when flattened.
fp = openfile(findfile('msg_46.txt'))
msgdata = fp.read()
parser = email.Parser.HeaderParser()
msg = parser.parsestr(msgdata)
out = StringIO()
gen = email.Generator.Generator(out, True, 0)
gen.flatten(msg, False)
self.assertEqual(out.getvalue(), msgdata)