+
    nif  c                   s|   R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIt^ RI	H
t
Ht ^ RIHt Rt/ tRtRsRtRs]P(                  ^ ,          ^8  tR tR1R lt ! R R	]4      t ! R
 R]4      t ! R R]4      t ! R R4      t ! R R]4      t ! R R4      t  ! R R]4      t!]! RR4      t"]! RR4      t#]! RR4      t$]! RR4      t%]! RR4      t&]! RR4      t']! RR4      t(]! RR 4      t)]! RR!4      t*]! RR"4      t+R#s,R$ t-R% t.R& t/R2R' lt0R2R( lt1R) t2R3R* lt3R4R+ lt4R, t5]'       d   R- t6MR. t6Rs7R#s8R/ t9R0 t:R# )5a  
This module is based on a rox module (LGPL):

http://cvs.sourceforge.net/viewcvs.py/rox/ROX-Lib2/python/rox/mime.py?rev=1.21&view=log

This module provides access to the shared MIME database.

types is a dictionary of all known MIME types, indexed by the type name, e.g.
types['application/x-python']

Applications can install information about MIME types by storing an
XML file as <MIME>/packages/<application>.xml and running the
update-mime-database command, which is provided by the freedesktop.org
shared mime database package.

See http://www.freedesktop.org/standards/shared-mime-info-spec/ for
information about the format of these files.

(based on version 0.13)
N)BaseDirectory)minidomXML_NAMESPACE)defaultdictz5http://www.freedesktop.org/standards/shared-mime-infoc                s    RP                  V P                   Uu. uF  qP                  NK  	  up4      P                  4       # u upi )zGet text of XML node )joinZ
childNodesZ	nodeValuestrip)ZnodeZn   & -/usr/lib/python3.14/site-packages/xdg/Mime.py_get_node_datar	   -   s2    779AKK9:@@BB9s   Ac                s    \        W4      # )zGet the MIMEtype object for the given type.

This remains for backwards compatibility; calling MIMEtype now does
the same thing.

The name can either be passed as one part ('text/plain'), or as two
('text', 'plain').
)MIMEtypemediasubtype   &&r   lookupr   1   s     E##    c                   sj   a a ] tR t^<t oRtRV 3R lltR tR tR tR t	R t
R tR	 tR
 tRtVtV ;t# )r
   zClass holding data about a MIME type.

Calling the class will return a cached instance, so there is only one 
instance for each MIME type. The name can either be passed as one part
('text/plain'), or as two ('text', 'plain').
c                s4  < Vf   RV9   d   VP                  R^4      w  rRV9  g   Q hVP                  4       pVP                  4       p \        W3,          #   \         d4    \        \
        T `  T 4      pTP                  Y4       T\        Y3&   Tu # i ; i)N/)splitlowertypesZKeyErrorZsuperr
   __new___init)clsr   r   mtype	__class__s   &&& r   r   ZMIMEtype.__new__C   s    ?se|"[[a0NE'!!!--/	%)** 	(C05EKK'&+E5"#L		s   A ;BBc                s,    Wn         W n        R V n        R # N)r   r   _comment)selfr   r      &&&r   r   ZMIMEtype._initU   s    
r   c                s.   \         P                  P                  RV P                  V P                  R,           4      p\
        P                  ! V4       F  p\        P                  ! V4      pVf   K  VP                  P                  \        R4       F{  pVP                  \        R4      ;'       g    Rp^V\        P                  P                   9   ,           pW`P"                  ^ ,          8  d   V\%        V4      3V n        V^8X  g   Ky    R# 	  K  	  R# )z>Loads comment for current language. Use get_comment() instead.mime.xmlNcommentlangZen)ospathr   r   r   r    load_data_pathsr   ZparseZdocumentElementZgetElementsByTagNameNSFREE_NSZgetAttributeNSr   xdgZLocaleZlangsr   r	   )r   resourcer#   Zdocr    r!   Zgoodnesss   &      r   _loadZMIMEtype._loadZ   s    77<<

