
    7Th              	      z   % 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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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r0S\1S '   S"S#S! jjr2\&\'\+\(\*\)\,\-\/4	 H  r3\2" \35        M     g)$    )annotationsN)FutureThreadPoolExecutor)groupby)
itemgetter)	TYPE_CHECKINGAnyCallableClassVarGeneric
NamedTupleOptionalOrderedDictTypeVar)	ParamSpecPTfsspecc                  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       F/var/www/auris/envauris/lib/python3.13/site-packages/fsspec/caching.py__init__BaseCache.__init__=   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._fetchG   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_statsP   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#   r0   s    r%   
_log_statsBaseCache._log_statsV   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#   r0   s    r%   __repr__BaseCache.__repr__]   s    

..
!
!	" #!^^, -!\\N +!YYK (!^^, -!__- .$$($>$>#? @	 	r(   )r   r   r!   r"   r   r    r#   Nr   intr   Fetcherr    r=   returnNoner+   
int | Noner,   rB   r?   bytesr?   r@   )r?   str)r9   
__module____qualname____firstlineno____doc__r   __annotations__r&   r-   r1   r5   r:   __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$ )	MMapCachej   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    rV   rU   rW   r8   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)rP   tempfiler    	bytearrayrV   ospathexistsTemporaryFilerT   rU   openseekwriteflushfileno)r$   rP   r^   fds       r%   rX   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(   r\   c              3  J   >#    U  H  oTR                   ;  d  M  Uv   M     g 7frR   rU   .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)r\   Nrn   ro   s     r%   rr   rs      s     IAT[[8Haart   c                    U S   U S   -
  $ )Nr   r\   rL   )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#   appendrU   updater"   lenrY   rW   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$ )NrY   )__dict__copyr$   states     r%   __getstate__MMapCache.__getstate__   s     ""$'Nr(   c                d    U R                   R                  U5        U R                  5       U l        g rR   )r   r   rX   rY   r   s     r%   __setstate__MMapCache.__setstate__   s"    U#^^%
r(   )rU   rY   rV   rW   )NNN)r   r=   r   r>   r    r=   rV   z
str | NonerU   zset[int] | NonerW   zMultiFetcher | Noner?   r@   )r?   zmmap.mmap | bytearrayr+   rB   r   rB   r?   rC   r?   dict[str, Any]r   r   r?   r@   )r9   rF   rG   rH   rI   r   r&   rX   r-   r   r   rK   __classcell__r8   s   @r%   rN   rN   j   s    8 D  $"&-1&& & 	&
 &  & +& 
