def guess_extension(content_type):
    """
    Python's `mimetypes.guess_extension` is no use because it simply returns
    the first of an unordered set. We use the same set of media types here,
    but take a reasonable preference on what extension to map to.
    """
    return {'application/javascript': '.js', 'application/msword': '.doc',
        'application/octet-stream': '.bin', 'application/oda': '.oda',
        'application/pdf': '.pdf', 'application/pkcs7-mime': '.p7c',
        'application/postscript': '.ps', 'application/vnd.apple.mpegurl':
        '.m3u', 'application/vnd.ms-excel': '.xls',
        'application/vnd.ms-powerpoint': '.ppt', 'application/x-bcpio':
        '.bcpio', 'application/x-cpio': '.cpio', 'application/x-csh':
        '.csh', 'application/x-dvi': '.dvi', 'application/x-gtar': '.gtar',
        'application/x-hdf': '.hdf', 'application/x-latex': '.latex',
        'application/x-mif': '.mif', 'application/x-netcdf': '.nc',
        'application/x-pkcs12': '.p12', 'application/x-pn-realaudio':
        '.ram', 'application/x-python-code': '.pyc', 'application/x-sh':
        '.sh', 'application/x-shar': '.shar',
        'application/x-shockwave-flash': '.swf', 'application/x-sv4cpio':
        '.sv4cpio', 'application/x-sv4crc': '.sv4crc', 'application/x-tar':
        '.tar', 'application/x-tcl': '.tcl', 'application/x-tex': '.tex',
        'application/x-texinfo': '.texinfo', 'application/x-troff': '.tr',
        'application/x-troff-man': '.man', 'application/x-troff-me': '.me',
        'application/x-troff-ms': '.ms', 'application/x-ustar': '.ustar',
        'application/x-wais-source': '.src', 'application/xml': '.xml',
        'application/zip': '.zip', 'audio/basic': '.au', 'audio/mpeg':
        '.mp3', 'audio/x-aiff': '.aif', 'audio/x-pn-realaudio': '.ra',
        'audio/x-wav': '.wav', 'image/gif': '.gif', 'image/ief': '.ief',
        'image/jpeg': '.jpe', 'image/png': '.png', 'image/svg+xml': '.svg',
        'image/tiff': '.tiff', 'image/vnd.microsoft.icon': '.ico',
        'image/x-cmu-raster': '.ras', 'image/x-ms-bmp': '.bmp',
        'image/x-portable-anymap': '.pnm', 'image/x-portable-bitmap':
        '.pbm', 'image/x-portable-graymap': '.pgm',
        'image/x-portable-pixmap': '.ppm', 'image/x-rgb': '.rgb',
        'image/x-xbitmap': '.xbm', 'image/x-xpixmap': '.xpm',
        'image/x-xwindowdump': '.xwd', 'message/rfc822': '.eml', 'text/css':
        '.css', 'text/csv': '.csv', 'text/html': '.html', 'text/plain':
        '.txt', 'text/richtext': '.rtx', 'text/tab-separated-values':
        '.tsv', 'text/x-python': '.py', 'text/x-setext': '.etx',
        'text/x-sgml': '.sgml', 'text/x-vcard': '.vcf', 'text/xml': '.xml',
        'video/mp4': '.mp4', 'video/mpeg': '.mpeg', 'video/quicktime':
        '.mov', 'video/webm': '.webm', 'video/x-msvideo': '.avi',
        'video/x-sgi-movie': '.movie'}.get(content_type, '')
