
    Ki              	      ~   % 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  S SK	J
r
  S SKJrJr  S SKJr  S SKJr  S SKJrJrJrJrJrJr  \(       a  S SKrS S	KJr  \" S
5      rO\" S
5      r\" S5      r\R<                  " S5      r\
\ \ /\!4   r"\
\#\ \ 4   /\!4   r$ " S S5      r% " S S\%5      r& " S S\%5      r' " S S\%5      r( " S S\%5      r) " S S\%5      r* " S S\%5      r+ " S S\%5      r, " S S\\\4   5      r- " S S \%5      r.S\%0r/S!\0S"'   S$S%S# jjr1\%\&\*\'\)\(\+\,\.4	 H  r2\1" \25        M     g)&    )annotationsN)OrderedDict)Callable)FutureThreadPoolExecutor)groupby)
itemgetter)TYPE_CHECKINGAnyClassVarGeneric
NamedTupleTypeVar)	ParamSpecPTzfsspec.cachingc                  Z    \ rS rSr% SrSrS\S'   SS jrSS jrSS jr	SS	 jr
SS
 jrSrg)	BaseCache"   a;  Pass-though cache: doesn't keep anything, calls every time

Acts as base class for other cachers

Parameters
----------
blocksize: int
    How far to read ahead in numbers of bytes
fetcher: func
    Function of the form f(start, end) which gets bytes from remote as
    specified
size: int
    How big this file is
noneClassVar[str]namec                `    Xl         SU l        X l        X0l        SU l        SU l        SU l        g Nr   )	blocksizenblocksfetchersize	hit_count
miss_counttotal_requested_bytes)selfr   r   r   s       P/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/fsspec/caching.py__init__BaseCache.__init__4   s.    "	%&"    c                v    Uc  SnUc  U R                   nXR                   :  d  X:  a  gU R                  X5      $ )Nr   r&   )r   r   r"   startstops      r#   _fetchBaseCache._fetch>   s:    =E<99DII||E((r&   c                .    SU l         SU l        SU l        g)zAReset hit and miss counts for a more ganular report e.g. by file.r   N)r   r    r!   r"   s    r#   _reset_statsBaseCache._reset_statsG   s    %&"r&   c           	         U R                   S:X  a  U R                  S:X  a  gSU R                   SU R                    SU R                   SU R                   S3	$ )z2Return a formatted string of the cache statistics.r    z , z: z hits, z	 misses, z total requested bytes)r   r    r   r!   r.   s    r#   
_log_statsBaseCache._log_statsM   s^    >>Q4??a#7TYYKr$..!18ISWSmSmRn  oE  F  	Fr&   c                    SU R                   R                   SU R                   SU R                   SU R                   SU R
                   SU R                   SU R                   S3$ )	Nz

        <z:
            block size  :   z
            block count :   z
            file size   :   z
            cache hits  :   z
            cache misses:   z$
            total requested bytes: z
>
        )	__class____name__r   r   r   r   r    r!   r.   s    r#   __repr__BaseCache.__repr__T   s    

..
!
!	" #!^^, -!\\N +!YYK (!^^, -!__- .$$($>$>#? @	 	r&   )r   r   r   r    r   r   r!   Nr   intr   Fetcherr   r;   returnNoner)   
int | Noner*   r@   r=   bytesr=   r>   )r=   str)r7   
__module____qualname____firstlineno____doc__r   __annotations__r$   r+   r/   r3   r8   __static_attributes__ r&   r#   r   r   "   s-     !D- ')'F
r&   r   c                     ^  \ rS rSrSrSr   S
             SU 4S jjjrSS jrSS jrSS jr	SS jr
S	rU =r$ )	MMapCachea   a  memory-mapped sparse file cache

Opens temporary file, which is filled blocks-wise when data is requested.
Ensure there is enough disc space in the temporary location.

This cache method might only work on posix

Parameters
----------
blocksize: int
    How far to read ahead in numbers of bytes
fetcher: Fetcher
    Function of the form f(start, end) which gets bytes from remote as
    specified
size: int
    How big this file is
location: str
    Where to create the temporary file. If None, a temporary file is
    created using tempfile.TemporaryFile().
blocks: set[int]
    Set of block numbers that have already been fetched. If None, an empty
    set is created.
multi_fetcher: MultiFetcher
    Function of the form f([(start, end)]) which gets bytes from remote
    as specified. This function is used to fetch multiple blocks at once.
    If not specified, the fetcher function is used instead.
mmapc                   > [         TU ]  XU5        Uc
  [        5       OUU l        X@l        X`l        U R                  5       U l        g N)superr$   setblockslocationmulti_fetcher	_makefilecache)r"   r   r   r   rT   rS   rU   r6   s          r#   r$   MMapCache.__init__   s<     	T2%~ce6 *^^%