DLL64IJ!11(;D--%C{..EEgyY--mVDLL

(8(8 89mmA..%-~g/F$GDMq=& Z	 <r   c                s    V P                   f#   ^ \        V 4      3V n         V P                  4        V P                   ^,          # )z;Returns comment for current language, loading it if needed.)r   strr(   r      &r   get_commentZMIMEtype.get_commenti   s5     == D	NDMJJL}}Qr   c                sr    \        4        \        V 4      pV\        9   d   \        \        V,          4      # V # )z:Returns the canonical MimeType object if this is an alias.)update_cacher)   aliasesr   )r   sr   r   	canonicalZMIMEtype.canonicalq   s+    I<'!*%%r   c                sb    \        4        \        R \        \        V 4      ,           4       4      # )z5Returns a set of Mime types which this inherits from.c              3   s8   "   T F  p\        V4      x  K  	  R # 5ir   )r   ).0tr   r   	<genexpr>Z)MIMEtype.inherits_from.<locals>.<genexpr>|   s     =&<6!99&<s   )r-   setinheritancer)   r*   r+   r   inherits_fromZMIMEtype.inherits_fromy   s!    =k#d)&<===r   c                sJ    V P                   R ,           V P                  ,           # )r   r   r*   r+   r   __str__ZMIMEtype.__str__~   s    zzC$,,..r   c                s@    R V P                   : RV P                  : R2# )z	MIMEtype(z, )r   r*   r+   r   __repr__ZMIMEtype.__repr__   s    %)ZZ>>r   c                s`    \        V P                  4      \        V P                  4      ,          # r   )Zhashr   r   r*   r+   r   __hash__ZMIMEtype.__hash__   s    DJJ$t||"444r   )r   r   r   r   )__name__
__module____qualname____firstlineno____doc__r   r   r(   r,   r0   r6   r7   r9   r:   __static_attributes____classdictcell__Z__classcell__)r   __classdict__s   @@r   r
   r
   <   s<     $
) >
/?5 5r   r
   c                   s    ] tR t^tRtR# )UnknownMagicRuleFormat N)r;   r<   r=   r>   r@   rD   r   r   rC   rC      s    r   rC   c                   s    ] tR t^tRtRtR# )DiscardMagicRuleszGRaised when __NOMAGIC__ is found, and caught to discard previous rules.rD   N)r;   r<   r=   r>   r?   r@   rD   r   r   rE   rE      s    Mr   rE   c                   sv   a  ] tR t^t o RtR t]P                  ! R4      t]	R 4       t
R tR tR tR tR	tV tR# )
	MagicRuleNc                sB    Wn         W n        W0n        W@n        WPn        R # r   startvaluemaskwordrange)r   rH   rI   rJ   rK   rL   s   &&&&&&r   __init__ZMagicRule.__init__   s    

		
r   s   (?:~(\d+))?(?:\+(\d+))?\n$c                s   VP                  4       pVP                  R^4      w  r2V'       d   \        V4      M^ pVP                  R^4      w  rB\        V4      pVR8X  d   \        h\        P
                  ^ ,          ^8  d    \        P                  VR,          RR7      pM0\        V^ ,          4      ^,          \        V^,          4      ,           pVR,          p\        V4      V8:  d   W!P                  4       ,          pK(  VRV W%R r&VP                  R	4      '       d@   \        V4      V8:  d   W!P                  4       ,          pK(  V^V^,            W%^,           R r'MRpV P                  P                  V4      pV'       g   \        \        V4      4      hVP                  4       w  rV	e   \        V	4      M^p	V
e   \        V
4      M^p
W0! WFWyV
4      3# )
zbRead a rule from the binary magics file. Returns a 2-tuple of
the nesting depth and the MagicRule.s   >s   =s   __NOMAGIC__
:N   NZbig)Z	byteorderrN   NNNr+   )readliner   intrE   sysversion_infoZ
from_bytesordlen
startswithrule_ending_rematchrC   ZreprZgroups)r   flineZ
nest_depthrH   lenvaluerI   rJ   ZendingrK   rL      &&         r   	from_fileZMagicRule.from_file   s    zz|  ::dA.
(2S_
 jjq)E
