³ò Ÿl‡Jc@sQdZddkZddkZddkZddddddgZd d d d d ddddg Zeadd-d„ƒYZe d„a e d„a e d„a e d„a dd„Zd„Zd„ZeƒedjooddkZddkZdZdd„Zy/eieiddd d!d"gƒ\ZZWn%eij oZedeƒnXdZd#Zx]eD]U\ZZed.joed#ƒqred/jo d#Zqred0jo dZqrqrWxeD]sZ eo,t e eƒZ!e!p d*Ge GHqEe!GHqÒt e eƒ\Z!Z"e!p d*Ge GHqÒd+Ge!Gd,Ge"GHqÒWndS(1s§Guess the MIME type of a file. This module defines two useful functions: guess_type(url, strict=1) -- guess the MIME type and encoding of a URL. guess_extension(type, strict=1) -- 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 read_mime_types(file) -- parse one file, return a dictionary or None iÿÿÿÿNt guess_typetguess_extensiontguess_all_extensionstadd_typetread_mime_typestinits/etc/mime.typess/etc/httpd/mime.typess/etc/httpd/conf/mime.typess/etc/apache/mime.typess/etc/apache2/mime.typess$/usr/local/etc/httpd/conf/mime.typess"/usr/local/lib/netscape/mime.typess/usr/local/etc/mime.typest MimeTypescBseeZdZded„Zed„Zed„Zed„Zed„Zed„Z ed„Z RS( sç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. cCsÓtp tƒntiƒ|_tiƒ|_hhf|_hhf|_x-tiƒD]\}}|i||t ƒq[Wx-t iƒD]\}}|i||t ƒq‹Wx|D]}|i ||ƒqµWdS(N( tinitedRt encodings_maptcopyt suffix_mapt types_mapt types_map_invtitemsRtTruet common_typestFalsetread(tselft filenameststricttextttypetname((s/sys/lib/python/mimetypes.pyt__init__9s   cCsL||i||<|i|i|gƒ}||jo|i|ƒndS(s‰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 t setdefaulttappend(RRRRtexts((s/sys/lib/python/mimetypes.pyRGs  c Cs ti|ƒ\}}|djo|idƒ}|djod Sn|idd|ƒ}|djo|| }n || }d|jp d|jo d}n|dfSnti|ƒ\}}x5||ijo$ti||i|ƒ\}}qÊW||ijo&|i|} ti|ƒ\}}nd} |it } || jo| || fSnA|i ƒ| jo| |i ƒ| fSn|od| fSn|it } || jo| || fSn6|i ƒ| jo| |i ƒ| fSn d| fSdS( s: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. tdatat,it;t=t/s text/plainN(NN( turllibt splittypetfindtNonet posixpathtsplitextR RR RtlowerR( RturlRtschemetcommatsemiRtbaseRtencodingR ((s/sys/lib/python/mimetypes.pyRXs@     %     cCsv|iƒ}|iti|gƒ}|pFxC|iti|gƒD]$}||jo|i|ƒqFqFWn|S(sÓ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. (R'R RtgetRR(RRRt extensionsR((s/sys/lib/python/mimetypes.pyR–s  cCs)|i||ƒ}|pdSn|dS(s 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. iN(RR$(RRRR/((s/sys/lib/python/mimetypes.pyR©s cCs*t|ƒ}|i||ƒ|iƒdS(s× 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. N(topentreadfptclose(RtfilenameRtfp((s/sys/lib/python/mimetypes.pyR»s c Cs·x°|iƒ}|pPn|iƒ}x;tt|ƒƒD]'}||ddjo ||3Pq:q:W|pqn|d|d}}x%|D]}|i|d||ƒqWqdS(sÀ 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. it#it.N(treadlinetsplittrangetlenR( RR4RtlinetwordstiRtsuffixestsuff((s/sys/lib/python/mimetypes.pyR1Çs    (( t__name__t __module__t__doc__RRRRRRRR1(((s/sys/lib/python/mimetypes.pyR1s  >   cCstƒt||ƒS(sþ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. (RR(R(R((s/sys/lib/python/mimetypes.pyRÞscCstƒt||ƒS(sý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. (RR(RR((s/sys/lib/python/mimetypes.pyRôs cCstƒt||ƒS(sã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. (RR(RR((s/sys/lib/python/mimetypes.pyRs cCstƒt|||ƒS(siAdd 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(RRR((s/sys/lib/python/mimetypes.pyRs cCsµtatƒ}|djo t}nx8|D]0}tii|ƒo|it |ƒƒq-q-W|i a |i a |i ta |i a |ia|ia|ia|i tadS(N(RRRR$t knownfilestostpathtisfileR1R0RR R RRRRRR(tfilestdbtfile((s/sys/lib/python/mimetypes.pyR#s           cCsNyt|ƒ}Wntj o dSnXtƒ}|i|tƒ|itS(N(R0tIOErrorR$RR1RR (RItfRH((s/sys/lib/python/mimetypes.pyR8s  cCsÒhdd<dd<ddd?<d>d@<d>dA<dBdC<ddD<dEdF<dGdH<dIdJ<dKdL<d,dM<d,dN<dOdP<dQdR<dSdT<dUdV<dUdW<dGdX<dGdY<dGdZ<dGd[<d\d]<dd^<d,d_<d d`<d da<dbdc<ddde<dfdg<dhdi<djdk<dddl<dmdn<ddo<dpdq<drds<dtdu<dtdv<dwdx<dtdy<dtdz<d d{<dtd|<d}d~<dd€<dd<dQd‚<dƒd„<d…d†<d‡dˆ<d‰dŠ<d‹dŒ<ddŽ<dd<d‘d’<d‘d“<d”d•<d–d—<dd˜<d d™<dšd›<dœd<dždŸ<d d¡<dd¢<d£d¤<d¥d¦<d§d¨<d©dª<d©d«<d¬d­<d¬d®<dd¯<d°d±<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Êsj     ­      ¤