
    i=                      L   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJrJ	r	J
r
  SSKJr  SSKJrJr  SSKrSSKJr  \R&                  " \5      rSq\" S5      rS	\4S
 jrS	\4S jr " S S5      rS\R8                  S\S\S-  S	\4S jrS\\\\	4   -  S	\4S jr S\S	S4S jr!g)zHelpers.    N)CallableHashableIterable)Path)TypeVarcast)FileLockFTreturnc                      SSK Jn   SU -   n[        R                  R                  [        R                  5      n[        R                  " [        R                  R                  S5      SS9R                  5       SS	 nS
R                  [        R                  SS  Vs/ s H  n[        U5      PM     sn5      nUUUU/nSR                  U5      nU$ ! [         a    Sn  Nf = fs  snf )zGenerate an identifier unique to the python version, tldextract version, and python instance.

This will prevent interference between virtualenvs and issues that might arise when installing
a new version of tldextract
r   )versiondevztldextract-utf-8FusedforsecurityN   .__)tldextract._versionr   ImportErrorospathbasenamesysprefixhashlibmd5encode	hexdigestjoinversion_infostr)r   tldextract_versionpython_env_namepython_binary_path_short_hashvpython_versionidentifier_partspkg_identifiers           T/home/kali/github-search/github-env/lib/python3.13/site-packages/tldextract/cache.pyget_pkg_unique_identifierr,      s    / '0gg&&szz2O$+KK

'"E%ik"1%! XXs/?/?/DE/D!s1v/DEFN%	 YY/0N%   Fs   C C$C! C!c                     [         R                  R                  SS5      n U b  U $ [         R                  " SS5      nUc3  [         R                  " SS5      nU(       a  [	        [        US5      5      nUb  [	        [        US[        5       5      5      $ [	        [        [         R                  R                  [        5      S5      5      $ )zGet a cache dir that we have permission to write to.

Try to follow the XDG standard, but if that doesn't work fallback to the package directory
http://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
TLDEXTRACT_CACHENXDG_CACHE_HOMEHOMEz.cachezpython-tldextractz.suffix_cache)
r   environgetgetenvr#   r   r,   r   dirname__file__)	cache_dirxdg_cache_home	user_homes      r+   get_cache_dirr9   7   s     

148IYY/6NIIfd+	 i!:;N!!46O6QR
 	

 tBGGOOH-?@@    c            
       &   \ rS rSrSrSS\S-  S\4S jjrS\S\\\\	4   -  S	\
4S
 jrS\S\\\\	4   -  S\