#### A!#~~d2h%~@HDGaT!W5HBx $i8#JJL D9HotIt ??4  d)x'

$a
+T1*+->$D ##))$/ )d44mmo!-s4yA$0E
q3uT???r   c                s    V P                   \        V P                  4      ,           V P                  ,           pV P                  '       d$   \        WP                  P                  4       4      # V# r   )rH   rU   rI   rL   alsomaxmaxlen)r   lr   r   r`   ZMagicRule.maxlen   sG    JJTZZ(4::5999q))**,--r   c                s    V P                  V4      '       d0   V P                  '       d   V P                  P                  V4      # R # R# )TN)match0r^   rX   r   bufferr   r   rX   ZMagicRule.match   s5    ;;vyyyyyv.. r   c                s@   \        V4      p\        V P                  4      p\        V P                  4       F  pV P                  V,           pWS,           pW&8  d    R # V P                  '       d   Rp\        V4       F  p\
        '       d)   WV,           ,          V P                  V,          ,          p	M9\        WV,           ,          4      \        V P                  V,          4      ,          p	V\        V	4      ,          pK  	  MWV pWpP                  8X  g   K   R# 	  R# )Fr   TN)rU   rI   rL   rH   rJ   PY3rT   Zchr)
r   rd   ra   r[   Zor/   ZeZtestic
   &&        r   rb   ZMagicRule.match0   s    
f+tzz?tzz"AjjlAjAsyyyxAs"Q3K$))A,6s,s499Q</@@CFND ) {ZZ# #r   c                s    R V P                   : RV P                  : RV P                  : RV P                  : RV P                  : R2# )zMagicRule(start=z, value=z, mask=z, word=z, range=r8   rG   r*   r+   r   r9   ZMagicRule.__repr__   s/    "&**"&**"&))"&))"&**. 	.r   )rJ   rL   rH   rI   rK   )r;   r<   r=   r>   r^   rM   recompilerW   classmethodr]   r`   rX   rb   r9   r@   rA   rB      @r   rF   rF      sN     D ZZ >?N2@ 2@h,. .r   rF   c                   sV   a  ] tR t^t o RtR tR tR t]R 4       t	]R 4       t
RtV tR# )	MagicMatchAnyzMatch any of a set of magic rules.

This has a similar interface to MagicRule objects (i.e. its match() and
maxlen() methods), to allow for duck typing.
c                s    Wn         R # r   rules)r   rp   r   r   rM   ZMagicMatchAny.__init__   s    
r   c                s   a \         ;QJ d)    V3R  lV P                   4       F  '       g   K   R# 	  R# ! V3R  lV P                   4       4      # )c              3   sD   <"   T F  qP                  S4      x  K  	  R # 5ir   )rX   )r1   rrd   s   & r   r3   Z&MagicMatchAny.match.<locals>.<genexpr>  s     7Jq776??Js    TF)anyrp   rc   s   &fr   rX   ZMagicMatchAny.match  s4    s7DJJ7ss7s7s7DJJ777r   c                s:    \        R  V P                   4       4      # )c              3   s@   "   T F  qP                  4       x  K  	  R # 5ir   )r`   )r1   rq   r   r   r3   Z'MagicMatchAny.maxlen.<locals>.<genexpr>  s     2z!88::zs   )r_   rp   r*   r+   r   r`   ZMagicMatchAny.maxlen  s    2tzz222r   c                s   VP                  ^4      pVP                  R^4       . pV'       d\   VR8w  dU    VP                  \        P	                  V4      4       VP                  ^4      pV'       g   KO  VP                  R^4       Kc  . p^ V/pV F*  w  rg. pWV,          P                  Wx34       WV^,           &   K,  	  V P                  V4      #   \
         d     Li ; i)z/Read a set of rules from the binary magic file.s   [)readZseekappendrF   r]   rC   from_rule_tree)	r   rY   rg   Zdepths_rulestreeZinsert_pointsZdepthrulesubrules	   &&       r   r]   ZMagicMatchAny.from_file	  s     &&)	r1AI##I$7$7$:; ffQiAqr1 4'KEH ''(89%-%'" (
 !!$'' * s   $C CCc                s    . pV F4  w  r4V'       d   V P                  V4      Vn        VP                  V4       K6  	  \        V4      ^ 8X  d   R# \        V4      ^8X  d
   V^ ,          # V ! V4      # )zFrom a nested list of (rule, subrules) pairs, build a MagicMatchAny
instance, recursing down the tree.

Where there's only one top-level rule, this is returned directly,
to simplify the nested structure. Returns None if no rules were read.
N)rv   r^   ru   rU   )r   rw   rp   rx   ry   s   &&   r   rv   ZMagicMatchAny.from_rule_tree#  sd     "ND..x8	LL #
 u:q=u:q=8O5zr   ro   N)r;   r<   r=   r>   r?   rM   rX   r`   rk   r]   rv   r@   rA   rl   rm   r   rn   rn      sA     
