WcXdZddlZddlZddlZddlZ 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.typesFcdeZdZdZddZddZddZddZddZdd 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. Tcts ttj|_t j|_iif|_iif|_tjD]\}}|j||dtjD]\}}|j||d|D]}|j||dSNTF)rr _encodings_map_defaultcopyr_suffix_map_defaultr r types_map_inv_types_map_defaultitemsr _common_types_defaultread)self filenamesstrictexttypenames "/usr/lib64/python3.12/mimetypes.py__init__zMimeTypes.__init__Hsv FF388:-224b "X-335 + +KS$ MM$T * * *0668 , ,KS$ MM$U + + + $ $D IIdF # # # $ $c||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)rr setdefaultappend)rr"r!r extss r$r zMimeTypes.add_typeVsY'+vs#!!&)44T2> d?? KK     ?r&cZtj|}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. data,r)NN;N=/ text/plainTF) osfspathurllibparse _splittypefind posixpathsplitextlowerr rr) rurlr schemecommasemir"baser! ext_lowerencodingrs r$rzMimeTypes.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+ +> !r&c|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:listrgetr))rr"r extensionsr!s r$rzMimeTypes.guess_all_extensionsszz|$,,T266tR@A v))%044T2> + +j((%%c***r&c@|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)rr"r rEs r$r zMimeTypes.guess_extensions*..tV< z4!}r&cxt|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-8rAN)openreadfp)rfilenamer fps r$rzMimeTypes.reads(W - - $ KKF # # $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s/9c |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. r#N.)readlinesplitrangelenr ) rrMr linewordsir"suffixessuffs r$rKzMimeTypes.readfps;;=D4JJLE3u:&  8A;#%%abb 5"1XuQRy(D  8 8 dC$J777r&cts 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. Nc,j||dS)NT)r )r"r!rs r$z1MimeTypes.read_windows_registry..stS$)Gr&)r_winregr _read_windows_registry)rr r s` r$read_windows_registryzMimeTypes.read_windows_registrysl0/ F== 6GGGGH , + ,X 6 6 6 6 W  ' ' 1 1 1 1Wr&cd}tjtjd5}||D]} tj||5}|jds ddd:tj|d\}}|tj kr dddu|||ddd ddddS#1swYxYw#t $rYwxYw#1swYdSxYw)Nc3~Kd} tj||}d|vr| |dz }(#t$rYdSwxYw)NrTrO)r^EnumKeyOSError)mimedbrXctypes r$ enum_typesz4MimeTypes._read_windows_registry..enum_typessmA$#OOFA6E5((# QEEs . <<rQz Content Type)r^OpenKeyHKEY_CLASSES_ROOT startswith QueryValueExREG_SZre)clsr rhhkcr subkeynamesubkeymimetypedatatypes r$r_z 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__ __module__ __qualname____doc__r%r rrr rrKr` classmethodr_rr&r$rr@s $ $ $ $";";";";"z&$ $ $ $ $8888.2222,r&rTcXt 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 s r$rrs!$ {  >>#v &&r&cXt ttj||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. )r|r rr"r s r$rr6s# {   # #D& 11r&cXt ttj||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. )r|r r r~s r$r r Gs# {    tV ,,r&cZt 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 )r"r!r s r$r r Ws# {  <<c6 **r&cda|t=t}|j|t}ntt |z}nt}|D]6}t jj|s%|j|8|ja |ja |jda |jda |adSr)rr|rr`rrCr2pathisfilerrr rr)filesdbfiles r$r r hsF } [   "" =EEe,EE  77>>$   GGDMMM$$MJ T"I<<&L CCCr&c t|d}|5t}|j|d|jdcdddS#t$rYdSwxYw#1swYdSxYw)NrHrIT)rJrerrKr)rfrs r$r r s  ( ( "" [ !T||D!""""""" tt""""""""""sA1A  AA 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.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.txtr1z.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 } |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. ricnt|r t|tj|dSN)printsysexit)codemsgUSAGEs r$usagez_main..usagehs* e 3c  r&rOhle)helplenient extension)z-hz--help)z-lz --lenient)z-ez --extensionz I don't know anything about typeztype:z encoding:)ri)getoptrargverrorr rr) rroptsargsrr roptarggtypeguessrArs @r$_mainrYs~MMM E ]]388AB<#C#C#CE d FIS " " " E!HHH ' ' 'FF ) ) )II?? 9#E62E5% BEJJJ,,,(7OE85% BEJJJ X>>>?? << a s+C C/ C**C/__main__rur)ryr2rr8 urllib.parser4_winapir ImportErrorwinregr^__all__rrr|rrrr r r r rrrvrr&r$rs2 ,888888         ]]]]]]]~''''.2222"---- ++++"    8"""D D D N+?+?+?\ z EGGGGM,,,'+$$$, GGGs"A-A:-A76A7:BB