WcXcsdZddlZddlZddlZddlZ ddlmZ ddl Z gdZ gdZ da daGddZdd Zdd Zdd Zdd ZddZdZdZedZedkr edSdS#e$rdZY\wxYw#e$rdZ YdwxYw)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.typesFcsdeZdZdZddZddZddZddZddZdd 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. Tcsts ttj|_t j|_iif|_iif|_tjD]\}}|j||dtjD]\}}|j||d|D]}|j||dSNTF)rr _encodings_map_defaultZcopyr _suffix_map_defaultr r types_map_inv_types_map_defaultZitemsr_common_types_defaultread)selfZ filenamesstrictexttypeZnames "/usr/lib64/python3.12/mimetypes.py__init__zMimeTypes.__init__Hsv FF388:-224b "X-335 + +KS$ MM$T * * *0668 , ,KS$ MM$U + + + $ $D IIdF # # # $ $cs||j||<|j|j|g}||vr|j|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)r rZ setdefaultappend)rrrrZexts rrzMimeTypes.add_typeVsY'+vs#!!&)44T2> d?? KK     ?rcsZtj|}tjj |\}}|dkrM|j d}|dkrdS|j dd|}|dkr|d|}n|d|}d|vsd|vrd }|dfSt j|\}}|jx} |jvrMt j||j| z\}}|jx} |jvrM||jvr-|j|} t j|\}}nd} |j}|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. Zdataz,r)NNz;Nz=z/ text/plainTF) osZfspathurllibZparseZ _splittypeZfind posixpathZsplitextlowerr r r ) rurlrZschemeZcommaZsemirZbaserZ ext_lowerencodingr s rrzMimeTypes.guess_typegs&iinll--c2  V  HHSMEqyy!z88CE*Dqyy5Dz6E{d{{coo#: &&s+ cIIK'yDOO;;!**4$//)2L+LMID# IIK'yDOO;; $$$ $ $))#.H!**40ID##HiikNN4( )  S>8+ + V> !NN5) )  S>8+ +> !rcs|j}t|jdj|g}|s>|jdj|gD]}||vs|j ||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%listrZgetr)rrr extensionsrr rrzMimeTypes.guess_all_extensionsszz|$,,T266tR@A v))%044T2> + +j((%%c***rcs@|j||}|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)rrrr) rrzMimeTypes.guess_extensions*..tV< z4!}rcsxt|d5}|j||ddddS#1swYdSxYw)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-8r'N)openreadfp)rZfilenamerfpr*rrzMimeTypes.reads(W - - $ KKF # # $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s/9cs |j}|sdS|j}tt|D]}||ddks||d=|s^|d|dd}}|D]}|j |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. rz#N.)ZreadlineZsplitZrangeZlenr) rr/rZlineZwordsirZsuffixesZsuffs rr.zMimeTypes.readfps;;=D4JJLE3u:&  8A;#%%abb 5"1XuQRy(D  8 8 dC$J777rcsts tsdSj}|rfd}trt|dStrj|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. Ncs,j||dS)NT)r)rrr rzz1MimeTypes.read_windows_registry..stS$)Gr)r_winregr_read_windows_registry)rrrs` rread_windows_registryzMimeTypes.read_windows_registrysl0/ F== 6GGGGH , + ,X 6 6 6 6 W  ' ' 1 1 1 1Wrcsd}tjtjd5}||D]} tj||5}|jds ddd:tj|d\}}|tj kr dddu|||ddd ddddS#1swYxYw#t $rYwxYw#1swYdSxYw)Nc3s~Kd} tj||}d|vr| |dz }(#t$rYdSwxYw)NrTzr0)r4ZEnumKeyOSError)Zmimedbr2Zctype r enum_typesz4MimeTypes._read_windows_registry..enum_typessmA$#OOFA6E5((# QEEs . <<r1z Content Type)r4ZOpenKeyZHKEY_CLASSES_ROOTZ startswithZ QueryValueExZREG_SZr7)Zclsrr9ZhkcrZ subkeynameZsubkeyZmimetypeZdatatypes rr5z MimeTypes._read_windows_registrys   __W66 ; t(j.     z: 7f)44S99$ 7 7 7 7 7 7 .5-A-A"N.4*(#w~~55$ 7 7 7 7 7 7!:66 7 7 7 7 7         7 7 7 7 7 7 7 7 7H          sj C&CC % C.C&/1C  C)C&* C 4 C=C& C C C# C&"C##C&&C0N)rTT)__name__Z __module__Z __qualname____doc__rrrrrrr.r6Z classmethodr5rrrrr@s $ $ $ $";";";";"z&$ $ $ $ $8888.2222,rrTcXt ttj||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 rrrs!$ {  >>#v &&rcr>)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. )r?r rrrr@rrr6s# {   # #D& 11rcr>)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. )r?r rrAr@rrrGs# {    tV ,,rcsZt ttj|||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. )r?r r)rrrr8rrrWs# {  <<c6 **rcsda|t=t}|j|t}ntt |z}nt}|D]6}t jj|s%|j|8|ja |ja |jda |jda |adSr)rr?rr6rr(r"ZpathZisfilerr r r r)Zfilesdbfiler8rr r hsF } [   "" =EEe,EE  77>>$   GGDMMM$$MJ T"I<<&L CCCrcs t|d}|5t}|j|d|jdcdddS#t$rYdSwxYw#1swYdSxYw)Nr+r,T)r-r7rr.r )rCZfrBr8rr r s  ( ( "" [ !T||D!""""""" tt""""""""""sA1A  AA A*csdddddddxaadddd 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.txzZgzipZcompressZbzip2ZxzZbr)z.gzz.Zz.bz2z.xzz.brz.jsztext/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.txtr!z.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.midrDz.pictz.pctz.picz.webpz.xul)r rr rr rrrrrr_default_mime_typesrEs6  ( (  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(((rcs ddl}d d fd } |jtjdddgd\}}d}d}D]!\}}|dvr |d|d vrd}|d vs d}#D]c} |r-t | |} | st d | $t | 2t | |\} } | st d | Tt d | d | edS#|j$r}|d|Yd}~d}~wwxYw)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. r:csnt|r t|tj|dSN)printsysZexit)ZcodemsgUSAGEr3rusagez_main..usagehs* e 3c  rr0Zhle)ZhelpZlenient extension)z-hz--help)z-lz --lenient)z-ez --extensionz I don't know anything about typeztype:z encoding:)r:)getoptrHZargvZerrorrrGr) rMrKZoptsZargsrIrrLZoptZargZgtypeZguessr'rJs @r_mainrNYs~MMM E ]]388AB<#C#C#CE d FIS " " " E!HHH ' ' 'FF ) ) )II?? 9#E62E5% BEJJJ,,,(7OE85% BEJJJ X>>>?? << a s+C C/ C**C/Z__main__r;rF)r=r"rHr$Z urllib.parser#Z_winapirZ ImportErrorZwinregr4Z__all__rrr?rrrrrr r rErNr<rrrrOs2 ,888888         ]]]]]]]~''''.2222"---- ++++"    8"""D D D N+?+?+?\ z EGGGGM,,,'+$$$, GGGs"A-A:-A76A7:BB