grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026 ”qcoQã@s«dZddlZddlZddlZddlZyddlZWnek r`dZYnXddddddgZ d d d d d ddddg Z da da Gdd„dƒZ ddd„Zddd„Zddd„Zddd„Zddd„Zdd„Zdd„Zeƒedkr§ddlZdZdd d!„Zy5ejejd"d…d#d$d%d&gƒ\ZZWn5ejk r¼Zzed"eƒWYddZ[XnXd"ZdZxTeD]L\Z Z!e d0krõedƒqÐe d1kr dZqÐe d2krÐd"ZqÐWx„eD]|Z"ereee"eƒZ#e#sXe$d-e"ƒq£e$e#ƒq'ee"eƒ\Z#Z%e#s�e$d-e"ƒq'e$d.e#d/e%ƒq'WdS)3aìGuess 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Ú guess_typeÚguess_extensionÚguess_all_extensionsÚadd_typeÚread_mime_typesÚinitz/etc/mime.typesz/etc/httpd/mime.typesz/etc/httpd/conf/mime.typesz/etc/apache/mime.typesz/etc/apache2/mime.typesz$/usr/local/etc/httpd/conf/mime.typesz"/usr/local/lib/netscape/mime.typesz/usr/local/etc/mime.typesFc@s‘eZdZdZfddd„Zddd„Zddd„Zdd d „Zdd d „Zdd d„Z ddd„Z ddd„Z dS)Ú MimeTypeszçMIME-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. TcCsÎts tƒtjƒ|_tjƒ|_iif|_iif|_x-tjƒD]\}}|j||dƒqVWx-t jƒD]\}}|j||dƒq†Wx|D]}|j ||ƒq°WdS)NTF) ÚinitedrÚ encodings_mapÚcopyÚ suffix_mapÚ types_mapÚ types_map_invÚitemsrÚ common_typesÚread)ÚselfÚ filenamesÚstrictÚextÚtypeÚname©rú./opt/alt/python35/lib64/python3.5/mimetypes.pyÚ__init__@s zMimeTypes.__init__cCsG||j||<|j|j|gƒ}||krC|j|ƒdS)a‰Add 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 rÚ setdefaultÚappend)rrrrZextsrrrrNs  zMimeTypes.add_typec Csìtjj|ƒ\}}|dkr¯|jdƒ}|dkrCd S|jdd|ƒ}|dkrw|d|…}n|d|…}d|ksŸd|kr¥d}|dfStj|ƒ\}}x3||jkrùtj||j|ƒ\}}qÇW||jkr.|j|} tj|ƒ\}}nd} |jd } || kr[| || fS|j ƒ| kr�| |j ƒ| fS|r‘d| fS|jd } || kr¸| || fS|j ƒ| krÞ| |j ƒ| fSd| fSdS) a:Guess 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. Údataú,rNú;ú=ú/z text/plainTF)NN) ÚurllibÚparseZ splittypeÚfindÚ posixpathÚsplitextr r r Úlower) rÚurlrÚschemeZcommaZsemirÚbaserÚencodingr rrrr_s@    $      zMimeTypes.guess_typecCsl|jƒ}|jdj|gƒ}|shx:|jdj|gƒD]}||krE|j|ƒqEW|S)aÓGuess 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'rÚgetr)rrrÚ extensionsrrrrr�s   zMimeTypes.guess_all_extensionscCs$|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-rrrr°s zMimeTypes.guess_extensionc Cs0t|ddƒ�}|j||ƒWdQRXdS)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. r+zutf-8N)ÚopenÚreadfp)rÚfilenamerÚfprrrrÂszMimeTypes.readc Csµx®|jƒ}|sP|jƒ}x<tt|ƒƒD](}||ddkr5||d…=Pq5W|sjq|d|dd…}}x%|D]}|j|d||ƒqŒWqWdS)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éÚ.)ÚreadlineÚsplitÚrangeÚlenr) rr1rÚlineZwordsÚirÚsuffixesZsuffrrrr/Ís    zMimeTypes.readfpcCs×ts dSdd„}tjtjdƒ�¥}x›||ƒD]�}yotj||ƒ�V}|jdƒskw;tj|dƒ\}}|tjkr•w;|j|||ƒWdQRXWq;tk rÇw;Yq;Xq;WWdQRXdS)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 ssXd}xKytj||ƒ}Wntk r4PYnXd|krF|V|d7}q WdS)Nrúr3)Ú_winregZEnumKeyÚEnvironmentError)Zmimedbr:ZctyperrrÚ enum_typesñs  z3MimeTypes.read_windows_registry..enum_typesÚr4z Content Type)r=ÚOpenKeyZHKEY_CLASSES_ROOTÚ startswithZ QueryValueExZREG_SZrr>)rrr?ZhkcrZ subkeynameZsubkeyZmimetypeZdatatyperrrÚread_windows_registryäs   zMimeTypes.read_windows_registryN) Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrrr/rCrrrrr8s > rTcCs#tdkrtƒtj||ƒS)aþGuess 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. N)Ú_dbrr)r(rrrrr s cCs#tdkrtƒtj||ƒS)aýGuess 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. N)rHrr)rrrrrr$s cCs#tdkrtƒtj||ƒS)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. N)rHrr)rrrrrr5s cCs&tdkrtƒtj|||ƒ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. N)rHrr)rrrrrrrEs cCs—datƒ}|dkr1tr+|jƒt}x-|D]%}tjj|ƒr8|j|ƒq8W|j a |j a |j da |j da |a dS)NTF)r rr=rCÚ knownfilesÚosÚpathÚisfilerr r r rrH)ÚfilesÚdbÚfilerrrrVs        cCs_yt|ƒ}Wntk r(dSYnX|�)tƒ}|j|dƒ|jdSWdQRXdS)NT)r.ÚOSErrorrr/r )rOÚfrNrrrrjs   cCsˆddddddddddd d iad d d dddddiadddddddddddddddd d!d"d#dd$d%d&d d'd(d'd)d*d+d,d-d.d/d0d1d2dd3d4d5d4d6d7d8d9d:dd;d<d=dd>d?d@dAdBd dCdDdEdFdGdFdHdIdJdKdLdMdNdMdOdMdPdQdRd dSdTdUdVdWdXdYdXdZd[d\d]d^d9d_d9d`dadbdcdddedfdgdhdgdidjdkdVdldVdmdVdndVdodpdqd)drd9dsddtddudvdwdxdydzd{d|d}d~ddxd€d�d‚d dƒd„d…d†d‡dˆd‰dˆdŠd‹dŒdˆd�dˆdŽdd�dˆd�d‘d’d“d”d“d•dcd–d—d˜d™dšd›dœd�dždŸd d¡d¢d£d¤d¥d¦d¥d§d¨d©dªd«dd¬dd­d®d¯d°d±d²d³d´dµd¶d·d¡d¸d¹dºd»d¼d½d¾d¿dÀd¿dÁdÂdÃdÂdÄd¡dÅdÆdÇd dÈdÉdÊdËdÌdÍdÎdÏdÐd4dÑd�dÒdÓdÔdÕdÖd×dÖdÕdØdÙdÚd�dÛdÜdÝd�dÞdßdàdái€adOdâdãdädådädædçdèdçdédçdêdëdìdíiadS)îNz.svgzz.svg.gzz.tgzz.tar.gzz.tazz.tzz.tbz2z.tar.bz2z.txzz.tar.xzz.gzZgzipz.ZÚcompressz.bz2Zbzip2z.xzZxzz.azapplication/octet-streamz.aizapplication/postscriptz.aifz audio/x-aiffz.aifcz.aiffz.auz audio/basicz.avizvideo/x-msvideoz.batz text/plainz.bcpiozapplication/x-bcpioz.binz.bmpzimage/x-ms-bmpz.cz.cdfzapplication/x-cdfzapplication/x-netcdfz.cpiozapplication/x-cpioz.cshzapplication/x-cshz.cssztext/cssz.csvztext/csvz.dllz.doczapplication/mswordz.dotz.dvizapplication/x-dviz.emlzmessage/rfc822z.epsz.etxz text/x-setextz.exez.gifz image/gifz.gtarzapplication/x-gtarz.hz.hdfzapplication/x-hdfz.htmz text/htmlz.htmlz.icozimage/vnd.microsoft.iconz.iefz image/iefz.jpez image/jpegz.jpegz.jpgz.jszapplication/javascriptz.kshz.latexzapplication/x-latexz.m1vz video/mpegz.m3uzapplication/vnd.apple.mpegurlz.m3u8z.manzapplication/x-troff-manz.mezapplication/x-troff-mez.mhtz.mhtmlz.mifzapplication/x-mifz.movzvideo/quicktimez.moviezvideo/x-sgi-moviez.mp2z audio/mpegz.mp3z.mp4z video/mp4z.mpaz.mpez.mpegz.mpgz.mszapplication/x-troff-msz.ncz.nwsz.oz.objz.odazapplication/odaz.p12zapplication/x-pkcs12z.p7czapplication/pkcs7-mimez.pbmzimage/x-portable-bitmapz.pdfzapplication/pdfz.pfxz.pgmzimage/x-portable-graymapz.plz.pngz image/pngz.pnmzimage/x-portable-anymapz.potzapplication/vnd.ms-powerpointz.ppaz.ppmzimage/x-portable-pixmapz.ppsz.pptz.psz.pwzz.pyz text/x-pythonz.pyczapplication/x-python-codez.pyoz.qtz.razaudio/x-pn-realaudioz.ramzapplication/x-pn-realaudioz.raszimage/x-cmu-rasterz.rdfzapplication/xmlz.rgbz image/x-rgbz.roffzapplication/x-troffz.rtxz text/richtextz.sgmz text/x-sgmlz.sgmlz.shzapplication/x-shz.sharzapplication/x-sharz.sndz.soz.srczapplication/x-wais-sourcez.sv4cpiozapplication/x-sv4cpioz.sv4crczapplication/x-sv4crcz.svgz image/svg+xmlz.swfzapplication/x-shockwave-flashz.tz.tarzapplication/x-tarz.tclzapplication/x-tclz.texzapplication/x-texz.texizapplication/x-texinfoz.texinfoz.tifz image/tiffz.tiffz.trz.tsvztext/tab-separated-valuesz.txtz.ustarzapplication/x-ustarz.vcfz text/x-vcardz.wavz audio/x-wavz.webmz video/webmz.wizz.wsdlz.xbmzimage/x-xbitmapz.xlbzapplication/vnd.ms-excelz.xlszapplication/excelz.xmlztext/xmlz.xpdlz.xpmzimage/x-xpixmapz.xslz.xwdzimage/x-xwindowdumpz.zipzapplication/zipz image/jpgz.midz audio/midiz.midiz.pctz image/pictz.picz.pictz.rtfzapplication/rtfz.xulztext/xul)r r r rrrrrÚ_default_mime_typesus$   rSÚ__main__a4Usage: 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@cCs+ttƒ|rt|ƒtj|ƒdS)N)ÚprintÚUSAGEÚsysÚexit)ÚcodeÚmsgrrrÚusage7s  r[r3ZhleÚhelpZlenientÚ extensionú-hú--helpú-lú --lenientú-eú --extensionz I don't know anything about typeztype:z encoding:)r^r_)r`ra)rbrc)&rGrJrWr%Z urllib.parser"Úwinregr=Ú ImportErrorÚ__all__rIr rHrrrrrrrrSrDZgetoptrVr[ÚargvZoptsÚargsÚerrorrZrr]ZoptÚargZgtypeZguessrUr+rrrrÚst        Õ °