r&   c                D   SS K nSS KnU R                  S:X  a
  [        5       $ U R                  b.  [
        R                  R                  U R                  5      (       d  U R                  c   UR                  5       n[        5       U l
        O[        U R                  S5      nUR                  U R                  S-
  5        UR                  S5        UR                  5         O[        U R                  S5      nUR                   " UR                  5       U R                  5      $ )Nr   zwb+      1zr+b)rN   tempfiler   	bytearrayrT   ospathexistsTemporaryFilerR   rS   openseekwriteflushfileno)r"   rN   r\   fds       r#   rV   MMapCache._makefile   s    99>; == t}}(E(E}}$++-!e$--/GGDIIM"HHTNHHJdmmU+Byydii00r&   c                *  ^  [         R                  SU SU 35        Uc  SnUc  T R                  nUT R                  :  d  X:  a  gUT R                  -  nUT R                  -  n[	        X4S-   5      nU 4S jU 5       nT =R
                  [        U 4S jU 5       5      -  sl        / n[        [        U5      S S	9 H  u  p[        [        [        S5      U	5      5      n	U	S   T R                  -  n
[        U	S
   T R                  -  T R                  -   T R                  5      nT =R                  X-
  -  sl        [         R                  SU	S    SU	S
    SU
 SU S3	5        UR                  X45        T R                  R!                  U	5        T =R"                  [%        U	5      -  sl        M     U(       d  T R&                  X $ T R(                  (       ak  [         R                  SU 35        [        T R)                  U5      5       H4  u  pX|   u  p[         R                  SU
 SU 35        UT R&                  X& M6     OCU H=  u  p[         R                  SU
 SU 35        T R+                  X5      T R&                  X& M?     T R&                  X $ )NzMMap cache fetching -r   r&   rZ   c              3  J   >#    U  H  oTR                   ;  d  M  Uv   M     g 7frP   rS   .0ir"   s     r#   	<genexpr>#MMapCache._fetch.<locals>.<genexpr>   s     ?;a4;;*>;   #	#c              3  J   >#    U  H  oTR                   ;   d  M  S v   M     g7f)rZ   Nrl   rm   s     r#   rp   rq      s     IAT[[8Haarr   c                    U S   U S   -
  $ )Nr   rZ   rJ   )xs    r#   <lambda>"MMapCache._fetch.<locals>.<lambda>   s    1!r&   )keyzMMap get blocks z ()zMMap copy block (zMMap get block ()loggerdebugr   r   ranger   sumr   	enumeratetuplemapr	   minr!   appendrS   updater    lenrW   rU   r   )r"   r)   endstart_block	end_blockblock_rangeneedranges__blockssstartsendidxrs   `             r#   r+   MMapCache._fetch   sN   +E7!C59:=E;))CDIIt~~-4>>)	KQ7?;?#IIII ")D/7LMJAC
1w78GQZ$..0Fwr{T^^3dnnDdiiPD &&$-7&LL"71:,a}BvhavQO MM6.) KKw'OOs7|+O% N( ::e((LL+F845#D$6$6v$>?%{0$@A*+

6' @
 !'/xq?@*.,,v*D

6' !' zz%$$r&   c                @    U R                   R                  5       nUS	 U$ )NrW   )__dict__copyr"   states     r#   __getstate__MMapCache.__getstate__   s     ""$'Nr&   c                d    U R                   R                  U5        U R                  5       U l        g rP   )r   r   rV   rW   r   s     r#   __setstate__MMapCache.__setstate__   s"    U#^^%
r&   )rS   rW   rT   rU   )NNN)r   r;   r   r<   r   r;   rT   z
str | NonerS   zset[int] | NonerU   zMultiFetcher | Noner=   r>   )r=   zmmap.mmap | bytearrayr)   r@   r   r@   r=   rA   r=   dict[str, Any]r   r   r=   r>   )r7   rD   rE   rF   rG   r   r$   rV   r+   r   r   rI   __classcell__r6   s   @r#   rL   rL   a   s    8 D  $"&-1&& & 	&
 &  & +& 
& &1,<%|& &r&   rL   c                  >   ^  \ rS rSrSrSrSU 4S jjrSS jrSrU =r	$ )	ReadAheadCache   a  Cache which reads only when we get beyond a block of data

This is a much simpler version of BytesCache, and does not attempt to
fill holes in the cache or keep fragments alive. It is best suited to
many small reads in a sequential order (e.g., reading lines from a file).
	readaheadc                P   > [         TU ]  XU5        SU l        SU l        SU l        g )Nr&   r   )rQ   r$   rW   r)   r   r"   r   r   r   r6   s       r#   r$   ReadAheadCache.__init__   s'    T2

r&   c                T   Uc  SnUb  X R                   :  a  U R                   nXR                   :  d  X:  a  gX!-
  nXR                  :  aK  X R                  ::  a<  U =R                  S-  sl        U R                  XR                  -
  X R                  -
   $ U R                  Us=::  a  U R                  :  aN  O  OKU =R
                  S-  sl        U R                  XR                  -
  S  nU[        U5      -  nU R                  nOU =R
                  S-  sl        Sn[        U R                   X R                  -   5      nU =R                  X!-
  -  sl	        U R                  X5      U l        Xl        U R                  [        U R                  5      -   U l        X@R                  S U -   $ Nr   r&   rZ   )r   r)   r   r   rW   r    r   r   r   r!   r   )r"   r)   r   lparts        r#   r+   ReadAheadCache._fetch   sI   =E;#		/))CIIKJJ3((?NNaN::ejj033CDDZZ5+488+OOq O::ejj023DTNAHHE OOq OD$))S>>12""ck1"\\%-

::DJJ/jj!n$$r&   )rW   r   r)   r:   r   
r7   rD   rE   rF   rG   r   r$   r+   rI   r   r   s   @r#   r   r      s     D% %r&   r   c                  >   ^  \ rS rSrSrSrSU 4S jjrSS jrSrU =r	$ )	FirstChunkCachei  zCaches the first block of a file only

