本文整理汇总了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)
示例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)
示例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