audio.py (1042B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\stdlib\email\mime\audio.py 2 __all__ = ['MIMEAudio'] 3 try: 4 import sndhdr 5 except ImportError: 6 pass 7 8 from cStringIO import StringIO 9 from email import encoders 10 from email.mime.nonmultipart import MIMENonMultipart 11 _sndhdr_MIMEmap = {'au': 'basic', 12 'wav': 'x-wav', 13 'aiff': 'x-aiff', 14 'aifc': 'x-aiff'} 15 16 def _whatsnd(data): 17 hdr = data[:512] 18 fakefile = StringIO(hdr) 19 for testfn in sndhdr.tests: 20 res = testfn(hdr, fakefile) 21 if res is not None: 22 return _sndhdr_MIMEmap.get(res[0]) 23 24 25 class MIMEAudio(MIMENonMultipart): 26 27 def __init__(self, _audiodata, _subtype = None, _encoder = encoders.encode_base64, **_params): 28 if _subtype is None: 29 _subtype = _whatsnd(_audiodata) 30 if _subtype is None: 31 raise TypeError('Could not find audio MIME subtype') 32 MIMENonMultipart.__init__(self, 'audio', _subtype, **_params) 33 self.set_payload(_audiodata) 34 _encoder(self)