83 ( (2  r   rn   c                   sL   a  ] tR tRt o R tR tR tR
R ltR
R ltR t	R	t
V tR# )MagicDBi7  c                s.    \        \        4      V n        R # r   )r   listbytyper*   r+   r   rM   ZMagicDB.__init__8  s    #D)r   c                s   \        VR4      ;_uu_ 4       pVP                  4       pVR8w  d   \        R4      h VP                  4       P                  R4      pV'       g   MV^ ,          R8w  g   VR
R R8w  d   \	        RV4      hV^R
 P                  R	4      w  rV\        V4      p\        V4      p \        P                  V4      pVf   K  V P                  V,          P                  WX34       K  RRR4       R#   \         d5    T P                  P                  TR4       \        P                  T4      p Lsi ; i  + '       g   i     R# ; i)z<Read a magic binary file, and add its rules to this MagicDB.rbs   MIME-Magic 
zNot a MIME magic fileZascii[Nz]
zMalformed section heading:i)openrP   IOErrorZdecode
ValueErrorr   rQ   r   rn   r]   rE   r}   popru   )	r   ZfnamerY   rZ   ZsheadpriZtnamer   rx   rz   r   
merge_fileZMagicDB.merge_file;  s!   %!::<D((566

++G48s?eBCjE&9$%@%HH"1R[..s3
#hu6(2215D < E"))3+63 $ ) 6KKOOE40(2215D6% s7   A
D> AD>2C<+D><<D;8D>:D;;D>>E	c                s(   ^ p. V n         V P                  P                  4        FF  w  r#V F;  w  rEV P                   P                  WBV34       \	        WP                  4       4      pK=  	  KH  	  Wn        V P                   P                  R RR7       R# )zcPrepare the MagicDB for matching.

This should be called after all rules have been merged into it.
c                     V ^ ,          #     rD   xr+   r   <lambda>Z"MagicDB.finalise.<locals>.<lambda>f  s    1r   TkeyreverseN)alltypesr}   itemsru   r_   r`   sort)r   r`   r   rp   r   rx   s   &     r   finaliseZMagicDB.finaliseX  sz    
  KK--/LE"	$$c$%78V[[]3 # 0
 ~t<r   Nc                s2   VeO   . pV F2  pV P                   V,           F  w  rxVP                  WvV34       K  	  K4  	  VP                  R R7       MV P                  pV F2  w  rpW8  d   K  W8  d    R# VP	                  V4      '       g   K0  V
u # 	  R# )a%  Do magic sniffing on some bytes.

max_pri & min_pri can be used to specify the maximum & minimum priority
rules to look for. possible can be a list of mimetypes to check, or None
(the default) to check all mimetypes until one matches.

Returns the MIMEtype found, or None if no entries match.
Nc                 r   r   rD   r   r+   r   r   Z$MagicDB.match_data.<locals>.<lambda>v  s    QqTr   )r   )r}   ru   r   r   rX   )r   datamax_primin_pripossibler   mtr   rx   Zprioritymimetypes   &&&&&      r   
match_dataZMagicDB.match_datah  s     E!%RICLL#41 "1  JJ>J*MME(-$H!!zz$ ).r   c                s    \        VR4      ;_uu_ 4       pVP                  V P                  4      pRRR4       V P                  XW#V4      #   + '       g   i     L#; i)ae  Read data from the file and do magic sniffing on it.

