Your IP : 18.189.195.35


Current Path : /lib64/python3.6/__pycache__/
Upload File :
Current File : //lib64/python3.6/__pycache__/mimetypes.cpython-36.opt-1.pyc

3


 \2R�@sdZddlZddlZddlZddlZyddlZWnek
rHdZYnXddddddd	d
ddd
ddg
Z	dddddddddg	Z
dadaGdd�d�Z
d6dd�Zd7dd�Zd8dd�Zd9dd	�Zd:dd
�Zd d�Zd!d"�Ze�ed#k�rddlZd$Zd;d&d'�Zy&ejejd(d�d)d*d+d,g�\ZZWn0ejk
�rRZzed(e�WYddZ[XnXd(ZdZxDeD]<\Z Z!e d<k�r~ed�ne d=k�r�dZne d>k�rbd(Z�qbWxheD]`Z"e�r�ee"e�Z#e#�s�e$d3e"�ne$e#�n.ee"e�\Z#Z%e#�s�e$d3e"�ne$d4e#d5e%��q�WdS)?a�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�
knownfiles�inited�	MimeTypes�
guess_type�guess_all_extensions�guess_extension�add_type�init�read_mime_types�
suffix_map�
encodings_map�	types_map�common_typesz/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@sdeZdZdZfdfdd�Zddd�Zddd�Zdd	d
�Zddd�Zdd
d�Z	ddd�Z
ddd�ZdS)rz�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�q<Wx"t	j�D]\}}|j||d�q`Wx|D]}|j
||�q�WdS)NTF)rr	r�copyrr
�
types_map_inv�itemsrr�read)�self�	filenames�strict�ext�type�name�r�!/usr/lib64/python3.6/mimetypes.py�__init__Bs




