本文整理汇总了Python中email.mime.audio.MIMEAudio方法的典型用法代码示例。如果您正苦于以下问题:Python audio.MIMEAudio方法的具体用法?Python audio.MIMEAudio怎么用?Python audio.MIMEAudio使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类email.mime.audio
的用法示例。
在下文中一共展示了audio.MIMEAudio方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test__all__
# 需要导入模块: from email.mime import audio [as 别名]
# 或者: from email.mime.audio import MIMEAudio [as 别名]
def test__all__(self):
module = __import__('email')
# Can't use sorted() here due to Python 2.3 compatibility
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',
])
示例2: test_mangled_from_with_bad_bytes
# 需要导入模块: from email.mime import audio [as 别名]
# 或者: from email.mime.audio import MIMEAudio [as 别名]
def test_mangled_from_with_bad_bytes(self):
source = textwrap.dedent("""\
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
From: aaa@bbb.org
""").encode('utf-8')
msg = email.message_from_bytes(source + b'From R\xc3\xb6lli\n')
b = BytesIO()
g = BytesGenerator(b, mangle_from_=True)
g.flatten(msg)
self.assertEqual(b.getvalue(), source + b'>From R\xc3\xb6lli\n')
# Test the basic MIMEAudio class
示例3: attach
# 需要导入模块: from email.mime import audio [as 别名]
# 或者: from email.mime.audio import MIMEAudio [as 别名]
def attach(self, filename, content, mimetype):
maintype, subtype = mimetype.split('/', 1)
if maintype == 'text':
mime = MIMEText(content, subtype, None)
mime.set_payload(content, utf8_charset)
elif maintype == 'image':
mime = MIMEImage(content, subtype)
elif maintype == 'audio':
mime = MIMEAudio(content, subtype)
else:
mime = MIMEBase(maintype, subtype)
mime.set_payload(content)
encoders.encode_base64(mime)
self.attach_mime(filename, mime)
示例4: add_attachment
# 需要导入模块: from email.mime import audio [as 别名]
# 或者: from email.mime.audio import MIMEAudio [as 别名]
def add_attachment(self,filepath,filename=None):
if filename == None:
filename=os.path.basename(filepath)
with open(filepath,'rb') as f:
file=f.read()
ctype, encoding = mimetypes.guess_type(filepath)
if ctype is None or encoding is not None:ctype = "application/octet-stream"
maintype, subtype = ctype.split('/', 1)
if maintype == "text":
with open(filepath) as f:file=f.read()
attachment = MIMEText(file, _subtype=subtype)
elif maintype == "image":
with open(filepath,'rb') as f:file=f.read()
attachment = MIMEImage(file, _subtype=subtype)
elif maintype == "audio":
with open(filepath,'rb') as f:file=f.read()
attachment = MIMEAudio(file, _subtype=subtype)
else:
with open(filepath,'rb') as f:file=f.read()
attachment = MIMEBase(maintype,subtype)
attachment.set_payload(file)
attachment.add_header('Content-Disposition', 'attachment', filename=filename)
encoders.encode_base64(attachment)
attachment.add_header('Content-Disposition', 'attachment', filename=filename)
attachment.add_header('Content-ID',str(self.attachment_num))
self.attachment_num+=1
self.attachment_list.append(attachment)
示例5: test_dont_mangle_from
# 需要导入模块: from email.mime import audio [as 别名]
# 或者: from email.mime.audio import MIMEAudio [as 别名]
def test_dont_mangle_from(self):
s = StringIO()
g = Generator(s, mangle_from_=False)
g.flatten(self.msg)
self.assertEqual(s.getvalue(), """\
From: aaa@bbb.org
From the desk of A.A.A.:
Blah blah blah
""")
# Test the basic MIMEAudio class
示例6: setUp
# 需要导入模块: from email.mime import audio [as 别名]
# 或者: from email.mime.audio import MIMEAudio [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)
示例7: test_checkSetMinor
# 需要导入模块: from email.mime import audio [as 别名]
# 或者: from email.mime.audio import MIMEAudio [as 别名]
def test_checkSetMinor(self):
au = MIMEAudio(self._audiodata, 'fish')
self.assertEqual(au.get_content_type(), 'audio/fish')
示例8: _process_attachments
# 需要导入模块: from email.mime import audio [as 别名]
# 或者: from email.mime.audio import MIMEAudio [as 别名]
def _process_attachments(self, attachments):
for attachment in attachments:
ctype = attachment.AttachMimeTag
data = attachment.data
filename = attachment.Filename
maintype, subtype = ctype.split("/", 1)
if data is None:
continue
if isinstance(data, bytes):
data = data.decode("utf-8", "ignore")
if maintype == "text" or "message" in maintype:
attach = MIMEText(data, _subtype=subtype)
elif maintype == "image":
attach = MIMEImage(data, _subtype=subtype)
elif maintype == "audio":
attach = MIMEAudio(data, _subtype=subtype)
else:
attach = MIMEBase(maintype, subtype)
attach.set_payload(data)
# Encode the payload using Base64
encoders.encode_base64(attach)
# Set the filename parameter
base_filename = os.path.basename(filename)
attach.add_header("Content-ID", "<{}>".format(base_filename))
attach.add_header(
"Content-Disposition", "attachment", filename=base_filename
)
self.message.attach(attach)
示例9: setUp
# 需要导入模块: from email.mime import audio [as 别名]
# 或者: from email.mime.audio import MIMEAudio [as 别名]
def setUp(self):
with openfile('audiotest.au', 'rb') as fp:
self._audiodata = fp.read()
self._au = MIMEAudio(self._audiodata)
示例10: createAttachment
# 需要导入模块: from email.mime import audio [as 别名]
# 或者: from email.mime.audio import MIMEAudio [as 别名]
def createAttachment(filename, data):
# Guess the content type based on the file's extension. Encoding
# will be ignored, although we should check for simple things like
# gzip'd or compressed files.
ctype, encoding = mimetypes.guess_type(filename)
if ctype is None or encoding is not None:
# No guess could be made, or the file is encoded (compressed), so
# use a generic bag-of-bits type.
ctype = 'application/octet-stream'
maintype, subtype = ctype.split('/', 1)
if maintype == 'text':
data_bytes = data.read()
charset = chardet.detect(data_bytes)['encoding']
msg = MIMEText(data_bytes, _subtype=subtype, _charset=charset)
elif maintype == 'image':
msg = MIMEImage(data.read(), _subtype=subtype)
elif maintype == 'audio':
msg = MIMEAudio(data.read(), _subtype=subtype)
else:
msg = MIMEBase(maintype, subtype)
msg.set_payload(data.read())
# Encode the payload using Base64
encoders.encode_base64(msg)
# Set the filename parameter
msg.add_header('Content-Disposition', 'attachment', filename=filename)
return msg