max_pri & min_pri can be used to specify the maximum & minimum priority
rules to look for. possible can be a list of mimetypes to check, or None
(the default) to check all mimetypes until one matches.

Returns the MIMEtype found, or None if no entries match. Raises IOError
if the file can't be opened.
r~   N)r   rt   r`   r   )r   r#   r   r   r   rY   Zbufs   &&&&&  r   rX   ZMagicDB.match  sF     $&&%C sGh?? s   AA	c                s:    R \        V P                  4      ,          # )z<MagicDB (%d types)>)rU   r   r*   r+   r   r9   ZMagicDB.__repr__  s    %DMM(:::r   )r   r}   r`   )d   r   N)r;   r<   r=   r>   rM   r   r   r   rX   r9   r@   rA   rl   rm   r   r{   r{   7  s)     *7:=  8@; ;r   r{   c                   sD   a  ] tR tRt o R tR tR tR tR tR t	Rt
V tR	# )
GlobDBi  c                s.    \        \        4      V n        R# )zPrepare the GlobDB. It can't actually be used until .finalise() is
called, but merge_file() can be used to add data before that.
N)r   r4   allglobsr*   r+   r   rM   ZGlobDB.__init__  s    
 $C(r   c           
     s   V P                   p\        V4      ;_uu_ 4       pV F  pVP                  R4      '       d   K  VRR P                  R4      pVR,          w  rgp\	        V4      p\        V4      p	\        V4      ^8  d   V^,          P                  R4      p
MRp
VR8X  d   VP                  V	R4       K  W),          P                  Wh\        V
4      34       K  	  RRR4       R#   + '       g   i     R# ; i)	z3Loads name matching information from a globs2 file.Z#Nr   :Ni   NZ,Z__NOGLOBS__rs   rD   )
r   r   rV   r   rQ   r   rU   r   addZtuple)r   r#   r   rY   rZ   ZfieldsweightZ	type_namepatternr   flagsr\   r   r   ZGlobDB.merge_file  s    ==$ZZ1??3''cr--3BZ*7Vy)v;?"1IOOC0EEm+LL-##VeEl$CD#  ZZZs   CC++C<	c                s   \        \        4      V n        \        \        4      V n        . V n        / V n        / V n        V P                  P                  4        EFq  w  rVP                  4       pV EFT  w  r4pRV9   pVP                  R4      '       d~   VR,          pRV9   gn   RV9   gg   RV9   g`   V'       d%   V P                  V,          P                  W34       M1V P                  VP                  4       ,          P                  W34       K  RV9   g   RV9   g   RV9   dg   V'       d   ^ M\        P                  p\        P                  ! \         P"                  ! V4      VR7      pV P                  P                  WAV34       EK  V'       d   W3V P                  V&   EK6  W3V P
                  VP                  4       &   EKW  	  EKt  	  V P                  P%                  RR	 R
7       R# )zbPrepare the GlobDB for matching.

This should be called after all files have been merged into it.
Zcsz*.rO   Z*r   Z?)r   Tc                 sL    V ^,          \        V ^ ,          P                  4      3# )rN   )rU   r   r   r+   r   r   Z!GlobDB.finalise.<locals>.<lambda>  s    QqT3qt||;L4Mr   )r   r   N)r   r|   exts
cased_extsglobsliteralscased_literalsr   r   r0   rV   ru   r   ri   ZIrj   fnmatchZ	translater   )	r   r   r   r   r   r   ZcasedZrestZre_flagss	   &        r   r   ZGlobDB.finalise  sp   
  %	%d+
  MM//1LE//#%(-$fuEME!!$''r{tsd{cTk-44e_E		$**,/66Gw#.C7N %1244**W%6%6w%?xP

!!76":; 49?D''06;_DMM'--/21 ). 2: 	