S	S4S jrSS jrS\S\\\\	4   -  S	\4S jrS\S\4   S\S\\\	4   S\\   S	\4
S jrS\R(                  S\S\\-  S-  S	\4S jrSrg)	DiskCacheP   z0Disk _cache that only works for jsonable values.r6   Nlock_timeoutc                     [        U5      U l        [        R                  R	                  [        U5      =(       d    S5      U l        X l        SU l        g)z.Construct a disk cache in the given directory. z.tldextract.jsonN)	boolenabledr   r   
expanduserr#   r6   r>   file_ext)selfr6   r>   s      r+   __init__DiskCache.__init__S   s;    I++C	N,@bA( +r:   	namespacekeyr   c                    U R                   (       d  [        S5      eU R                  X5      n[        R                  R                  U5      (       d  [        SU-   S-   [        U5      -   5      e [        U5       n[        R                  " U5      sSSS5        $ ! , (       d  f       g= f! [        [        4 a#  n[        SU-   S-   [        U5      -   5      UeSnAff = f)z%Retrieve a value from the disk cache.zCache is disabledznamespace: z key: N)rB   KeyError_key_to_cachefile_pathr   r   isfilerepropenjsonloadOSError
ValueError)rE   rH   rI   cache_filepath
cache_fileexcs         r+   r2   DiskCache.get\   s    ||.//44YDww~~n--=94x?$s)KLL	Vn%yy, &%%$ 	V=94x?$s)KLRUU	Vs6   0B, ;B	B, 
B)%B, )B, ,C<CCvaluec                 ^   U R                   (       d  gU R                  X5      n [        U5        [        US5       n[        R
                  " X55        SSS5        g! , (       d  f       g= f! [         a5  n[        (       d   [        R                  SUUUU5        Sq SnAg SnAgSnAff = f)zSet a value in the disk cache.Nwunable to cache %s.%s in %s. This could refresh the Public Suffix List over HTTP every app startup. Construct your `TLDExtract` with a writable `cache_dir` or set `cache_dir=None` to silence this warning. %sT)
rB   rL   	_make_dirrO   rP   dumprR   _DID_LOG_UNABLE_TO_CACHELOGwarning)rE   rH   rI   rX   rT   rU   ioes          r+   setDiskCache.setj   s     ||44YD	0n%nc*j		%, +** 	0++G "	 ,0( ,	0s4   A- AA- 
A*&A- *A- -
B,7&B''B,c           
         [         R                  " U R                  5       H}  u  pnU Hq  nUR                  U R                  5      (       d%  UR                  U R                  S-   5      (       d  MH   [         R
                  " [        [        X5      5      5        Ms     M     g! [         a     M  [         a*  nUR                  [        R                  :w  a  e  SnAM  SnAff = f)zClear the disk cache..lockN)r   walkr6   endswithrD   unlinkr#   r   FileNotFoundErrorrR   errnoENOENT)rE   root_filesfilenamerV   s         r+   clearDiskCache.clear   s     ggdnn5NDU!$$T]]33x7H7HMMG+8 8"		#d4&:";< " 6 - " " 994! 5"s   2(B##
C#0	C#9CC#c                     [        [        U R                  U5      5      n[        U5      n[        [        X4U R                  -   5      5      nU$ )N)r#   r   r6   _make_cache_keyrD   )rE   rH   rI   namespace_path
hashed_key
cache_paths         r+   rL    DiskCache._key_to_cachefile_path   sA     T$..)<=$S)
n4==.HIJ
r:   func.kwargshashed_argnamesc           	      P   U R                   (       d  U" S0 UD6$ UR                  5        VVs0 s H  u  pVXT;   d  M  XV_M     nnnU R                  X'5      nUS-   n	 [        U5        [        XR                  S9    [        [        U R                  X'S95      nUsSSS5        $ s  snnf ! [         a8  n
[
        (       d  [        R                  SUUUU
5        SqU" S0 UD6s Sn
A
$ Sn
A
ff = f! [         a    U" S0 UD6nU R                  X'US9   Nzf = f! , (       d  f       g= f)	!Get a url but cache the response.re   r[   TNtimeout)rH   rI   )rH   rI   rX    )rB   itemsrL   r\   rR   r^   r_   r`   r	   r>   r   r
   r2   rK   rb   )rE   rx   rH   ry   rz   kr'   key_argsrT   	lock_pathra   results               r+   run_and_cacheDiskCache.run_and_cache   s%    ||>&>!%+\\^L^TQq7KDAD^L44YI"W,		"n%$ i):):;JaI!LM
  <;- M
  	"++G "	 ,0(>&>!	"(  J9&IJ <;sX   B$B$B* :D<C/D*
C,4-C'!C,'C,/"DDDD
D%sessionurlr~   c                 6    U R                  [        SXUS.S/S9$ )r|   urls)r   r   r~   r   )rx   rH   ry   rz   )r   
_fetch_url)rE   r   r   r~   s       r+   cached_fetch_urlDiskCache.cached_fetch_url   s/     !!&wG"G	 " 
 	
r:   )r6   rB   rD   r>   )   )r   N)__name__
__module____qualname____firstlineno____doc__r#   intrF   dictr   objectr2   rb   rp   rL   r   r
   r   r   requestsSessionfloatr   __static_attributes__r   r:   r+   r<   r<   P   s+   :+#* +C +VS VsT#x--@'@ VV V00#&c8m)<#<0EK0	08""#&c8m)<#<	(sAv( ( S(]#	(
 "#( 
(T	
''	
.1	
<ACK$<N	
		
r:   r<   r   r   r~   c                     U R                  XS9nUR                  5         UR                  n[        U[        5      (       d  [	        US5      nU$ )Nr}   r   )r2   raise_for_statustext
isinstancer#   )r   r   r~   responser   s        r+   r   r      sE    {{3{0H==DdC  4!Kr:   inputsc                 |    [        U 5      n[        R                  " UR                  S5      SS9R	                  5       $ )Nutf8Fr   )rN   r   r   r   r    )r   rI   s     r+   rs   rs      s.    
v,C;;szz&)5AKKMMr:   ro   c                 \   [         R                  R                  [         R                  R                  U 5      5      (       d5   [         R                  " [         R                  R                  U 5      5        gg! [
         a)  nUR                  [        R                  :w  a  e  SnAgSnAff = f)z-Make a directory if it doesn't already exist.N)r   r   existsr4   makedirsrR   rj   EEXIST)ro   rV   s     r+   r\   r\      so    77>>"''//(344	KK12 5  	yyELL( )	s   3A8 8
B+B&&B+)"r   rj   r   rP   loggingr   r   collections.abcr   r   r   pathlibr   typingr   r   r   filelockr	   	getLoggerr   r_   r^   r
   r#   r,   r9   r<   r   r   r   r   rs   r\   r   r:   r+   <module>r      s         	 
 8 8 
  !  CL3 :As A2D
 D
N(( s S4Z C NC$sH}"55 N# N
  r:   