This may be useful for file types where the metadata is stored in the header,
but is randomly accessed.
firstc                B   > X:  a  Un[         TU ]  XU5        S U l        g rP   )rQ   r$   rW   r   s       r#   r$   FirstChunkCache.__init__&  s$    IT2#'
r&   c                l   U=(       d    SnXR                   :  a  [        R                  S5        g[        X R                   5      nXR                  :  Ga#  U R
                  c  U =R                  S-  sl        X R                  :  a?  U =R                  U-  sl        U R                  SU5      nUS U R                   U l        X1S  $ U R                  SU R                  5      U l        U =R                  U R                  -  sl        U R
                  X nX R                  :  a?  U =R                  X R                  -
  -  sl        X@R                  U R                  U5      -  nU =R                  S-  sl	        U$ U =R                  S-  sl        U =R                  X!-
  -  sl        U R                  X5      $ )Nr   z,FirstChunkCache: requested start > file sizer&   rZ   )
r   r{   r|   r   r   rW   r    r!   r   r   )r"   r)   r   datar   s        r#   r+   FirstChunkCache._fetch-  sR   
99LLGH#yy!>>!zz!1$'..#5.<<3/D!%&6!7DJ<'!\\!T^^<
**dnn<*::e(D^^#**cNN.BB*T^^S99NNaNKOOq O&&#+5&<<++r&   )rW   r:   r   r   r   s   @r#   r   r     s     D(, ,r&   r   c                     ^  \ rS rSrSrSr S         SU 4S jjjrS rSS jrSS jr	SS jr
SU 4S	 jjr          SS
 jrSrU =r$ )
BlockCacheiK  a  
Cache holding memory as a set of blocks.

Requests are only ever made ``blocksize`` at a time, and are
stored in an LRU cache. The least recently accessed block is
discarded when more than ``maxblocks`` are stored.

Parameters
----------
blocksize : int
    The number of bytes to store in each block.
    Requests are only ever made for ``blocksize``, so this
    should balance the overhead of making a request against
    the granularity of the blocks.
fetcher : Callable
size : int
    The total size of the file being cached.
maxblocks : int
    The maximum number of blocks to cache for. The maximum memory
    use for this cache is then ``blocksize * maxblocks``.

blockcachec                   > [         TU ]  XU5        [        R                  " X1-  5      U l        X@l        [        R                  " U5      " U R                  5      U l	        g rP   )
rQ   r$   mathceilr   	maxblocks	functools	lru_cache_fetch_block_fetch_block_cachedr"   r   r   r   r   r6   s        r#   r$   BlockCache.__init__d  sJ     	T2yy!12"#,#6#6y#A$BSBS#T r&   c                6    U R                   R                  5       $ zz
The statistics on the block cache.

Returns
-------
NamedTuple
    Returned directly from the LRU Cache used internally.
r   
cache_infor.   s    r#   r   BlockCache.cache_infol       ''2244r&   c                $    U R                   nUS	 U$ )Nr   r   r   s     r#   r   BlockCache.__getstate__w  s    '(r&   c                    U R                   R                  U5        [        R                  " US   5      " U R                  5      U l        g )Nr   )r   r   r   r   r   r   r   s     r#   r   BlockCache.__setstate__|  s:    U##,#6#6u[7I#J$
 r&   c                    Uc  SnUc  U R                   nXR                   :  d  X:  a  gU R                  XXR                  -  US-
  U R                  -  5      $ r   )r   _read_cacher   )r"   r)   r   s      r#   r+   BlockCache._fetch  sY    =E;))CII/#'dnn1L
 	
