
    !ha                        S r SSKJ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S
 jrSS jr " S S5      rSS jrSS jrSS jrg)zHelpers.    )annotationsN)CallableHashableIterable)Path)TypeVarcast)FileLockFTc                     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           W/root/1688_scrapy/alibaba-scraper/venv/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   9   s     

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

 tBGGOOH-?@@    c                      \ rS rSrSrSSS jjrSS jr        SS jrSS jr      SS jr	          SS jr
        SS	 jrS
rg)	DiskCacheR   z0Disk _cache that only works for jsonable values.c                    [        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   lock_timeoutfile_ext)selfr6   rC   s      r+   __init__DiskCache.__init__U   s;    I++C	N,@bA( +r:   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)rA   KeyError_key_to_cachefile_pathr   r   isfilerepropenjsonloadOSError
ValueError)rE   	namespacekey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c                ^   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)
rA   rJ   	_make_dirrM   rN   dumprP   _DID_LOG_UNABLE_TO_CACHELOGwarning)rE   rR   rS   valuerT   rU   ioes          r+   setDiskCache.setl   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   FileNotFoundErrorrP   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   rR   rS   namespace_path
hashed_key
cache_paths         r+   rJ    DiskCache._key_to_cachefile_path   sA     T$..)<=$S)
n4==.HIJ
r:   c           	     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   rZ   TNtimeout)rR   rS   )rR   rS   r`    )rA   itemsrJ   r[   rP   r]   r^   r_   r
   rC   r	   r   r2   rI   rb   )rE   funcrR   kwargshashed_argnames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%c                6    U R                  [        SXUS.S/S9$ )ry   urls)sessionurlr{   r   )r~   rR   r   r   )r   
_fetch_url)rE   r   r   r{   s       r+   cached_fetch_urlDiskCache.cached_fetch_url   s/     !!&wG"G	 " 
 	
r:   )r6   rA   rD   rC   N)   )r6   z
str | NonerC   int)rR   r#   rS   str | dict[str, Hashable]returnobject)rR   r#   rS   r   r`   r   r   None)r   r   )rR   r#   rS   r   r   r#   )
r~   zCallable[..., T]rR   r#   r   zdict[str, Hashable]r   zIterable[str]r   r   )r   requests.Sessionr   r#   r{   zfloat | int | Noner   r#   )__name__
__module____qualname____firstlineno____doc__rF   r2   rb   rp   rJ   r   r   __static_attributes__r|   r:   r+   r<   r<   R   s    :+V00#<0EK0	08""#<	(( ( $	(
 '( 
(T	
'	
.1	
<N	
		
r:   r<   c                    U R                  XS9nUR                  5         UR                  n[        U[        5      (       d  [	        US5      nU$ )Nrz   r   )r2   raise_for_statustext
isinstancer#   )r   r   r{   responser   s        r+   r   r      sE    {{3{0H==DdC  4!Kr:   c                |    [        U 5      n[        R                  " UR                  S5      SS9R	                  5       $ )Nutf8Fr   )rL   r   r   r   r    )inputsrS   s     r+   rs   rs      s.    
v,C;;szz&)5AKKMMr:   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   makedirsrP   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   r#   )r   r   r   r#   r{   z
int | Noner   r#   )r   r   r   r#   )ro   r#   r   r   ) r   
__future__r   rj   r   rN   loggingr   r   collections.abcr   r   r   pathlibr   typingr   r	   requestsfilelockr
   	getLoggerr   r^   r]   r   r,   r9   r<   r   rs   r[   r|   r:   r+   <module>r      sz     "     	 
 8 8 
  !  CL:A2D
 D
NN
r:   