+++ /dev/null
-# Copyright (C) 2001-2006 Python Software Foundation\r
-# Author: Anthony Baxter\r
-# Contact: email-sig@python.org\r
-\r
-"""Class representing audio/* type MIME documents."""\r
-\r
-__all__ = ['MIMEAudio']\r
-\r
-import sndhdr\r
-\r
-from cStringIO import StringIO\r
-from email import encoders\r
-from email.mime.nonmultipart import MIMENonMultipart\r
-\r
-\r
-\f\r
-_sndhdr_MIMEmap = {'au' : 'basic',\r
- 'wav' :'x-wav',\r
- 'aiff':'x-aiff',\r
- 'aifc':'x-aiff',\r
- }\r
-\r
-# There are others in sndhdr that don't have MIME types. :(\r
-# Additional ones to be added to sndhdr? midi, mp3, realaudio, wma??\r
-def _whatsnd(data):\r
- """Try to identify a sound file type.\r
-\r
- sndhdr.what() has a pretty cruddy interface, unfortunately. This is why\r
- we re-do it here. It would be easier to reverse engineer the Unix 'file'\r
- command and use the standard 'magic' file, as shipped with a modern Unix.\r
- """\r
- hdr = data[:512]\r
- fakefile = StringIO(hdr)\r
- for testfn in sndhdr.tests:\r
- res = testfn(hdr, fakefile)\r
- if res is not None:\r
- return _sndhdr_MIMEmap.get(res[0])\r
- return None\r
-\r
-\r
-\f\r
-class MIMEAudio(MIMENonMultipart):\r
- """Class for generating audio/* MIME documents."""\r
-\r
- def __init__(self, _audiodata, _subtype=None,\r
- _encoder=encoders.encode_base64, **_params):\r
- """Create an audio/* type MIME document.\r
-\r
- _audiodata is a string containing the raw audio data. If this data\r
- can be decoded by the standard Python `sndhdr' module, then the\r
- subtype will be automatically included in the Content-Type header.\r
- Otherwise, you can specify the specific audio subtype via the\r
- _subtype parameter. If _subtype is not given, and no subtype can be\r
- guessed, a TypeError is raised.\r
-\r
- _encoder is a function which will perform the actual encoding for\r
- transport of the image data. It takes one argument, which is this\r
- Image instance. It should use get_payload() and set_payload() to\r
- change the payload to the encoded form. It should also add any\r
- Content-Transfer-Encoding or other headers to the message as\r
- necessary. The default encoding is Base64.\r
-\r
- Any additional keyword arguments are passed to the base class\r
- constructor, which turns them into parameters on the Content-Type\r
- header.\r
- """\r
- if _subtype is None:\r
- _subtype = _whatsnd(_audiodata)\r
- if _subtype is None:\r
- raise TypeError('Could not find audio MIME subtype')\r
- MIMENonMultipart.__init__(self, 'audio', _subtype, **_params)\r
- self.set_payload(_audiodata)\r
- _encoder(self)\r