r&   c                8  > XR                   :  a  [        SU SU R                    S35      eXR                  -  nX R                  -   nU =R                  X2-
  -  sl        U =R                  S-  sl        [
        R                  SU5        [        TU ]!  X#5      nU$ )-
Fetch the block of data for `block_number`.
'block_number=(' is greater than the number of blocks (rz   rZ   zBlockCache fetching block %d)	r   
ValueErrorr   r!   r    r{   inforQ   r+   )r"   block_numberr)   r   block_contentsr6   s        r#   r   BlockCache._fetch_block  s     ,,&  /))-a9 
 ~~-nn$""ck1"12LA3r&   c           	        XR                   -  nX R                   -  nUS:X  a  U R                   nU =R                  S-  sl        X4:X  a  U R                  U5      nXuU $ U R                  U5      US /nUR                  [	        U R                  [        US-   U5      5      5        UR                  U R                  U5      SU 5        SR                  U5      $ )
Read from our block cache.

Parameters
----------
start, end : int
    The start and end byte positions.
start_block_number, end_block_number : int
    The start and end block numbers.
r   rZ   Nr&   r   r   r   extendr   r}   r   join	r"   r)   r   start_block_numberend_block_number	start_posend_posblockouts	            r#   r   BlockCache._read_cache  s     NN*	&a<nnG!1334FGE7++ ++,>?	
KLC
 JJ,,,q02BC JJt//0@A(7KL88C= r&   )r   r   r       
r   r;   r   r<   r   r;   r   r;   r=   r>   r   r   r   )r   r;   r=   rA   
r)   r;   r   r;   r   r;   r   r;   r=   rA   )r7   rD   rE   rF   rG   r   r$   r   r   r   r+   r   r   rI   r   r   s   @r#   r   r   K  s    , D MOUU'.U69UFIU	U U	5



