fYdZddlZddlZddlZddlZ ddlmZn #e$rdZYnwxYw ddl Z n #e$rdZ YnwxYwgdZ gdZ da daGddZdd Zdd Zdd Zdd ZddZdZdZedZedkr edSdS)aGuess the MIME type of a file. This module defines two useful functions: guess_type(url, strict=True) -- guess the MIME type and encoding of a URL. guess_extension(type, strict=True) -- guess the extension for a given MIME type. It also contains the following, for tuning the behavior: Data: knownfiles -- list of files to parse inited -- flag set when init() has been called suffix_map -- dictionary mapping suffixes to suffixes encodings_map -- dictionary mapping suffixes to encodings types_map -- dictionary mapping suffixes to types Functions: init([files]) -- parse a list of files, default knownfiles (on Windows, the default values are taken from the registry) read_mime_types(file) -- parse one file, return a dictionary or None N) _mimetypes_read_windows_registry) knownfilesinited MimeTypes guess_typeguess_all_extensionsguess_extensionadd_typeinitread_mime_types suffix_map encodings_map types_map common_types) z/etc/mime.typesz/etc/httpd/mime.typesz/etc/httpd/conf/mime.typesz/etc/apache/mime.typesz/etc/apache2/mime.types$/usr/local/etc/httpd/conf/mime.typesz"/usr/local/lib/netscape/mime.typesrz/usr/local/etc/mime.typesFcheZdZdZddZddZddZddZddZdd Z dd Z dd Z e d Z d S)rzMIME-types datastore. This datastore can handle information from mime.types-style files and supports basic determination of MIME type from a filename or URL, and can guess a reasonable extension given a MIME type. Tctstt|_t |_iif|_iif|_t D]\}}| ||dt D]\}}| ||d|D]}| ||dSNTF)rr _encodings_map_defaultcopyr_suffix_map_defaultr r types_map_inv_types_map_defaultitemsr _common_types_defaultread)self filenamesstrictexttypenames 0/opt/alt/python311/lib64/python3.11/mimetypes.py__init__zMimeTypes.__init__Hs  FFF388::-2244b "X-3355 + +KS$ MM$T * * * *06688 , ,KS$ MM$U + + + + $ $D IIdF # # # # $ $c||j||<|j||g}||vr||dSdS)aAdd a mapping between a type and an extension. When the extension is already known, the new type will replace the old one. When the type is already known the extension will be added to the list of known extensions. If strict is true, information will be added to list of standard types, else to the list of non-standard types. N)rr setdefaultappend)rr"r!r extss r$r zMimeTypes.add_typeVsZ'+vs#!&)44T2>> d?? KK      ?r&ctj|}tj|}|jr't |jdkr|j}|j}n'd}tj|d}|dkr]| d}|dkrdS| dd|}|dkr |d|}n |d|}d|vsd |vrd }|dfStj |\}} | x} |j vrBtj ||j | z\}} | x} |j vB| |jvr%|j| } tj |\}} nd} | } |jd } | | vr | | | fS|rd| fS|jd } | | vr | | | fSd| fS) aUGuess the type of a file which is either a URL or a path-like object. Return value is a tuple (type, encoding) where type is None if the type can't be guessed (no or unknown suffix) or a string of the form type/subtype, usable for a MIME Content-type header; and encoding is None for no encoding or the name of the program used to encode (e.g. compress or gzip). The mappings are table driven. Encoding suffixes are case sensitive; type suffixes are first tried case sensitive, then case insensitive. The suffixes .tgz, .taz and .tz (case sensitive!) are all mapped to '.tar.gz'. (This is table-driven too, using the dictionary suffix_map.) Optional `strict' argument when False adds a bunch of commonly found, but non-standard types. Ndata,r)NN;=/ text/plainTF)osfspathurllibparseurlparseschemelenpath splitdrivefind posixpathsplitextlowerr rr) rurlr pr8commasemir"baser! ext_lowerencodingrs r$rzMimeTypes.guess_typegs &inn L ! !# & & 8 -AH ))XF&CCF'$$S))!,C V  HHSMMEqyy!z88CE**Dqyy5D5z6E6{d{{coo#: &s++ cIIKK'yDO;;!*4$/)2L+LMMID# IIKK'yDO;; $$ $ $)#.H!*400ID##HiikkN4( )  S>8+ +  "> !N5) )  S>8+ +> !r&c|}t|jd|g}|s=|jd|gD]}||vr|||S)aGuess the extensions for a file based on its MIME type. Return value is a list of strings giving the possible filename extensions, including the leading dot ('.'). The extension is not guaranteed to have been associated with any particular data stream, but would be mapped to the MIME type `type' by guess_type(). Optional `strict' argument when false adds a bunch of commonly found, but non-standard types. TF)r?listrgetr))rr"r extensionsr!s r$rzMimeTypes.guess_all_extensionsszz||$,T266tR@@AA  +)%044T2>> + +j((%%c***r&cF|||}|sdS|dS)a Guess the extension for a file based on its MIME type. Return value is a string giving a filename extension, including the leading dot ('.'). The extension is not guaranteed to have been associated with any particular data stream, but would be mapped to the MIME type `type' by guess_type(). If no extension can be guessed for `type', None is returned. Optional `strict' argument when false adds a bunch of commonly found, but non-standard types. Nr)r)rr"r rJs r$r zMimeTypes.guess_extensions0..tV<<  4!}r&ct|d5}|||ddddS#1swxYwYdS)z Read a single mime.types-format file, specified by pathname. If strict is true, information will be added to list of standard types, else to the list of non-standard types. utf-8rFN)openreadfp)rfilenamer fps r$rzMimeTypes.reads(W - - - $ KKF # # # $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s 6::c6 |}|sdS|}tt|D]}||ddkr||d=n|sh|d|dd}}|D]}||d|z|)z Read a single mime.types-format file. If strict is true, information will be added to list of standard types, else to the list of non-standard types. r,r#N.)readlinesplitranger9r ) rrRr linewordsir"suffixessuffs r$rPzMimeTypes.readfps 8;;==D JJLLE3u::&&  8A;#%%abb E& "1XuQRRy(D  8 8 dC$J7777 8r&cts tsdSj}|rfd}trt|dStr|dSdS)z Load the MIME types database from Windows registry. If strict is true, information will be added to list of standard types, else to the list of non-standard types. Nc2||dS)NT)r )r"r!rs r$z1MimeTypes.read_windows_registry..stS$)G)Gr&)r_winregr _read_windows_registry)rr r s` r$read_windows_registryzMimeTypes.read_windows_registrys0   F=  HGGGGH , 2 ,X 6 6 6 6 6  2  ' ' 1 1 1 1 1 2 2r&cd}tjtjd5}||D]} tj||5}|ds ddd;tj|d\}}|tjkr dddp|||dddn #1swxYwY#t $rYwxYw ddddS#1swxYwYdS)Nc3xKd} tj||}d|vr|Vn#t$rYdSwxYw|dz }6)NrTr,)raEnumKeyOSError)mimedbr[ctypes r$ enum_typesz4MimeTypes._read_windows_registry..enum_types sqA $#OFA66E5((# EE Q s % 33rUz Content Type)raOpenKeyHKEY_CLASSES_ROOT startswith QueryValueExREG_SZrh)clsr rkhkcr subkeynamesubkeymimetypedatatypes r$rbz MimeTypes._read_windows_registrys   _W6 ; ; t(j..     z:: 7f)44S99%$ 7 7 7 7 7 7 7 .5-A"N.4.4*(#w~55$ 7 7 7 7 7 7 7!:666 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7H                   s|C!CB7 C)C!*)B7 CC! B7+ C7B; ;C>B; ?CC! C C!CC!!C%(C%N)rTT)__name__ __module__ __qualname____doc__r%r rrr rrPrc classmethodrbrr&r$rr@s $ $ $ $"A"A"A"A"F&$ $ $ $ $8888.2222,[r&rTcbttt||S)aGuess the type of a file based on its URL. Return value is a tuple (type, encoding) where type is None if the type can't be guessed (no or unknown suffix) or a string of the form type/subtype, usable for a MIME Content-type header; and encoding is None for no encoding or the name of the program used to encode (e.g. compress or gzip). The mappings are table driven. Encoding suffixes are case sensitive; type suffixes are first tried case sensitive, then case insensitive. The suffixes .tgz, .taz and .tz (case sensitive!) are all mapped to ".tar.gz". (This is table-driven too, using the dictionary suffix_map). Optional `strict' argument when false adds a bunch of commonly found, but non-standard types. )_dbr r)r@r s r$rr%s&$ {  >>#v & &&r&cbttt||S)aGuess the extensions for a file based on its MIME type. Return value is a list of strings giving the possible filename extensions, including the leading dot ('.'). The extension is not guaranteed to have been associated with any particular data stream, but would be mapped to the MIME type `type' by guess_type(). If no extension can be guessed for `type', None is returned. Optional `strict' argument when false adds a bunch of commonly found, but non-standard types. )rr rr"r s r$rr<s( {   # #D& 1 11r&cbttt||S)aGuess the extension for a file based on its MIME type. Return value is a string giving a filename extension, including the leading dot ('.'). The extension is not guaranteed to have been associated with any particular data stream, but would be mapped to the MIME type `type' by guess_type(). If no extension can be guessed for `type', None is returned. Optional `strict' argument when false adds a bunch of commonly found, but non-standard types. )rr r rs r$r r Ms( {    tV , ,,r&cdttt|||S)aiAdd a mapping between a type and an extension. When the extension is already known, the new type will replace the old one. When the type is already known the extension will be added to the list of known extensions. If strict is true, information will be added to list of standard types, else to the list of non-standard types. )rr r )r"r!r s r$r r ]s( {  <<c6 * **r&cxda|tDt}||t}ntt |z}nt}|D]6}t j|r| |7|j a |j a |j da |j da |adSr)rrrrcrrHr3r:isfilerrr rr)filesdbfiles r$r r nsF } [[   """ =EEe,EE  7>>$    GGDMMM$MJ T"I<&L CCCr&c t|d}n#t$rYdSwxYw|5t}||d|jdcdddS#1swxYwYdS)NrMrNT)rOrhrrPr)rfrs r$r r s  ( ( ( tt "" [[ !T|D!""""""""""""""""""s ""1A%%A),A)cdddddddxaadddd d d xaaid d dd ddddddddddddddddddddddd dd!dd"dd#d$id%d&d'd(d)d*d+d*d,d*d-d.d/d0d1d0d2d3d4d3d5d6d7d6d8d6d9d6d:d6d;d<d=d>id?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdPdRdSdTdSdUdVdWdXdYdXdZd[d\d]id^d_d`dadbdcdddedfdgdhdidjdkdldkdmdndodndpdndqdrdsdtdudvdwdxdydzd{d|id}d|d~d|dd|ddddddddddddddddddddddddddddiddddddddddddddddddddddddddddddddddiddddddddddddddddddÓddœddǓddɓddɓddɓddɓddΓddГiddғddғddՓddדddדddדddדddדddדddדddߓdddddddddddddddddddddddddd xaadddddddddd xaadS)Nz.svg.gzz.tar.gzz.tar.bz2z.tar.xz)z.svgzz.tgzz.tazz.tzz.tbz2z.txzgzipcompressbzip2xzbr)z.gzz.Zz.bz2z.xzz.brz.jszapplication/javascriptz.mjsz.jsonzapplication/jsonz .webmanifestzapplication/manifest+jsonz.doczapplication/mswordz.dotz.wizz.nqzapplication/n-quadsz.ntzapplication/n-triplesz.binzapplication/octet-streamz.az.dllz.exez.oz.objz.soz.odazapplication/odaz.pdfzapplication/pdfz.p7czapplication/pkcs7-mimez.pszapplication/postscriptz.aiz.epsz.trigzapplication/trigz.m3uzapplication/vnd.apple.mpegurlz.m3u8z.xlszapplication/vnd.ms-excelz.xlbz.pptzapplication/vnd.ms-powerpointz.potz.ppaz.ppsz.pwzz.wasmzapplication/wasmz.bcpiozapplication/x-bcpioz.cpiozapplication/x-cpioz.cshzapplication/x-cshz.dvizapplication/x-dviz.gtarzapplication/x-gtarz.hdfzapplication/x-hdfz.h5zapplication/x-hdf5z.latexzapplication/x-latexz.mifzapplication/x-mifz.cdfzapplication/x-netcdfz.ncz.p12zapplication/x-pkcs12z.pfxz.ramzapplication/x-pn-realaudioz.pyczapplication/x-python-codez.pyoz.shzapplication/x-shz.sharzapplication/x-sharz.swfzapplication/x-shockwave-flashz.sv4cpiozapplication/x-sv4cpioz.sv4crczapplication/x-sv4crcz.tarzapplication/x-tarz.tclzapplication/x-tclz.texzapplication/x-texz.texizapplication/x-texinfoz.texinfoz.roffzapplication/x-troffz.tz.trz.manzapplication/x-troff-manz.mezapplication/x-troff-mez.mszapplication/x-troff-msz.ustarzapplication/x-ustarz.srczapplication/x-wais-sourcez.xslzapplication/xmlz.rdfz.wsdlz.xpdlz.zipzapplication/zipz.3gpz audio/3gppz.3gppz.3g2z audio/3gpp2z.3gpp2z.aacz audio/aacz.adtsz.loasz.assz.auz audio/basicz.sndz.mp3z audio/mpegz.mp2z.opusz audio/opusz.aifz audio/x-aiffz.aifcz.aiffz.razaudio/x-pn-realaudioz.wavz audio/x-wavz.avifz image/avifz.bmpz image/bmpz.gifz image/gifz.iefz image/ief.jpgz image/jpegz.jpez.jpegz.heicz image/heicz.heifz image/heifz.pngz image/pngz.svgz image/svg+xmlz.tiffz image/tiffz.tifz.icozimage/vnd.microsoft.iconz.raszimage/x-cmu-rasterz.pnmzimage/x-portable-anymapz.pbmzimage/x-portable-bitmapz.pgmzimage/x-portable-graymapz.ppmzimage/x-portable-pixmapz.rgbz image/x-rgbz.xbmzimage/x-xbitmapz.xpmzimage/x-xpixmapz.xwdzimage/x-xwindowdumpz.emlzmessage/rfc822z.mhtz.mhtmlz.nwsz.cssztext/cssz.csvztext/csvz.htmlz text/htmlz.htmz.n3ztext/n3z.txtr2z.batz.cz.hz.kshz.plz.srtz.rtxz text/richtextz.tsvztext/tab-separated-valuesz.vttztext/vttz.pyz text/x-pythonz.etxz text/x-setextz.sgmz text/x-sgmlz.sgmlz text/x-vcardztext/xmlz video/mp4z video/mpegzvideo/quicktimez video/webmzvideo/x-msvideozvideo/x-sgi-movie) z.vcfz.xmlz.mp4z.mpegz.m1vz.mpaz.mpez.mpgz.movz.qtz.webmz.aviz.moviezapplication/rtfz audio/midiz image/jpgz image/pictz image/webpztext/xul) z.rtfz.midiz.midrz.pictz.pctz.picz.webpz.xul)r rrrrrrrrr&r$_default_mime_typesrs6  ( (  J$ . .  M*V&  ,V& ,V&  &V&  3 V& ( V& ( V&  (V&  )V&  +V&  .V&  .V&  .V&  .V&  .V&  .V& .!V& " %#V& V& $ %%V& & ,'V& ( ,)V& * ,+V& , ,-V& . &/V& 0 31V& 2 33V& 4 .5V& 6 .7V& 8 39V& : 3;V& < 3=V& > 3?V& @ 3AV& B &CV& D )EV& V& V& F (GV& H 'IV& J 'KV& L (MV& N 'OV& P (QV& R )SV& T 'UV& V *WV& X *YV& Z *[V& \ *]V& ^ 0_V& ` /aV& b /cV& d &eV& f (gV& V& V& h 3iV& j +kV& l *mV& n 'oV& p 'qV& r 'sV& t +uV& v +wV& x )yV& z ){V& | )}V& ~ -V& @ ,AV& B ,CV& D )EV& F /GV& H %IV& V& V& J %KV& L %MV& N %OV& P %QV& R LSV& T LUV& V MWV& X MYV& Z K[V& \ K]V& ^ K_V& ` KaV& b McV& d MeV& f LgV& h LiV& j LkV& V& V& l NmV& n NoV& p NqV& r *sV& t MuV& v LwV& x KyV& z K{V& | K}V& ~ LV& @ LAV& B LCV& D LEV& F LGV& H KIV& J OKV& L LMV& V& V& N LOV& P .QV& R (SV& T -UV& V -WV& X .YV& Z -[V& \ M]V& ^ %_V& ` %aV& b )cV& d $eV& f $gV& h $iV& j $kV& l JmV& n JoV& V& V& p KqV& r KsV& t IuV& v LwV& x LyV& z L{V& | L}V& ~ LV& @ LAV& B LCV& D OEV& F /GV& H JIV& J OKV& L OMV& N MOV& P MQV& V& R#     %% %'kV& V& V& V I"z# , ,  L(((r&c ddl}d d fd } |tjdddgd\}}n##|j$r}|d|Yd}~nd}~wwxYwd}d}|D]"\}}|dvr |d|d vrd}|d vrd}#|D]o} |r3t | |} | st d | 't | 7t | |\} } | st d | ]t d | d | pdS)Nra4Usage: mimetypes.py [options] type Options: --help / -h -- print this message and exit --lenient / -l -- additionally search of some common, but non-standard types. --extension / -e -- guess extension instead of type More than one type argument may be given. rlcpt|rt|tj|dSN)printsysexit)codemsgUSAGEs r$usagez_main..usagens/ e c  r&r,hle)helplenient extension)z-hz--help)z-lz --lenient)z-ez --extensionz I don't know anything about typeztype:z encoding:)rl)getoptrargverrorr rr) rroptsargsrr roptarggtypeguessrFrs @r$_mainr_sMMM E ]]38ABB<#C#C#CEE dd < a FIS " " " E!HHHH ' ' 'FF ) ) )I??  ?#E622E % BEJJJJ,,,,(77OE8 ?% BEJJJJ X>>>>??s.> A AA__main__rxr)r|r3rr= urllib.parser5_winapir ImportErrorwinregra__all__rrrrrrr r r r rrryrr&r$rs2 ,8888888,,,'+$$$,GGG         ccccccccJ''''.2222"---- ++++"    8"""D D D N+?+?+?\ z EGGGGGs%%.88