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


Python audio.MIMEAudio方法代码示例

本文整理汇总了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',
            ]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_email_renamed.py

示例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 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:18,代码来源:test_email.py

示例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) 
开发者ID:alexandrevicenzi,项目名称:fluentmail,代码行数:18,代码来源:message.py

示例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) 
开发者ID:Aliencn,项目名称:Smail,代码行数:34,代码来源:Smail.py

示例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 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_email_renamed.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_email_renamed.py

示例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') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_email_renamed.py

示例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) 
开发者ID:vikramarsid,项目名称:msg_parser,代码行数:34,代码来源:email_builder.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:6,代码来源:test_email.py

示例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 
开发者ID:muesli-hd,项目名称:muesli,代码行数:28,代码来源:mail.py


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