$(!(!"(!8;(!OR(!	(! (!r&   r   c                  l   ^  \ rS rSr% SrSrS\S'    S
         SU 4S jjjrSS jrSS jr	S	r
U =r$ )
BytesCachei  a+  Cache which holds data in a in-memory bytes object

Implements read-ahead by the block size, for semi-random reads progressing
through the file.

Parameters
----------
trim: bool
    As we read more data, whether to discard the start of the buffer when
    we are more than a blocksize ahead of it.
rA   r   r   c                \   > [         TU ]  XU5        SU l        S U l        S U l        X@l        g )Nr&   )rQ   r$   rW   r)   r   trim)r"   r   r   r   r   r6   s        r#   r$   BytesCache.__init__  s.     	T2
!%
#	r&   c                   Uc  SnUc  U R                   nXR                   :  d  X:  a  gU R                  bb  XR                  :  aS  U R                  bF  X R                  :  a7  XR                  -
  nU =R                  S-  sl        U R                  X3U-   U-
   $ U R
                  (       a#  [        U R                   X R
                  -   5      nOUnXA:X  d  XR                   :  a  gU R                  b  XR                  :  af  U R                  b  X R                  :  aJ  U =R                  XA-
  -  sl        U =R                  S-  sl        U R                  X5      U l        Xl        GOU R                  c   eU R                  c   eU =R                  S-  sl        XR                  :  a  U R                  b  U R                  U-
  U R
                  :  a5  U =R                  XA-
  -  sl        U R                  X5      U l        Xl        GO/U =R                  U R                  U-
  -  sl        U R                  XR                  5      nXl        XPR                  -   U l        OU R                  b  X@R                  :  a  U R                  U R                   :  a  OX R                  -
  U R
                  :  a4  U =R                  XA-
  -  sl        U R                  X5      U l        Xl        OQU =R                  X@R                  -
  -  sl        U R                  U R                  U5      nU R                  U-   U l        U R                  [        U R                  5      -   U l        XR                  -
  nU R                  X3U-   U-
   nU R                  (       ar  U R                  U R                  -
  U R
                  S-   -  nUS:  aC  U =R                  U R
                  U-  -  sl        U R                  U R
                  U-  S  U l        U$ r   )r   r)   r   r   rW   r   r   r!   r    r   r   r   )r"   r)   r   offsetbendnewr   nums           r#   r+   BytesCache._fetch  s    =E;))CIIJJ"#$hh ZZ'FNNaN::f|e';<<>>tyy#"67DD=EII-JJ%**"4HHhh &&$,6&OOq Oe2DJJ::)))88'''OOq Ozz!88#txx#~'F..$,>.!%e!:DJ!&J..$**u2DD.,,ujj9C!&J!$zz!1DJ%$/88dii'88^dnn4..$,>.!%e!:DJ!&J..$/A.,,txx6C!%c!1DJ::DJJ/#jj3,"679988djj(dnnq.@ACQw

dnns22
!ZZ(<(>?

r&   c                ,    [        U R                  5      $ rP   )r   rW   r.   s    r#   __len__BytesCache.__len__,  s    4::r&   )rW   r   r)   r   )T)
r   r;   r   r<   r   r;   r   boolr=   r>   r   )r=   r;   )r7   rD   rE   rF   rG   r   rH   r$   r+   r   rI   r   r   s   @r#   r   r     s^    
 "D-! IM'.69AE	 GR r&   r   c                  h   ^  \ rS rSr% SrSrS\S'       S	         S
U 4S jjjrSS jrSr	U =r
$ )AllBytesi0  z!Cache entire contents of the fileallr   r   c                   > [         TU ]  XU5        UcP  U =R                  S-  sl        U =R                  U R                  -  sl        U R                  SU R                  5      nX@l        g )NrZ   r   )rQ   r$   r    r!   r   r   r   )r"   r   r   r   r   r6   s        r#   r$   AllBytes.__init__5  sU     	T2<OOq O&&$))3&<<499-D	r&   c                H    U =R                   S-  sl         U R                  X $ )NrZ   )r   r   r(   s      r#   r+   AllBytes._fetchC  s    !yy$$r&   )r   )NNNN)
r   r@   r   zFetcher | Noner   r@   r   zbytes | Noner=   r>   r?   )r7   rD   rE   rF   rG   r   rH   r$   r+   rI   r   r   s   @r#   r   r   0  sb    +D- !%"&!   	
  
 % %r&   r   c                     ^  \ rS rSr% SrSrS\S'     S           SU 4S jjjr\S 5       r	\	R                  S 5       r	\S	 5       r\R                  S
 5       rSS jrSrU =r$ )KnownPartsOfAFileiH  aq  
Cache holding known file parts.

Parameters
----------
blocksize: int
    How far to read ahead in numbers of bytes
fetcher: func
    Function of the form f(start, end) which gets bytes from remote as
    specified
size: int
    How big this file is
data: dict
    A dictionary mapping explicit `(start, stop)` file-offset tuples
    with known bytes.
strict: bool, default True
    Whether to fetch reads that go beyond a known byte-range boundary.
    If `False`, any read that ends outside a known part will be zero
    padded. Note that zero padding will not be used for reads that
    begin outside a known byte-range.