*MOr   c                sj     \        V P                  V4      4      ^ ,          #   \         d     R# i ; i)zLReturn the first match found for a given path, or None if no match
is found.N)Znext_match_pathZStopIterationr   r#   r   r   first_matchZGlobDB.first_match  s4    	((./22 		s    # 22c                s6    \        V P                  V4      4      # )z<Return a list of (MIMEtype, glob weight) pairs for the path.)r|   r   r   r   r   all_matchesZGlobDB.all_matches  s    D$$T*++r   c              #  s  "   \         P                  P                  V4      pW P                  9   d   V P                  V,          x  VP	                  4       pW0P
                  9   d   V P
                  V,          x  Tp VP                  R4      pV^ 8  d   M=WE^,           R pW@P                  9   g   K7  V P                  V,           F  pVx  K	  	  KW  Tp VP                  R4      pV^ 8  d   M=WE^,           R pW@P                  9   g   K7  V P                  V,           F  pVx  K	  	  KW  V P                   F$  w  rxp	VP                  V4      '       g   K  W3x  K&  	  R# 5i)z(Yields pairs of (mimetype, glob weight).Z.N)r"   r#   Zbasenamer   r   r   Zfindr   r   r   rX   )
r   r#   ZleafZlleafextZpZresZregexZ	mime_typer   rh   r   r   ZGlobDB._match_path  s)    ww% &&&%%d++

MM!--&& A1ue!ef+Coo%??3//CI 0A1uecd)Cii99S>>CI * +/**&Uv{{4   )) +5s   B.E$5AE$AE$E$)r   r   r   r   r   r   N)r;   r<   r=   r>   rM   r   r   r   r   r   r@   rA   rl   rm   r   r   r     s+     )E.(PT,!* !*r   r   textZplainapplicationzoctet-streamZinodeZblockdeviceZ
chardeviceZ	directoryZfifoZsocketZsymlinkZdoorZ
executableFc                  s   R s / s\        \        4      s\
        P                  ! \        P                  P                  RR4      4       FT  p \        V R4      ;_uu_ 4       pV F.  pVP                  4       P                  R^4      w  r4V\        V&   K0  	  RRR4       KV  	  \        4       s\
        P                  ! \        P                  P                  RR4      4       F  p \        P                  V 4       K  	  \        P!                  4        \#        4       s\
        P                  ! \        P                  P                  RR4      4       F  p \$        P                  V 4       K  	  \$        P!                  4        \
        P                  ! \        P                  P                  RR4      4       Fg  p \        V R4      ;_uu_ 4       pV FA  pVP                  4       P                  R^4      w  rV\        V,          P'                  V4       KC  	  RRR4       Ki  	  R#   + '       g   i     EK  ; i  + '       g   i     K  ; i)Tr   r.   rq   NZglobs2magicZ
subclasses)_cache_uptodater.   r   r4   r5   r    r$   r"   r#   r   r   r   r   r   r   r   r   r{   r   r   )r#   rY   rZ   Zaliasr0   ZsubZparents          r   _cache_databaser     s    OGc"K --bggll69.MN$__#'::<#5#5dA#> !*  _ O HE--bggll68.LM N	NN IE--bggll67.KL M	NN --bggll6<.PQ$__"jjl00q9C $$V,  _ R% __& __s   5HAH2H/2Ic                  s6    \         '       g   \        4        R # R # r   )r   r   rD   r   r   r-   r-   =  s    ? r   c                s@    \        4        \        P                  V 4      # )z6Returns type of file by its name, or None if not known)r-   r   r   )r#   r+   r   get_type_by_namer   A  s    NT""r   c                B    \        4        \        P                  WV4      # )z:Returns type of file by its contents, or None if not known)r-   r   rX   )r#   r   r   r   r   get_type_by_contentsr   F  s    N;;tg..r   c                r   )z0Returns type of the data, which should be bytes.)r-   r   r   )r   r   r   r   r   get_type_by_datar   L  s    ND733r   c                s   \         P                  ! V 4      '       d   \        # \         P                  ! V 4      '       d   \        # \         P
                  ! V 4      '       d   \        # \         P                  ! V 4      '       d   \        # \         P                  ! V 4      '       d   \        # \         P                  ! V 4      '       d   \        # \        # )z.Match special filesystem objects to Mimetypes.)statZS_ISDIR	inode_dirZS_ISCHR