zMimeTypes.__init__cCs6||j||<|j|j|g�}||kr2|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)rrrrZextsrrrrPszMimeTypes.add_typecCsltjj|�\}}|dkrz|jd�}|dkr.dS|jdd|�}|dkrR|d|�}n|d|�}d|ksnd|krrd}|dfStj|�\}}x&||jkr�tj||j|�\}}q�W||jkr�|j|}	tj|�\}}nd}	|jd	}
||
kr�|
||	fS|j	�|
k�r|
|j	�|	fS|�r"d|	fS|jd
}
||
k�rB|
||	fS|j	�|
k�r`|
|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�splitextrrr
�lower)r�urlr�schemeZcommaZsemir�baser�encodingr
rrrras@





zMimeTypes.guess_typecCsP|j�}|jdj|g�}|sLx,|jdj|g�D]}||kr2|j|�q2W|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�szMimeTypes.guess_all_extensionscCs|j||�}|sdS|dS)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.
        Nr)r)rrrr.rrrr�s
zMimeTypes.guess_extensionc
Cs(t|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.
        zutf-8)r,N)�open�readfp)r�filenamer�fprrrr�szMimeTypes.readc	Cs�x�|j�}|sP|j�}x0tt|��D] }||ddkr&||d�=Pq&W|sPq|d|dd�}}x|D]}|j|d||�qlWqWdS)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)	rr2r�lineZwords�ir�suffixesZsuffrrrr0�s

zMimeTypes.readfpcCs�tsdSdd�}tjtjd���}xz||�D]n}yRtj||��<}|jd�sJw*tj|d�\}}|tjkrfw*|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.
        NcssLd}xBytj||�}Wntk
r,PYnXd|kr<|V|d7}qWdS)Nr�r4)�_winregZEnumKey�EnvironmentError)Zmimedbr;Zctyperrr�
enum_types�sz3MimeTypes.read_windows_registry.<locals>.enum_types�r5zContent Type)r>�OpenKeyZHKEY_CLASSES_ROOT�
startswithZQueryValueExZREG_SZrr?)rrr@ZhkcrZ
subkeynameZsubkeyZmimetypeZdatatyperrr�read_windows_registry�s 


zMimeTypes.read_windows_registryN)T)T)T)T)T)T)T)�__name__�
__module__�__qualname__�__doc__rrrrrrr0rDrrrrr:s

>



TcCstdkrt�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)�_dbr	r)r)rrrrrscCstdkrt�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)rIr	r)rrrrrr&s
cCstdkrt�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)rIr	r)rrrrrr7scCstdkrt�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)rIr	r)rrrrrrrGscCsndat�}|dkr"tr|j�t}x"|D]}tjj|�r(|j|�q(W|j	a	|j
a
|jda|jda|a
dS)NTF)rrr>rDr�os�path�isfilerrrr
rrI)�files�db�filerrrr	Xs


cCsNyt|�}Wntk
r dSX|�t�}|j|d�|jdSQRXdS)NT)r/�OSErrorrr0r
)rO�frNrrrr
lsc�CsDddddddd�adddd	d
�addd
d
d
dddddddddddddddddddddddddd d d!d"d#d#d#d$d%dd&d'd(d(d)d*ddd+d$d,d-d.d.d/d'd'd'd'd0ddddd1d2d3d4d5d2d6dd7d8d9d9d:d9d9dd9d;d<d<d,d=d>d?d@dAdBdCdDdDdEdFdddGdHdIdJdKdBdLdMdNdOdOdPdPdBdQddRdSdTdUdd@dVdWdXdWdYd@dZd@d[d\d]��ad^d_d_d`d`d`dadbdc�adS)dNz.svg.gzz.tar.gzz.tar.bz2z.tar.xz)z.svgzz.tgzz.tazz.tzz.tbz2z.txzZgzip�compressZbzip2Zxz)z.gzz.Zz.bz2z.xzzapplication/octet-streamzapplication/postscriptzaudio/x-aiffzaudio/basiczvideo/x-msvideoz
text/plainzapplication/x-bcpiozimage/x-ms-bmpzapplication/x-cdfzapplication/x-netcdfzapplication/x-cpiozapplication/x-cshztext/cssztext/csvzapplication/mswordzapplication/x-dvizmessage/rfc822z
text/x-setextz	image/gifzapplication/x-gtarzapplication/x-hdfz	text/htmlzimage/vnd.microsoft.iconz	image/iefz
image/jpegzapplication/javascriptzapplication/jsonzapplication/x-latexz
video/mpegzapplication/vnd.apple.mpegurlzapplication/x-troff-manzapplication/x-troff-mezapplication/x-mifzvideo/quicktimezvideo/x-sgi-moviez
audio/mpegz	video/mp4zapplication/x-troff-mszapplication/odazapplication/x-pkcs12zapplication/pkcs7-mimezimage/x-portable-bitmapzapplication/pdfzimage/x-portable-graymapz	image/pngzimage/x-portable-anymapzapplication/vnd.ms-powerpointzimage/x-portable-pixmapz
text/x-pythonzapplication/x-python-codezaudio/x-pn-realaudiozapplication/x-pn-realaudiozimage/x-cmu-rasterzapplication/xmlzimage/x-rgbzapplication/x-troffz
text/richtextztext/x-sgmlzapplication/x-shzapplication/x-sharzapplication/x-wais-sourcezapplication/x-sv4cpiozapplication/x-sv4crcz
image/svg+xmlzapplication/x-shockwave-flashzapplication/x-tarzapplication/x-tclzapplication/x-texzapplication/x-texinfoz
image/tiffztext/tab-separated-valueszapplication/x-ustarztext/x-vcardzaudio/x-wavz
video/webmzimage/x-xbitmapzapplication/vnd.ms-excelzapplication/excelztext/xmlzimage/x-xpixmapzimage/x-xwindowdumpzapplication/zip)�z.az.aiz.aifz.aifcz.aiffz.auz.aviz.batz.bcpioz.binz.bmpz.cz.cdfz.cdfz.cpioz.cshz.cssz.csvz.dllz.docz.dotz.dviz.emlz.epsz.etxz.exez.gifz.gtarz.hz.hdfz.htmz.htmlz.icoz.iefz.jpez.jpegz.jpgz.jsz.jsonz.kshz.latexz.m1vz.m3uz.m3u8z.manz.mez.mhtz.mhtmlz.mifz.mjsz.movz.moviez.mp2z.mp3z.mp4z.mpaz.mpez.mpegz.mpgz.msz.ncz.nwsz.oz.objz.odaz.p12z.p7cz.pbmz.pdfz.pfxz.pgmz.plz.pngz.pnmz.potz.ppaz.ppmz.ppsz.pptz.psz.pwzz.pyz.pycz.pyoz.qtz.raz.ramz.rasz.rdfz.rgbz.roffz.rtxz.sgmz.sgmlz.shz.sharz.sndz.soz.srcz.sv4cpioz.sv4crcz.svgz.swfz.tz.tarz.tclz.texz.texiz.texinfoz.tifz.tiffz.trz.tsvz.txtz.ustarz.vcfz.wavz.webmz.wizz.wsdlz.xbmz.xlbz.xlsz.xlsz.xmlz.xpdlz.xpmz.xslz.xwdz.zipz	image/jpgz
audio/midiz
image/pictzapplication/rtfztext/xul)z.jpgz.midz.midiz.pctz.picz.pictz.rtfz.xul)rrr
rrrrr�_default_mime_typesws(	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.
rAcCs"tt�|rt|�tj|�dS)N)�print�USAGE�sys�exit)�code�msgrrr�usage;sr[r4Zhle�helpZlenient�	extension�-h�--help�-l�	--lenient�-e�--extensionz I don't know anything about typeztype:z	encoding:)T)T)T)T)N)rA)r^r_)r`ra)rbrc)&rHrJrWr&Zurllib.parser#�winregr>�ImportError�__all__rrrIrrrrrr	r
rSrEZgetoptrVr[�argvZopts�args�errorrZrr]�opt�argZgtypeZguessrUr,rrrr�<module>s|
V




3