partsr   r   c                  > [         TU ]  XU5        XPl        U(       a  [        UR	                  5       5      nUS   /nUR                  US   5      /n	USS   Hi  u  pUS   u  pX:X  a%  X4US'   U	S==   UR                  X45      -  ss'   M6  UR                  X45        U	R                  UR                  X45      5        Mk     [        [        X5      5      U l	        g 0 U l	        g )Nr   rZ   ry   )
rQ   r$   strictsortedkeyspopr   dictzipr   )r"   r   r   r   r   r  r   old_offsetsoffsetsrS   r)   r*   start0stop0r6   s                 r#   r$   KnownPartsOfAFile.__init__a  s     	T2  -K"1~&Ghh{1~./F*12 '>#).GBK2J$((E="99JNNE=1MM$((E="9:  / S12DIDIr&   c                :    [        S U R                   5       5      $ )Nc              3  6   #    U  H  oS    US   -
  v   M     g7f)rZ   r   NrJ   )rn   r   s     r#   rp   )KnownPartsOfAFile.size.<locals>.<genexpr>  s     2	1Q4!A$;	s   )r~   r   r.   s    r#   r   KnownPartsOfAFile.size  s    2		222r&   c                    g rP   rJ   r"   values     r#   r   r        r&   c                ,    [        U R                  5      $ rP   )r   r   r.   s    r#   r   KnownPartsOfAFile.nblocks  s    499~r&   c                    g rP   rJ   r  s     r#   r   r    r  r&   c                   [         R                  SX5        Uc  SnUc  U R                  nU =R                  X!-
  -  sl        SnSnSn[	        U R
                  5       GHV  u  pgXas=::  a  U:  aE  O  OBXbs=::  a  U::  a6  O  O3X-
  nU =R                  S-  sl        U R
                  Xg4   XU-   U-
   s  $ X&::  a    OU(       a;  Xe:  a6  U =R                  S-  sl        U R                  (       a  [        eUSXe-
  -  -  nXas=::  a  U:  a7  O  O4U =R                  S-  sl        X-
  nU R
                  Xg4   XU-   U-
   nSnOqX:  a-  X':  a(  U =R                  S-  sl        X0R
                  Xg4   -  nO?Xbs=::  a  U::  a3  O  O0U =R                  S-  sl        X0R
                  Xg4   S X&-
   -   nUs  $ UnGMY     U =R                  S-  sl        U(       a  U R                  (       d  USX%-
  -  -   nU$ [        e)NzKnown parts request %s %sr   r&   FrZ       T)
r{   r|   r   r!   r  r   r   r    r  r   )	r"   r)   r*   r   startedloc_oldloc0loc1offs	            r#   r+   KnownPartsOfAFile._fetch  s   0%>=E<99D""dl2" +JD$$4+?4+?l!#yy$.s4Z%5GHH|4>1$;;$$w$.11#t#!#lii-c$J4FG$+!#yy$..%%!#IItl3MdkBB
G; ,< 	14;;4>22CJr&   )r   r  )NF)r   r;   r   r<   r   r;   r   z#dict[tuple[int, int], bytes] | Noner  r   r   r   r?   )r7   rD   rE   rF   rG   r   rH   r$   propertyr   setterr   r+   rI   r   r   s   @r#   r  r  H  s    , "D-! 59  	
 2   < 3 3 
[[    ^^ , ,r&   r  c                  d    \ rS rSrSr " S S\5      rSSS jjrSS jrSS jr	SS jr
SS	 jrS
rg)UpdatableLRUi  z[
Custom implementation of LRU cache that allows updating keys

Used by BackgroudBlockCache
c                  >    \ rS rSr% S\S'   S\S'   S\S'   S\S'   Srg)	UpdatableLRU.CacheInfoi  r;   hitsmissesmaxsizecurrsizerJ   N)r7   rD   rE   rF   rH   rI   rJ   r&   r#   	CacheInfor*    s    	r&   r/  c                    [         R                  " 5       U l        Xl        X l        SU l        SU l        [        R                  " 5       U l	        g r   )
collectionsr   _cache_func	_max_size_hits_misses	threadingLock_lock)r"   funcmax_sizes      r#   r$   UpdatableLRU.__init__  s8    +6+B+B+D
!
^^%
r&   c                x   U(       a  [        SUR                  5        35      eU R                     XR                  ;   aH  U R                  R	                  U5        U =R
                  S-  sl        U R                  U   sS S S 5        $  S S S 5        U R                  " U0 UD6nU R                     X0R                  U'   U =R                  S-  sl        [        U R                  5      U R                  :  a  U R                  R                  SS9  S S S 5        U$ ! , (       d  f       N= f! , (       d  f       U$ = f)Nz Got unexpected keyword argument rZ   Flast)	TypeErrorr	  r9  r2  move_to_endr5  r3  r6  r   r4  popitem)r"   argskwargsresults       r#   __call__UpdatableLRU.__call__  s    >v{{}oNOOZZ{{"''-

a
{{4(	 Z"  T,V,ZZ &KKLLAL4;;$..0###/	   Z Z s   AD/A D*
D'*
D9c                l    U R                      XR                  ;   sS S S 5        $ ! , (       d  f       g = frP   )r9  r2  )r"   rC  s     r#   is_key_cachedUpdatableLRU.is_key_cached  s    ZZ;;& ZZs   %
3c                    U R                      XR                  U'   [        U R                  5      U R                  :  a  U R                  R	                  SS9  S S S 5        g ! , (       d  f       g = f)NFr>  )r9  r2  r   r4  rB  )r"   rE  rC  s      r#   add_keyUpdatableLRU.add_key  sI    ZZ &KK4;;$..0###/ ZZs   AA!!
A/c                    U R                      U R                  U R                  [        U R                  5      U R
                  U R                  S9sS S S 5        $ ! , (       d  f       g = f)N)r-  r.  r+  r,  )r9  r/  r4  r   r2  r5  r6  r.   s    r#   r   UpdatableLRU.cache_info  sE    ZZ>>T[[)ZZ||	 "  ZZs   AA
A()r2  r3  r5  r9  r4  r6  N)   )r:  zCallable[P, T]r;  r;   r=   r>   )rC  zP.argsrD  zP.kwargsr=   r   )rC  r   r=   r   )rE  r   rC  r   r=   r>   r=   r*  )r7   rD   rE   rF   rG   r   r/  r$   rF  rI  rL  r   rI   rJ   r&   r#   r(  r(    s,    J &&'0r&   r(  c                     ^  \ rS rSr% SrSrS\S'    S         SU 4S jjjrSS jrSS jr	SS	 jr
SS
 jrSSU 4S jjjr          SS jrSrU =r$ )BackgroundBlockCachei  a/  
