當前位置: 首頁>>代碼示例>>Python>>正文


Python Envelope.add_attachment方法代碼示例

本文整理匯總了Python中envelopes.envelope.Envelope.add_attachment方法的典型用法代碼示例。如果您正苦於以下問題:Python Envelope.add_attachment方法的具體用法?Python Envelope.add_attachment怎麽用?Python Envelope.add_attachment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在envelopes.envelope.Envelope的用法示例。


在下文中一共展示了Envelope.add_attachment方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_add_attachment

# 需要導入模塊: from envelopes.envelope import Envelope [as 別名]
# 或者: from envelopes.envelope.Envelope import add_attachment [as 別名]
    def test_add_attachment(self):
        msg = self._dummy_message()
        envelope = Envelope(**msg)

        _jpg = self._tempfile(suffix='.jpg')
        envelope.add_attachment(_jpg)

        _mp3 = self._tempfile(suffix='.mp3')
        envelope.add_attachment(_mp3)

        _pdf = self._tempfile(suffix='.pdf')
        envelope.add_attachment(_pdf)

        _something = self._tempfile(suffix='.something', prefix=u'ęóąśłżźćń')
        envelope.add_attachment(_something)

        _octet = self._tempfile(suffix='.txt')
        envelope.add_attachment(_octet, mimetype='application/octet-stream')

        assert len(envelope._parts) == 7

        assert envelope._parts[0][0] == 'text/plain'
        assert envelope._parts[1][0] == 'text/html'

        assert envelope._parts[2][0] == 'image/jpeg'
        assert envelope._parts[2][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_jpg)

        assert envelope._parts[3][0] == 'audio/mpeg'
        assert envelope._parts[3][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_mp3)

        assert envelope._parts[4][0] == 'application/pdf'
        assert envelope._parts[4][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_pdf)

        assert envelope._parts[5][0] == 'application/octet-stream'
        assert envelope._parts[5][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' %\
            os.path.basename(encoded(_something, 'utf-8'))

        assert envelope._parts[6][0] == 'application/octet-stream'
        assert envelope._parts[6][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_octet)
開發者ID:dec0dedab0de,項目名稱:envelopes,代碼行數:46,代碼來源:test_envelope.py

示例2: test_add_attachment

# 需要導入模塊: from envelopes.envelope import Envelope [as 別名]
# 或者: from envelopes.envelope.Envelope import add_attachment [as 別名]
    def test_add_attachment(self):
        msg = self._dummy_message()
        envelope = Envelope(**msg)

        _jpg = self._tempfile(suffix=".jpg")
        envelope.add_attachment(_jpg)

        _mp3 = self._tempfile(suffix=".mp3")
        envelope.add_attachment(_mp3)

        _pdf = self._tempfile(suffix=".pdf")
        envelope.add_attachment(_pdf)

        _something = self._tempfile(suffix=".something", prefix=u"ęóąśłżźćń")
        envelope.add_attachment(_something)

        _octet = self._tempfile(suffix=".txt")
        envelope.add_attachment(_octet, mimetype="application/octet-stream")

        assert len(envelope._parts) == 7

        assert envelope._parts[0][0] == "text/plain"
        assert envelope._parts[1][0] == "text/html"

        assert envelope._parts[2][0] == "image/jpeg"
        assert envelope._parts[2][1]["Content-Disposition"] == 'attachment; filename="%s"' % os.path.basename(_jpg)

        assert envelope._parts[3][0] == "audio/mpeg"
        assert envelope._parts[3][1]["Content-Disposition"] == 'attachment; filename="%s"' % os.path.basename(_mp3)

        assert envelope._parts[4][0] == "application/pdf"
        assert envelope._parts[4][1]["Content-Disposition"] == 'attachment; filename="%s"' % os.path.basename(_pdf)

        assert envelope._parts[5][0] == "application/octet-stream"
        assert envelope._parts[5][1]["Content-Disposition"] == 'attachment; filename="%s"' % os.path.basename(
            encoded(_something, "utf-8")
        )

        assert envelope._parts[6][0] == "application/octet-stream"
        assert envelope._parts[6][1]["Content-Disposition"] == 'attachment; filename="%s"' % os.path.basename(_octet)
開發者ID:blueicesir,項目名稱:envelopes,代碼行數:42,代碼來源:test_envelope.py

示例3: test_add_attachment

# 需要導入模塊: from envelopes.envelope import Envelope [as 別名]
# 或者: from envelopes.envelope.Envelope import add_attachment [as 別名]
    def test_add_attachment(self):
        msg = self._dummy_message()
        envelope = Envelope(**msg)

        _jpg = self._tempfile(suffix='.jpg')
        envelope.add_attachment(_jpg)

        _mp3 = self._tempfile(suffix='.mp3')
        envelope.add_attachment(_mp3)

        _pdf = self._tempfile(suffix='.pdf')
        envelope.add_attachment(_pdf)

        _something = self._tempfile(suffix='.something', prefix=u'ęóąśłżźćń')
        envelope.add_attachment(_something)

        _octet = self._tempfile(suffix='.txt')
        envelope.add_attachment(_octet, mimetype='application/octet-stream')

        # Attach from string
        envelope.add_attachment('file1.txt', data=LOREM, mimetype='text/plain')

        # Attach from stream
        sio = io.BytesIO(LOREM)
        envelope.add_attachment('file2.txt', data=sio, mimetype='text/plain')

        assert len(envelope._parts) == 9

        assert envelope._parts[0][0] == 'text/plain'
        assert envelope._parts[1][0] == 'text/html'

        assert envelope._parts[2][0] == 'image/jpeg'
        assert envelope._parts[2][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_jpg)

        assert envelope._parts[3][0] == 'audio/mpeg'
        assert envelope._parts[3][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_mp3)

        assert envelope._parts[4][0] == 'application/pdf'
        assert envelope._parts[4][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_pdf)

        assert envelope._parts[5][0] == 'application/octet-stream'
        assert envelope._parts[5][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' %\
            os.path.basename(encoded(_something, 'utf-8'))

        assert envelope._parts[6][0] == 'application/octet-stream'
        assert envelope._parts[6][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_octet)

        assert envelope._parts[6][0] == 'application/octet-stream'
        assert envelope._parts[6][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_octet)

        assert envelope._parts[7][0] == 'text/plain'
        assert envelope._parts[7][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename('file1.txt')
        assert envelope._parts[7][1].get_payload(decode=True) == LOREM

        assert envelope._parts[8][0] == 'text/plain'
        assert envelope._parts[8][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename('file2.txt')
        assert envelope._parts[8][1].get_payload(decode=True) == LOREM
開發者ID:zefciu,項目名稱:envelopes,代碼行數:67,代碼來源:test_envelope.py


注:本文中的envelopes.envelope.Envelope.add_attachment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。