inode_charZS_ISBLKinode_blockZS_ISFIFO
inode_fifoZS_ISLNKinode_symlinkZS_ISSOCKinode_socket
inode_door)st_moder+   r   _get_type_by_statr   R  s    ||GY.	g		z 1	g		{ 2	w		
!2	g		} 4	w		!4r   c                s"   \        4         V'       d   \        P                  ! V 4      pM\        P                  ! V 4      p \        P                  ! VP                  4      '       ds   \        WR7      pV'       g   \	        V 4      pV'       g   \        WR7      pVf:   \        P                  ! VP                  4      ^I,          '       d   \        # \
        # V# \        VP                  4      #    \	        T 4      pT;'       g    \
        u # ; i)a  Returns type of file indicated by path.

This function is *deprecated* - :func:`get_type2` is more accurate.

:param path: pathname to check (need not exist)
:param follow: when reading file, follow symbolic links
:param name_pri: Priority to do name matches. 100=override magic

This tries to use the contents of the file, and falls back to the name. It
can also handle special filesystem objects like directories and sockets.
)r   )r   )r-   r"   r   lstatr   r   S_ISREGr   r   S_IMODEapp_exer   )r#   followZname_pristr2   s   &&&  r   get_typer   \  s     NB$B
 ||BJJ 8&t,!*4B!9||BJJ'%// ,,!T"yyDs   C/ C/ /Dc                s   \        4         V'       d   \        P                  ! V 4      M\        P                  ! V 4      p\        P                  ! TP                  4      '       g   \        TP                  4      # \        \        P                  T 4      R RR7      pT'       dq   T^ ,          ^,          p^pTR,           F  w  rgYt8  d    MT^,          pK  	  TRT p\        T4      ^8X  d   T^ ,          ^ ,          # T UUu. uF  w  rgTNK	  	  pppMRp \        P                  YR7      p	T	'       d   T	# T'       d   T^ ,          ^ ,          # \        P"                  ! TP                  4      ^I,          '       d   \$        # \'        T 4      '       d   \(        # \        #   \         d    \        T 4      ;'       g    \        u # i ; iu uppi   \          d    Rp	 Li ; i)a  Find the MIMEtype of a file using the XDG recommended checking order.

This first checks the filename, then uses file contents if the name doesn't
give an unambiguous MIMEtype. It can also handle special filesystem objects
like directories and sockets.

:param path: file path to examine (need not exist)
:param follow: whether to follow symlinks

:rtype: :class:`MIMEtype`

.. versionadded:: 1.0
c                 s    V ^,          # )   rD   r   r+   r   r   Zget_type2.<locals>.<lambda>  s    AaDr   Tr   :r   NNN)r   )r-   r"   r   r   ZOSErrorr   octet_streamr   r   r   Zsortedr   r   rU   r   rX   r   r   r   is_text_filer   )
r#   r   r   mtypesZ
max_weightrf   r   wr   r2   rh   r   	get_type2r     s    N6$RWWT]"((4. <<

## ,,E%%d+.4PFAYq\
BZZEB~FA   v;!!9Q<#)*642B6*KKK0 		ay|	bjj	!E	)	)#D))t;|;G  6%5556& +  s/   4F  G
G  G=GGG G c                s     \        V R4      pT;_uu_ 4        \        TP                  ^ 4      4      uuRRR4       #   \         d     R# i ; i  + '       g   i     R# ; i)zGuess whether a file contains text or binary data.

Heuristic: binary if the first 32 bytes include ASCII control characters.
This rule may change in future versions.

.. versionadded:: 1.0
r~   FN)r   r   _is_textrt   )r#   rY   r   r   r   r     sO    t 
r
# 
   