& &1,<%|& &r(   rN   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   )rS   r&   rY   r+   r   r$   r   r   r    r8   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(   r\   )r    r+   r   r!   rY   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(   )rY   r   r+   r<   r   
r9   rF   rG   rH   rI   r   r&   r-   rK   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 rR   )rS   r&   rY   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(   r\   )
r    r}   r~   r   r   rY   r"   r#   r   r!   )r$   r+   r   datar   s        r%   r-   FirstChunkCache._fetch6  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(   )rY   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$ )
BlockCacheiT  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 rR   )
rS   r&   mathceilr   	maxblocks	functools	lru_cache_fetch_block_fetch_block_cachedr$   r   r   r    r   r8   s        r%   r&   BlockCache.__init__m  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_infor0   s    r%   r   BlockCache.cache_infou       ''2244r(   c                $    U R                   nUS	 U$ )Nr   r   r   s     r%   r   BlockCache.__getstate__  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XR                  -  nX R                  -  n[        X4S-   5       H  nU R                  U5        M     U R	                  UUUUS9$ )Nr   r(   r\   start_block_numberend_block_number)r    r   r   r   _read_cache)r$   r+   r   r   r   block_numbers         r%   r-   BlockCache._fetch  s    =E;))CII #nn4..0 ""46JKL$$\2 L 1-	   
 	
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 (r|   r\   zBlockCache fetching block %d)	r   
ValueErrorr   r#   r"   r}   inforS   r-   )r$   r   r+   r   block_contentsr8   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 =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      $ z
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\   Nr(   r   r!   r   extendr   r   r   join	r$   r+   r   r   r   	start_posend_posblockouts	            r%   r   BlockCache._read_cache  s     NN*	&!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?   rC   
r+   r=   r   r=   r   r=   r   r=   r?   rC   )r9   rF   rG   rH   rI   r   r&   r   r   r   r-   r   r   rK   r   r   s   @r%   r   r   T  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.
rC   r   r   c                \   > [         TU ]  XU5        SU l        S U l        S U l        X@l        g )Nr(   )rS   r&   rY   r+   r   trim)r$   r   r   r    r   r8   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!   rY   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      $ rR   )r   rY   r0   s    r%   __len__BytesCache.__len__>  s    4::r(   )rY   r   r+   r   )T)
r   r=   r   r>   r    r=   r   boolr?   r@   r   )r?   r=   )r9   rF   rG   rH   rI   r   rJ   r&   r-   r   rK   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
$ )AllBytesiB  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 )Nr\   r   )rS   r&   r"   r#   r    r   r   )r$   r   r   r    r   r8   s        r%   r&   AllBytes.__init__G  sU     	T2<OOq O&&$))3&<<499-D	r(   c                H    U =R                   S-  sl         U R                  X $ )Nr\   )r!   r   r*   s      r%   r-   AllBytes._fetchU  s    !yy$$r(   )r   )NNNN)
r   rB   r   zFetcher | Noner    rB   r   zbytes | Noner?   r@   rA   r9   rF   rG   rH   rI   r   rJ   r&   r-   rK   r   r   s   @r%   r   r   B  sb    +D- !%"&!   	
  
 % %r(   r   c                  n   ^  \ rS rSr% SrSrS\S'     S	           S
U 4S jjjrSU 4S jjrSr	U =r
$ )KnownPartsOfAFileiZ  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   r\   r{   )
rS   r&   strictsortedkeyspopr   dictzipr   )r$   r   r   r    r   r  r   old_offsetsoffsetsrU   r+   r,   start0stop0r8   s                 r%   r&   KnownPartsOfAFile.__init__s  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                ~  > Uc  SnUc  U R                   nSnU R                  R                  5        Hx  u  u  pEnXAs=::  a  U:  d  M  O  M  X-
  nXgXr-   U-
   nU R                  (       a  XBs=::  a  U::  a2  O  O/USX!-
  [	        U5      -
  -  -  nU =R
                  S-  sl        Us  $ Un  O   U R                  c  [        SX4 S35      e[        R                  " SX4 S35        [        R                  SU S	U 35        U =R                  X!-
  -  sl        U =R                  S-  sl        U[        TU ]=  X5      -   $ )
Nr   r(       r\   z&Read is outside the known file parts: z. z%. IO/caching performance may be poor!z!KnownPartsOfAFile cache fetching rl   )r    r   itemsr  r   r!   r   r   warningswarnr}   r~   r#   r"   rS   r-   )	r$   r+   r,   r   loc0loc1r   offr8   s	           r%   r-   KnownPartsOfAFile._fetch  sE   =E<99D"&))//"3LT$ #t##le!34{{d&:d&:
 7dlSX&=>>CNNa'NJ
 !E' #40 <<Eum_TVWXX 	4e]O D2 3	
 	8qGH""dl2"1UW^E000r(   )r   r  )NT)r   r=   r   r>   r    r=   r   z&Optional[dict[tuple[int, int], bytes]]r  r   r   r	   rA   r  r   s   @r%   r  r  Z  sj    , "D-! 8<  	
 5   <+1 +1r(   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currsizerL   N)r9   rF   rG   rH   rJ   rK   rL   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 r\   Flast)	TypeErrorr  r1  r*  move_to_endr-  r+  r.  r   r,  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rR   )r1  r*  )r$   r;  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)NFr6  )r1  r*  r   r,  r:  )r$   r=  r;  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$  )r1  r'  r,  r   r*  r-  r.  r0   s    r%   r   UpdatableLRU.cache_info  sE    ZZ>>T[[)ZZ||	 "  ZZs   AA
A()r*  r+  r-  r1  r,  r.  N)   )r2  zCallable[P, T]r3  r=   r?   r@   )r;  zP.argsr<  zP.kwargsr?   r   )r;  r	   r?   r   )r=  r   r;  r	   r?   r@   r?   r"  )r9   rF   rG   rH   rI   r   r'  r&   r>  rA  rD  r   rK   rL   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 )Nr\   max_workers)rS   r&   r   r   r   r   r   r   r   r   _thread_executor_fetch_future_block_number_fetch_futurer/  r0  _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   r0   s    r%   r   BackgroundBlockCache.cache_info$  r   r(   c                <    U R                   nUS	 US	 US	 US	 US	 U$ )Nr   rP  rQ  rR  rS  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   r\   rN  )r   r   r   r   r   r   rP  rQ  rR  r/  r0  rS  r   s     r%   r   !BackgroundBlockCache.__setstate__8  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.r\   asyncr   )r    r   rS  rR  rQ  doner}   r   r   rD  r=  r   r   r   rA  rP  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   r|   z!BlockCache fetching block (%s) %dr\   )	r   r   r   r}   r   r#   r"   rS   r-   )r$   r   log_infor+   r   r   r8   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   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   rR  rQ  rS  rP  r   r   r   r   rI  r   rD   r   )sync)r   r=   re  rE   r?   rC   r   )r9   rF   rG   rH   rI   r   rJ   r&   r   r   r   r-   r   r   rK   r   r   s   @r%   rK  rK    s    2 'D-& MO33'.3693FI3	3 3	53J
X $(!(!"(!8;(!OR(!	(! (!r(   rK  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   rj  r   )clsclobberr   s      r%   register_cachern    s=     88Dtv~+D83Fvd|nUVVF4Lr(   )F)rl  ztype[BaseCache]rm  r   r?   r@   )4
__future__r   r)  r   loggingr   r`   r/  r  concurrent.futuresr   r   	itertoolsr   operatorr   typingr   r	   r
   r   r   r   r   r   r   rP   typing_extensionsr   r   r   	getLoggerr}   r=   rC   r>   listMultiFetcherr   rN   r   r   r   r   r   r  r   rK  rj  rJ   rn  crL   r(   r%   <module>rz     sy   "     	   9  
 
 
 +#AACL 
		8	$
C:u$
%c3h(%/0< <~K&	 K&\+%Y +%\+,i +,\F! F!Rb bJ%y %0b1	 b1J971a4= 9xK!9 K!` 	)-) ( 

A 1

r(   