
    F\h+]                         S r SSKrSSKrSSKrSSKr SSKJr   SSK	r
/ SQr/ SQrSqSq " S S5      rSS
 jrS	S.S jrSS jrSS jrSS jrSS jrS rS r\" 5         S r\S:X  a  \" 5         gg! \ a    Sr Ndf = f! \ a    Sr
 Nmf = f)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) _mimetypes_read_windows_registry)
knownfilesinited	MimeTypes
guess_typeguess_file_typeguess_all_extensionsguess_extensionadd_typeinitread_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.typesr   z/usr/local/etc/mime.typesFc                       \ rS rSrSrSS jrSS jrSS jrSS.S jrS	 r	SS
 jr
SS jrSS jrSS jrSS jr\S 5       rSrg)r   @   zMIME-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.
Tc                    [         (       d
  [        5         [        R                  5       U l        [
        R                  5       U l        0 0 4U l        0 0 4U l        [        R                  5        H  u  p4U R                  XCS5        M     [        R                  5        H  u  p4U R                  XCS5        M     U H  nU R                  XR5        M     g NTF)r   r   _encodings_map_defaultcopyr   _suffix_map_defaultr   r   types_map_inv_types_map_defaultitemsr   _common_types_defaultread)self	filenamesstrictexttypenames          /usr/lib/python3.13/mimetypes.py__init__MimeTypes.__init__H   s    vF388:-224b "X-335KSMM$T* 60668KSMM$U+ 9DIId#     c                     U(       d  gXR                   U   U'   U R                  U   R                  U/ 5      nX$;  a  UR                  U5        gg)I  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)r   r#   r"   r!   extss        r%   r   MimeTypes.add_typeV   sN     &*vs#!!&)44T2>?KK r(   c                    [         R                  " U5      n[        R                  R	                  U5      nUR
                  (       a2  [        UR
                  5      S:  a  UR
                  nUR                  nOU R                  XS9$ US:X  aN  UR                  S5      nUS:  a  gUR                  SSU5      nUS:  a  USU nOUSU nS	U;   d  S
U;  a  SnUS4$ U R                  X[        R                  5      $ )a  Guess 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.
   r!   data,r   )NN;N=/
text/plain)osfspathurllibparseurlparseschemelenpathr   find_guess_file_type	posixpathsplitext)r   urlr!   pr=   commasemir#   s           r%   r   MimeTypes.guess_typei   s    ( iinLL!!#&88AHH)XXF&&C''';;V HHSMEqy!88CE*Dqy5Dz6E{d{co#:$$S)2D2DEEr(   r1   c                    [         R                  " U5      n[         R                  R                  U5      S   nU R	                  X[         R                  R
                  5      $ )iGuess the type of a file based on its path.

Similar to guess_type(), but takes file path istead of URL.
r0   )r8   fsdecoder?   
splitdriverA   rC   )r   r?   r!   s      r%   r   MimeTypes.guess_file_type   sH    
 {{4 ww!!$'*$$T2773C3CDDr(   c                    U" U5      u  pEUR                  5       =o`R                  ;   a:  U" X@R                  U   -   5      u  pEUR                  5       =o`R                  ;   a  M:  XPR                  ;   a  U R                  U   nU" U5      u  pEOS nUR                  5       nU R                  S   nXX;   a  X   U4$ U(       a  S U4$ U R                  S   nXX;   a  X   U4$ S U4$ r   )lowerr   r   r   )	r   r?   r!   rC   baser"   	ext_lowerencodingr   s	            r%   rA   MimeTypes._guess_file_type   s    TN	IIK'yOO; 	(B!BCID  IIK'yOO; $$$))#.H ID#HiikNN4(	>8++>!NN5)	>8++>!r(   c                     UR                  5       n[        U R                  S   R                  U/ 5      5      nU(       d>  U R                  S   R                  U/ 5       H  nXC;  d  M
  UR	                  U5        M     U$ )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)rO   listr   getr,   )r   r#   r!   
extensionsr"   s        r%   r	   MimeTypes.guess_all_extensions   sr     zz|$,,T266tR@A
))%044T2>(%%c* ? r(   c                 >    U R                  X5      nU(       d  gU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.
Nr   )r	   )r   r#   r!   rW   s       r%   r
   MimeTypes.guess_extension   s$     ..t<
!}r(   c                 n    [        USS9 nU R                  X25        SSS5        g! , (       d  f       g= f)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-8rR   N)openreadfp)r   filenamer!   fps       r%   r   MimeTypes.read   s(     (W-KK# .--s   &
4c                 @   UR                  5       =n(       a  UR                  5       n[        [        U5      5       H  nXE   S   S:X  d  M  XES2	   O   U(       d  M\  US   USS pvU H  nU R	                  USU-   U5        M     UR                  5       =n(       a  M  gg)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   #Nr0   .)readlinesplitranger>   r   )	r   ra   r!   linewordsir#   suffixessuffs	            r%   r_   MimeTypes.readfp   s     kkm#d#JJLE3u:&8A;#%b	 ' "1XuQRy( dC$J7 ! kkm#d##r(   c                    ^  [         (       d  [        (       d  gT R                  nU(       a  U 4S jn[         (       a  [        U5        g[        (       a  T R                  U5        gg)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                 (   > TR                  XS5      $ )NT)r   )r#   r"   r   s     r%   <lambda>1MimeTypes.read_windows_registry.<locals>.<lambda>
  s    t$)Gr(   )r   _winregr   _read_windows_registry)r   r!   r   s   `  r%   read_windows_registryMimeTypes.read_windows_registry   sK     0/==GH ,+,X6W''1 r(   c                    S n[         R                  " [         R                  S5       nU" U5       H  n [         R                  " X45       nUR                  S5      (       d   S S S 5        M<  [         R                  " US5      u  pgU[         R
                  :w  a   S S S 5        Mt  U" Xd5        S S S 5        M     S S S 5        g ! , (       d  f       M  = f! [         a     M  f = f! , (       d  f       g = f)Nc              3      #    Sn  [         R                  " X5      nSU;  a  Uv   US-  nM(  ! [         a     g f = f7f)Nr    r0   )rs   EnumKeyOSError)mimedbrk   ctypes      r%   
enum_types4MimeTypes._read_windows_registry.<locals>.enum_types  sP     A$#OOF6E 5(#Q   s   >. >
;>;> re   zContent Type)rs   OpenKeyHKEY_CLASSES_ROOT
startswithQueryValueExREG_SZr{   )clsr   r~   hkcr
subkeynamesubkeymimetypedatatypes           r%   rt    MimeTypes._read_windows_registry  s    
	 __W66;t(.
 :f)44S99$ ;:
 .5-A-A"N.4*#w~~5$ ;: !6 ;: / <; ;:   <;sv   C&CC$C,C&..CC$C&&C.C6C&
CCC&C
C#C&"C##C&&
C4)r   r   r   r   N) TT)__name__
__module____qualname____firstlineno____doc__r&   r   r   r   rA   r	   r
   r   r_   ru   classmethodrt   __static_attributes__r   r(   r%   r   r   @   sU    $&.F` /3 E",&$	$8(2,  r(   r   Tc                 N    [         c
  [        5         [         R                  X5      $ )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.
)_dbr   r   )rD   r!   s     r%   r   r   0  s    $ {>>#&&r(   r1   c                J    [         c
  [        5         [         R                  XS9$ )rJ   r1   )r   r   r   )r?   r!   s     r%   r   r   G  s"    
 {t33r(   c                 N    [         c
  [        5         [         R                  X5      $ )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.
)r   r   r	   r#   r!   s     r%   r	   r	   Q  s     {##D11r(   c                 N    [         c
  [        5         [         R                  X5      $ )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.
)r   r   r
   r   s     r%   r
   r
   b  s     {t,,r(   c                 P    [         c
  [        5         [         R                  XU5      $ )r*   )r   r   r   )r#   r"   r!   s      r%   r   r   r  s     {<<6**r(   c                    Sq U b  [        c7  [        5       nUR                  5         U c  [        n O[        [        U 5      -   n O[        nU  H:  n[        R                  R                  U5      (       d  M)  UR                  U5        M<     UR                  q
UR                  qUR                  S   qUR                  S   qUqg r   )r   r   r   ru   r   rU   r8   r?   isfiler   r   r   r   r   )filesdbfiles      r%   r   r     s     F}[
  "=Ee,E77>>$GGDM  $$MJT"I<<&L
Cr(   c                      [        U SS9nU   [        5       nUR                  US5        UR                  S   sS S S 5        $ ! [         a     g f = f! , (       d  f       g = f)Nr\   r]   T)r^   r{   r   r_   r   )r   fr   s      r%   r   r     sZ    ( 
[
		!T||D! 
  	
s   
A +A
AA
A!c            	      4   SSSSSSS.=q qSSSS	S
S.=qq0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S_S!S_S"S_S#S$_0 S%S&_S'S(_S)S*_S+S*_S,S*_S-S._S/S0_S1S0_S2S3_S4S3_S5S6_S7S6_S8S6_S9S6_S:S6_S;S<_S=S>_E0 S?S@_SASB_SCSD_SESF_SGSH_SISJ_SKSL_SMSN_SOSP_SQSP_SRSS_STSS_SUSV_SWSX_SYSX_SZS[_S\S]_E0 S^S__S`Sa_SbSc_SdSe_SfSg_ShSi_SjSk_SlSk_SmSn_SoSn_SpSn_SqSr_SsSt_SuSv_SwSx_SySz_S{S|_E0 S}S|_S~S|_SS|_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_GS GS_GSGS_GSGS_GSGS_EGSGS0E=qqGS	GS
GS
GSGSGSGSGSGS.=qqg (  Nz.svg.gzz.tar.gzz.tar.bz2z.tar.xz)z.svgzz.tgzz.tazz.tzz.tbz2z.txzgzipcompressbzip2xzbr)z.gzz.Zz.bz2z.xzz.brz.jsztext/javascriptz.mjsz.jsonzapplication/jsonz.webmanifestzapplication/manifest+jsonz.doczapplication/mswordz.dotz.wizz.nqzapplication/n-quadsz.ntzapplication/n-triplesz.binzapplication/octet-streamz.az.dllz.exez.oz.objz.soz.odazapplication/odaz.pdfzapplication/pdfz.p7czapplication/pkcs7-mimez.pszapplication/postscriptz.aiz.epsz.trigzapplication/trigz.m3uzapplication/vnd.apple.mpegurlz.m3u8z.xlszapplication/vnd.ms-excelz.xlbz.pptzapplication/vnd.ms-powerpointz.potz.ppaz.ppsz.pwzz.wasmzapplication/wasmz.bcpiozapplication/x-bcpioz.cpiozapplication/x-cpioz.cshzapplication/x-cshz.dvizapplication/x-dviz.gtarzapplication/x-gtarz.hdfzapplication/x-hdfz.h5zapplication/x-hdf5z.latexzapplication/x-latexz.mifzapplication/x-mifz.cdfzapplication/x-netcdfz.ncz.p12zapplication/x-pkcs12z.pfxz.ramzapplication/x-pn-realaudioz.pyczapplication/x-python-codez.pyoz.shzapplication/x-shz.sharzapplication/x-sharz.swfzapplication/x-shockwave-flashz.sv4cpiozapplication/x-sv4cpioz.sv4crczapplication/x-sv4crcz.tarzapplication/x-tarz.tclzapplication/x-tclz.texzapplication/x-texz.texizapplication/x-texinfoz.texinfoz.roffzapplication/x-troffz.tz.trz.manzapplication/x-troff-manz.mezapplication/x-troff-mez.mszapplication/x-troff-msz.ustarzapplication/x-ustarz.srczapplication/x-wais-sourcez.xslzapplication/xmlz.rdfz.wsdlz.xpdlz.zipzapplication/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.razaudio/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.icozimage/vnd.microsoft.iconz.webpz
image/webpz.raszimage/x-cmu-rasterz.pnmzimage/x-portable-anymapz.pbmzimage/x-portable-bitmapz.pgmzimage/x-portable-graymapz.ppmzimage/x-portable-pixmapz.rgbzimage/x-rgbz.xbmzimage/x-xbitmapz.xpmzimage/x-xpixmapz.xwdzimage/x-xwindowdumpz.emlzmessage/rfc822z.mhtz.mhtmlz.nwsz.cssztext/cssz.csvztext/csvz.htmlz	text/htmlz.htmz.mdztext/markdownz	.markdownz.n3ztext/n3z.txtr7   z.batz.cz.hz.kshz.plz.srtz.rtxztext/richtext.rtfztext/rtfz.tsvztext/tab-separated-valuesz.vttztext/vttz.pyztext/x-pythonz.rstz
text/x-rstz.etxztext/x-setextz.sgmztext/x-sgmlz.sgmlz.vcfztext/x-vcardz.xmlztext/xmlz.mp4z	video/mp4z.mpegz
video/mpegz.m1vz.mpaz.mpez.mpgz.movzvideo/quicktimez.qtz.webmz
video/webmz.avizvideo/x-msvideoz.moviezvideo/x-sgi-moviezapplication/rtfz
audio/midiz	image/jpgz
image/pictztext/xul)r   z.midiz.midr   z.pictz.pctz.picz.xul)r   r   r   r   r   r   r   r   r   r(   r%   _default_mime_typesr     s	    (
 
J$ .
 
M*[&
%[&
%[&
 	&[&
 	3	[&

 	([&
 	([&
 	([&
 	)[&
 	+[&
 	.[&
 	.[&
 	.[&
 	.[&
 	.[&
 	.[&
  	.![&
" 	%#[&
$ 	%%[&
& 	,'[&
( 	,)[&
* 	,+[&
, 	,-[&
. 	&/[&
0 	31[&
2 	33[&
4 	.5[&
6 	.7[&
8 	39[&
: 	3;[&
< 	3=[&
> 	3?[&
@ 	3A[&
B 	&C[&
D 	)E[&
F 	(G[&
H 	'I[&
J 	'K[&
L 	(M[&
N 	'O[&
P 	(Q[&
R 	)S[&
T 	'U[&
V 	*W[&
X 	*Y[&
Z 	*[[&
\ 	*][&
^ 	0_[&
` 	/a[&
b 	/c[&
d 	&e[&
f 	(g[&
h 	3i[&
j 	+k[&
l 	*m[&
n 	'o[&
p 	'q[&
r 	's[&
t 	+u[&
v 	+w[&
x 	)y[&
z 	){[&
| 	)}[&
~ 	-[&
@ 	,A[&
B 	,C[&
D 	)E[&
F 	/G[&
H 	%I[&
J 	%K[&
L 	%M[&
N 	%O[&
P 	%Q[&
R 	LS[&
T 	LU[&
V 	MW[&
X 	MY[&
Z 	K[[&
\ 	K][&
^ 	K_[&
` 	Ka[&
b 	Mc[&
d 	Me[&
f 	Lg[&
h 	Li[&
j 	Lk[&
l 	Nm[&
n 	No[&
p 	Nq[&
r 	*s[&
t 	Mu[&
v 	Lw[&
x 	Ky[&
z 	K{[&
| 	K}[&
~ 	L[&
@ 	LA[&
B 	LC[&
D 	LE[&
F 	LG[&
H 	KI[&
J 	OK[&
L 	LM[&
N 	LO[&
P 	.Q[&
R 	LS[&
T 	(U[&
V 	-W[&
X 	-Y[&
Z 	.[[&
\ 	-][&
^ 	M_[&
` 	%a[&
b 	%c[&
d 	)e[&
f 	$g[&
h 	$i[&
j 	$k[&
l 	$m[&
n 	Jo[&
p 	Jq[&
r 	Ks[&
t 	Ku[&
v 	Ow[&
x 	_y[&
z 	I{[&
| 	L}[&
~ 	L[&
@ 	LA[&
B 	LC[&
D 	LE[&
F 	LG[&
H 	LI[&
J 	OK[&
L 	JM[&
N 	/O[&
P 	JQ[&
R 	OS[&
T 	LU[&
V 	OW[&
X 	MY[&
Z 	M[[&
\ 	N][&
^ 	J_[&
` 	Ka[&
b 	Lc[&
d 	Le[&
f 	Lg[&
h 	Li[&
j 	Lk[&
l 	%m[&
n 	%o[&
p 	Lq[&
r 	%s[&
t 	'u[&
 [
I"D #	,
 	
L(r(   c                     ^ SS K n SmSU4S jjn U R                  [        R                  SS  S/ SQ5      u  p#SnSnW H)  u  pxUS;   a
  U" S5        M  US;   a  SnM  US	;   d  M'  SnM+     W Hg  n	U(       a-  [	        X5      n
U
(       d  [        S
U	5        M*  [        U
5        M7  [        X5      u  pU
(       d  [        S
U	5        MY  [        SU
SU5        Mi     g ! U R                   a  nU" SU5         S nANS nAff = f)Nr   a4  Usage: 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.
c                 l   > [        T5        U(       a  [        U5        [        R                  " U 5        g N)printsysexit)codemsgUSAGEs     r%   usage_main.<locals>.usage  s    ec
r(   r0   hle)helplenient	extension)z-hz--help)z-lz	--lenient)z-ez--extensionz I don't know anything about typeztype:z	encoding:)r   )getoptr   argverrorr
   r   r   )r   r   optsargsr   r!   r   optarggtypeguessrR   r   s               @r%   _mainr   x  s    
E
]]388AB<#CE

 FI""!H''F))I  #E2E% BEJ,(7OE% BEJX>  << as   (C C=*	C88C=__main__r   r   )r   r8   r   rB   urllib.parser:   _winapir   ImportErrorwinregrs   __all__r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r(   r%   <module>r      s   2 
 
  ,8

 

n n`'. %) 42"- +"8"H
V  +?\ z	G K  ,'+$,
  Gs"   A4 B 4A?>A?BB