s   = AAAA 	c                     \         ;QJ d&    R  V  4       F  '       g   K   R'       * # 	  R'       * # ! R  V  4       4      '       * # )c              3   s   "   T F4  q^8*  ;'       g$    ^Tu;8*  ;'       d    ^ 8  Mu ;'       g    V^8H  x  K6  	  R# 5i)i   NrD   r1   Zbr   r   r3   _is_text.<locals>.<genexpr>  s3     NACx??3!??d???a4i?s   >>>>TFrr   r   r+   r   r   r     s4    3NN33NN3NN3NNNNNr   c                 r   )c              3   s   "   T F5  pVR 8*  ;'       g$    RTu;8*  ;'       d    R8  Mu ;'       g    VR8H  x  K7  	  R# 5i)ZZZ ZNrD   r   r   r   r3   r     s?      +%) F{IIf&:&:F&:IIa6kI%)s   ????TFr   r   r+   r   r   r     sL    3 +%)+33 + 	+3 + 	+3 +%)+ + + 	+r   c                s   \        4        \        '       g`   \        \        4      s\
        P                  P                  4        F,  w  rV F!  w  r4\        V,          P                  V4       K#  	  K.  	  Rs\        V ,          # )a"  Retrieve the set of filename extensions matching a given MIMEtype.

Extensions are returned without a leading dot, e.g. 'py'. If no extensions
are registered for the MIMEtype, returns an empty set.

The extensions are stored in a cache the first time this is called.

.. versionadded:: 1.0
T)	r-   _mime2ext_cache_uptodater   r4   _mime2ext_cacher   r   r   r   )r   r   r   r   Zprios   &    r   get_extensionsr     sd     N##%c* ::++-KC%&**3/  & . $( 8$$r   c                s   V R,          p \        V4      ;_uu_ 4       pVP                  4       pRRR4       \        P                  P	                  RR4      p\        P                  P	                  W@4      p\
        P                  ! V4       F:  p \        V4      ;_uu_ 4       pVP                  4       pRRR4       XX8X  g   K9   R# 	  Rs\        P                  P	                  \
        P                  ! V4      V 4      p\        VR4      ;_uu_ 4       pVP                  X4       RRR4       Rp	\        P                  ! \        P                  W\
        P                  ! R4      4      '       d)   \        P                  ! V4       \        RV	,          4      hR#   + '       g   i     ELt; i  + '       g   i     EL; i    EK<  ; i  + '       g   i     L; i)	a  Copy 'package_file' as ``~/.local/share/mime/packages/<application>.xml.``
If package_file is None, install ``<app_dir>/<application>.xml``.
If already installed, does nothing. May overwrite an existing
file with the same name (if the contents are different)r   Nr   ZpackagesFr   zupdate-mime-databasezThe '%s' command returned an error code!
Make sure you have the freedesktop.org shared MIME package:
http://standards.freedesktop.org/shared-mime-info/)r   rt   r"   r#   r   r    r$   r   Zsave_data_pathZwriteZspawnlpZP_WAITZunlink	Exception)
r   Zpackage_filerY   Znew_dataZpackage_dirr'   r   Zold_dataZnew_fileZcommandrh   r   install_mime_infor     s`   
 6K	l		q668 
 '',,vz2Kww||K5H**84	aA668  x 5 O ww||M88E{SH 
h			 
 %G	zz"))W}/K/KF/STT
		( GIPQ R 	R U9 
		 	 
	sA   FG"F-3GG
F*	-F>8G>GG
G	r   )r   r   )Tr   )T);r?   r"   ri   r   rR   r   r&   r    Z
xdg.LocaleZxml.domr   r   Zcollectionsr   r%   r   r   r   r   r   rS   re   r	   r   Zobjectr
   r   rC   r   rE   rF   rn   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r-   r   r   r   r   r   r   r   r   r   r   r   r   rD   r   r   <module>r      s  * 
 	  
    * #
A

aC	$I5v I5V	Z 			 	i. i.X;F ;z\; \;|v*V v*r fgm^4Wm,G\*
7K(	GV$
gx(w	*GV$


- -D#
/4#-J5<n$  O+   %,'Rr   