#!/usr/bin/env python """Data structures and functions used to support work with mime objects.""" import sys import unittest import zipfile from io import BytesIO try: from StringIO import StringIO #Python 2 except ImportError: from io import StringIO #Python 3 mime_support_version = '0.7' #Default extension to use when a particular mime type is found. Not intended to be used directly, use ext_of_mime instead. default_ext_of_mime = { 'Composite Document File V2 Document': 'doc', 'application/CDFV2': 'wps', 'application/epub+zip': 'epub', 'application/java-archive': 'jar', 'application/javascript': 'js', 'application/mac-binhex40': 'hqx', 'application/msword': 'doc', 'application/ogg': 'ogg', 'application/pdf': 'pdf', 'application/pgp': 'gpg', 'application/pgp-keys': 'aexpk', 'application/pkcs7-signature': 'p7', 'application/postscript': 'ps', 'application/vnd.ms-cab-compressed': 'cab', 'application/vnd.ms-excel': 'xls', 'application/vnd.ms-excel.addin.macroEnabled.12': 'xlam', 'application/vnd.ms-excel.sheet.binary.macroEnabled.12': 'xlsb', 'application/vnd.ms-excel.sheet.macroEnabled.12': 'xlsm', 'application/vnd.ms-excel.template.macroEnabled.12': 'xltm', 'application/vnd.ms-fontobject': 'eot', 'application/vnd.ms-opentype': 'otf', 'application/vnd.ms-powerpoint': 'ppt', 'application/vnd.ms-powerpoint.addin.macroEnabled.12': 'ppam', 'application/vnd.ms-powerpoint.presentation.macroEnabled.12': 'pptm', 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12': 'ppsm', 'application/vnd.ms-powerpoint.template.macroEnabled.12': 'potm', 'application/vnd.ms-tnef': 'dat', 'application/vnd.ms-word.document.macroEnabled.12': 'docm', 'application/vnd.ms-word.template.macroEnabled.12': 'dotm', 'application/vnd.oasis.opendocument.presentation': 'odp', 'application/vnd.oasis.opendocument.spreadsheet': 'ods', 'application/vnd.oasis.opendocument.text': 'odt', 'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'pptx', 'application/vnd.openxmlformats-officedocument.presentationml.slideshow': 'ppsx', 'application/vnd.openxmlformats-officedocument.presentationml.template': 'potx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.template': 'xltx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.template': 'dotx', 'application/vnd.tcpdump.pcap': 'pcap', 'application/x-7z-compressed': '7z', 'application/x-apple-diskimage': 'dmg', 'application/x-arc': 'arc', 'application/x-arj': 'arj', 'application/x-bittorrent': 'torrent', 'application/x-bzip2': 'bz2', 'application/x-chrome-extension': 'crx', 'application/x-coredump': 'core', 'application/x-cpio': 'cpio', 'application/x-dmg': 'dmg', 'application/x-dosexec': 'exe', 'application/x-elc': 'elc', 'application/x-empty': 'empty', 'application/x-fortran': 'f', 'application/x-gzip': 'gz', 'application/x-executable': 'exe', 'application/x-font-ttf': 'ttf', 'application/x-hwp': 'hwp', 'application/x-ima': 'ima', 'application/x-iso9660-image': 'iso', 'application/x-java-applet': 'jar', 'application/x-javascript': 'js', 'application/x-lha': 'lha', 'application/x-lzh-compressed': 'lzh', 'application/x-mach-binary': 'macbin', 'application/x-ms-wmz': 'wmz', 'application/x-msdownload': 'exe', 'application/x-msi': 'msi', 'application/x-pem': 'pem', 'application/x-rar': 'rar', 'application/x-rpm': 'rpm', 'application/x-sharedlib': 'lib', 'application/x-shockwave-flash': 'swf', 'application/x-stuffit': 'sit', 'application/x-tar': 'tar', 'application/x-xar': 'pkg', 'application/x-xz': 'xz', 'application/zip': 'zip', 'application/zlib': 'dmg', 'audio/midi': 'mid', 'audio/mp4': 'm4a', 'audio/mpeg': 'mp3', 'audio/x-m4a': 'm4a', 'audio/x-wav': 'wav', 'image/gif': 'gif', 'image/jpeg': 'jpg', 'image/jxr': 'jxr', 'image/pjpeg': 'jpg', 'image/tiff': 'tif', 'image/png': 'png', 'image/svg+xml': 'svg', 'image/vnd.adobe.photoshop': 'psd', 'image/webp': 'webp', 'image/x-icns': 'icns', 'image/x-icon': 'ico', 'image/x-ms-bmp': 'bmp', 'image/x-pcx': 'pcx', 'image/x-tga': 'tga', 'inode/x-empty': 'empty', 'message/rfc822': 'eml', 'text/calendar': 'ics', 'text/javascript': 'js', 'text/json': 'json', 'text/PGP': 'pgp', 'text/rtf': 'rtf', 'text/rss': 'rss', 'text/troff': 'troff', 'text/v-card': 'vcf', 'text/vcard': 'vcf', 'text/x-asm': 'asm', 'text/x-c': 'c', 'text/x-c++': 'cpp', 'text/x-diff': 'diff', 'text/x-java': 'java', 'text/x-lua': 'lua', 'text/x-m4': 'm4', 'text/x-makefile': 'make', 'text/x-msdos-batch': 'bat', 'text/x-pascal': 'pas', 'text/x-perl': 'pl', 'text/x-php': 'php', 'text/x-python': 'py', 'text/x-ruby': 'rb', 'text/x-shellscript': 'sh', 'text/x-tex': 'tex', 'video/3gpp': '3g2', 'video/mp4': 'mp4', 'video/mpeg': 'mpg', 'video/quicktime': 'mov', 'video/x-flv': 'flv', 'video/x-ms-asf': 'asf', 'video/x-msvideo': 'avi' } #Notes: # 'application/msword': 'doc' #Could also be .dot # 'application/pgp': 'gpg' #Could also be .asc or .pgp # 'application/vnd.ms-excel': 'xls' #Could also be .xlt or .xla # 'application/vnd.ms-powerpoint'): 'ppt' #Could also be .pot, .pps, or .ppa # 'application/x-dosexec'): 'exe' #Should one of these be .com? # 'application/x-gzip'): 'gz' #Note - this catches .tgz as well # 'application/x-executable'): 'exe' #Should one of these be .com? # 'text/PGP'): 'pgp' #Could also be .gpg # 'text/x-pascal'): 'pas' #Lots of these come back for text files. #Default extension to use, but if found in this list check against the pri and sec overrides list for overrides mime_check_overrides = { 'application/octet-stream': 'bin', 'application/xml': 'xml', 'audio/x-ape': 'ape', 'text/html': 'htm', 'text/plain': 'txt', 'text/xml': 'xml' } #If a file's mime-type doesn't correctly identify the extension, find a string that #better identifies this file and the extension you feel it should have and place it here. sec_overrides = {'new ActiveXObject(': 'js', '("WScript.Shell")': 'js', '("ADODB.Stream")': 'js', '("Scripting.FileSystemObject")': 'js', 'document.writeln("': 'js', 'WScript.CreateObject(': 'js', 'WScript.Echo("': 'js', "