Cache holding memory as a set of blocks with pre-loading of
the next block in the background.

Requests are only ever made ``blocksize`` at a time, and are
stored in an LRU cache. The least recently accessed block is
discarded when more than ``maxblocks`` are stored. If the
next block is not in cache, it is loaded in a separate thread
in non-blocking way.

Parameters
----------
blocksize : int
    The number of bytes to store in each block.
    Requests are only ever made for ``blocksize``, so this
    should balance the overhead of making a request against
    the granularity of the blocks.
fetcher : Callable
size : int
    The total size of the file being cached.
maxblocks : int
    The maximum number of blocks to cache for. The maximum memory
    use for this cache is then ``blocksize * maxblocks``.

backgroundr   r   c                  > [         TU ]  XU5        [        R                  " X1-  5      U l        X@l        [        U R                  U5      U l        [        SS9U l
        S U l        S U l        [        R                  " 5       U l        g )NrZ   max_workers)rQ   r$   r   r   r   r   r(  r   r   r   _thread_executor_fetch_future_block_number_fetch_futurer7  r8  _fetch_future_lockr   s        r#   r$   BackgroundBlockCache.__init__  sm     	T2yy!12"#/0A0A9#M  2q A6:'37"+.."2r&   c                6    U R                   R                  5       $ r   r   r.   s    r#   r   BackgroundBlockCache.cache_info#  r   r&   c                <    U R                   nUS	 US	 US	 US	 US	 U$ )Nr   rX  rY  rZ  r[  r   r   s     r#   r   !BackgroundBlockCache.__getstate__.  s<    '($%.//"&'r&   c                    U R                   R                  U5        [        U R                  US   5      U l        [        SS9U l        S U l        S U l        [        R                  " 5       U l        g )Nr   rZ   rV  )r   r   r(  r   r   r   rX  rY  rZ  r7  r8  r[  r   s     r#   r   !BackgroundBlockCache.__setstate__7  sZ    U##/0A0A5CU#V  2q A*.'!"+.."2r&   c                   Uc  SnUc  U R                   nXR                   :  d  X:  a  gXR                  -  nX R                  -  nS nS nU R                     U R                  b  U R                  c   eU R                  R                  5       (       ab  [        R                  S5        U R                  R                  U R                  R                  5       U R                  5        S U l        S U l        OU[        UU R                  s=:*  =(       a    U:*  Os  5      nU(       a&  U R                  nU R                  nS U l        S U l        S S S 5        Ub?  [        R                  S5        U R                  R                  UR                  5       U5        [        X4S-   5       H  nU R                  U5        M     US-   n	U R                     U R                  ca  XR                  ::  aR  U R                  R                  U	5      (       d2  Xl        U R                  R!                  U R"                  U	S5      U l        S S S 5        U R%                  UUUUS9$ ! , (       d  f       GN= f! , (       d  f       N2= f)Nr   r&   z3BlockCache joined background fetch without waiting.z(BlockCache waiting for background fetch.rZ   async)r   r   )r   r   r[  rZ  rY  doner{   r   r   rL  rE  r   r}   r   rI  rX  submitr   r   )
r"   r)   r   r   r   fetch_future_block_numberfetch_future	must_joinr   end_block_plus_1s
             r#   r+   BackgroundBlockCache._fetch?  sH   =E;))CII #nn4..0$(!$$!!-66BBB%%**,,KK UV,,44**113T5T5T 7;D3)-D& !%*::, ,+,!I
 ! 594S4S1'+'9'9 ;?7-1*7 %< #KKBC$$,,##%'@
 ""46JKL$$\2 L
 ,a/$$""*$400>>?OPP2B/%)%:%:%A%A%%'7&" % 1-	   
 	
o %$X %$s   C3I
A/I%
I"%
I3c                8  > XR                   :  a  [        SU SU R                    S35      eXR                  -  nX0R                  -   n[        R	                  SX!5        U =R
                  XC-
  -  sl        U =R                  S-  sl        [        TU ]!  X45      nU$ )r   r   r   rz   z!BlockCache fetching block (%s) %drZ   )	r   r   r   r{   r   r!   r    rQ   r+   )r"   r   log_infor)   r   r   r6   s         r#   r   !BackgroundBlockCache._fetch_block  s     ,,&  /))-a9 
 ~~-nn$7P""ck1"13r&   c           	        XR                   -  nX R                   -  nU =R                  S-  sl        X4:X  a  U R                  U5      nXuU $ U R                  U5      US /nUR                  [	        U R                  [        US-   U5      5      5        UR                  U R                  U5      SU 5        SR                  U5      $ )r   rZ   Nr&   r   r   s	            r#   r    BackgroundBlockCache._read_cache  s     NN*	& 	!1,,-?@E7++ ++,>?	
KLC
 JJ,,,q02BC JJt//0@A(7KL88C= r&   )r   rZ  rY  r[  rX  r   r   r   r   rQ  r   rB   r   )sync)r   r;   rm  rC   r=   rA   r   )r7   rD   rE   rF   rG   r   rH   r$   r   r   r   r+   r   r   rI   r   r   s   @r#   rS  rS    s    2 'D-& MO33'.3693FI3	3 3	53J
X $(!(!"(!8;(!OR(!	(! (!r&   rS  z!dict[str | None, type[BaseCache]]cachesc                    U R                   nU(       d#  U[        ;   a  [        SU< S[        U    35      eU [        U'   g)z'Register' cache implementation.

Parameters
----------
clobber: bool, optional
    If set to True (default is False) - allow to overwrite existing
    entry.

Raises
------
ValueError
zCache with name z is already known: N)r   rr  r   )clsclobberr   s      r#   register_cacherv    s=     88Dtv~+D83Fvd|nUVVF4Lr&   )F)rt  ztype[BaseCache]ru  r   r=   r>   )3
__future__r   r1  r   loggingr   r^   r7  r   collections.abcr   concurrent.futuresr   r   	itertoolsr   operatorr	   typingr
   r   r   r   r   r   rN   typing_extensionsr   r   r   	getLoggerr{   r;   rA   r<   listMultiFetcherr   rL   r   r   r   r   r   r  r(  rS  rr  rH   rv  crJ   r&   r#   <module>r     sr   "     	  # $ 9   M M+#AACL 
		+	,
C:u$
%c3h(%/0< <~K&	 K&\+%Y +%\+,i +,\}! }!@b bJ%y %0s	 sl971a4= 9xK!9 K!` 	)-) ( 

A 1

r&   