+
    &j              	        a  0 t $ ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
Ht ^ RIHtHt ^ RIHt ^ RIHt ^ RIHtHtHtHtHtHt ]'       d   ^ RIt^ R	IHt ]! R
4      tM]! R
4      t]! R4      t]P>                  ! R4      t ]]!]!.]"3,          t#]]$]!]!3,          .]"3,          t% ! R R4      t& ! R R]&4      t' ! R R]&4      t( ! R R]&4      t) ! R R]&4      t* ! R R]&4      t+ ! R R]&4      t, ! R R]&4      t- ! R R]]]3,          4      t. ! R R ]&4      t/R]&/t0R!]1R"&   R%R# R$ llt2]&]']+](]*])],]-]/3	 F  t3]2! ]34       K  	  R# )&    )annotationsN)OrderedDict)Callable)FutureThreadPoolExecutor)groupby)
itemgetter)TYPE_CHECKINGAnyClassVarGeneric
NamedTupleTypeVar)	ParamSpecPTzfsspec.cachingc                  f    ] tR t^"t$ RtRtR]R&   R R ltR R ltR	 R
 lt	R R lt
R R ltRtR# )	BaseCachea;  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               (    V ^8  d   QhRRRRRRRR/#    	blocksizeintfetcherFetchersizereturnNone )formats   "f/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/fsspec/caching.py__annotate__BaseCache.__annotate__4   s(     ' '# ' 's 't '    c                	b    Wn         ^ V n        W n        W0n        ^ V n        ^ V n        ^ V n        R# r   N)r   nblocksr   r   	hit_count
miss_counttotal_requested_bytes)selfr   r   r   s   &&&&r$   __init__BaseCache.__init__4   s.    "	%&"r'   c               $    V ^8  d   QhRRRRRR/# r   start
int | Nonestopr    bytesr"   )r#   s   "r$   r%   r&   >   s!     ) )J )j )U )r'   c                	    Vf   ^ pVf   V P                   pWP                   8  g   W8  d   R# V P                  W4      # Nr'   )r   r   r.   r3   r5   s   &&&r$   _fetchBaseCache._fetch>   s:    =E<99DII||E((r'   c                   V ^8  d   QhRR/# r   r    r!   r"   )r#   s   "r$   r%   r&   G   s     ' 'd 'r'   c                0    ^ V n         ^ V n        ^ V n        R# )zAReset hit and miss counts for a more ganular report e.g. by file.N)r+   r,   r-   r.   s   &r$   _reset_statsBaseCache._reset_statsG   s    %&"r'   c                   V ^8  d   QhRR/# r   r    strr"   )r#   s   "r$   r%   r&   M   s     F FC Fr'   c           	         V P                   ^ 8X  d   V P                  ^ 8X  d   R# RV P                   RV P                    RV P                   RV P                   R2	# )z2Return a formatted string of the cache statistics. 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                   V ^8  d   QhRR/# rC   r"   )r#   s   "r$   r%   r&   T   s     
 
# 
r'   c                	    R V P                   P                   RV P                   RV P                   RV P                   RV P
                   RV P                   RV P                   R2# )z

        <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)rL   
__module____qualname____firstlineno____doc__r   __annotations__r/   r:   r@   rG   rM   __static_attributes__r"   r'   r$   r   r   "   s2     !D- ')'F
 
r'   r   c                  j   a  ] tR t^atRtRtRR V 3R llltR R ltR R ltR	 R
 lt	R R lt
RtV ;t# )	MMapCachea  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               4    V ^8  d   QhRRRRRRRRRR	R
RRR/# )r   r   r   r   r   r   locationz
str | Noneblockszset[int] | Nonemulti_fetcherzMultiFetcher | Noner    r!   r"   )r#   s   "r$   r%   MMapCache.__annotate__   sP     & && & 	&
 &  & +& 
&r'   c                	   < \         SV `  WV4       Vf   \        4       MTV n        W@n        W`n        V P                  4       V n        R # N)superr/   setrZ   rY   r[   	_makefilecache)r.   r   r   r   rY   rZ   r[   rK   s   &&&&&&&r$   r/   MMapCache.__init__   s<     	T2%~ce6 *^^%
r'   c                   V ^8  d   QhRR/# )r   r    zmmap.mmap | bytearrayr"   )r#   s   "r$   r%   r\      s     1 10 1r'   c                	T   ^ RI p^ RIpV P                  ^ 8X  d   \        4       # V P                  e0   \
        P                  P                  V P                  4      '       g   V P                  f!   VP                  4       p\        4       V n
        M\        V P                  R4      pVP                  V P                  ^,
          4       VP                  R4       VP                  4        M\        V P                  R4      pVP                   ! VP                  4       V P                  4      # )r   Nzwb+   1zr+b)rW   tempfiler   	bytearrayrY   ospathexistsTemporaryFiler`   rZ   openseekwriteflushfileno)r.   rW   rg   fds   &   r$   ra   MMapCache._makefile   s    99>; == t}}(E(E}}$++-!e$--/GGDIIM"HHTNHHJdmmU+Byydii00r'   c               $    V ^8  d   QhRRRRRR/# r   r3   r4   endr    r6   r"   )r#   s   "r$   r%   r\      s!     <% <%J <%Z <%E <%r'   c                	  a  \         P                  R V RV 24       Vf   ^ pVf   S P                  pVS P                  8  g   W8  d   R# VS P                  ,          pVS P                  ,          p\	        W4^,           4      pV 3R lV 4       pS ;P
                  \        V 3R lV 4       4      ,          un        . p\        \        V4      R R7       EF  w  r\        \        \        ^4      V	4      4      p	V	^ ,          S P                  ,          p
\        V	R,          S P                  ,          S P                  ,           S P                  4      pS ;P                  W,
          ,          un        \         P                  RV	^ ,           RV	R,           RV
 RV R	2	4       VP                  W34       S P                  P!                  V	4       S ;P"                  \%        V	4      ,          un        EK  	  V'       g   S P&                  W # S P(                  '       dp   \         P                  RV 24       \        S P)                  V4      4       F8  w  rW|,          w  r\         P                  R
V
 RV 24       VS P&                  W% K:  	  MCV F=  w  r\         P                  RV
 RV 24       S P+                  W4      S P&                  W% K?  	  S P&                  W # )zMMap cache fetching -r'   c              3  L   <"   T F  qSP                   9  g   K  Vx  K  	  R # 5ir^   rZ   .0ir.   s   & r$   	<genexpr>#MMapCache._fetch.<locals>.<genexpr>   s     ?;a4;;*>;   $
$c              3  L   <"   T F  qSP                   9   g   K  ^x  K  	  R# 5i   Nrz   r{   s   & r$   r~   r      s     IAT[[8Haar   c                0    V ^ ,          V ^,          ,
          # )r   r"   )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-   appendrZ   updater,   lenrb   r[   r   )r.   r3   rv   start_block	end_blockblock_rangeneedranges__blockssstartsendidxrs   f&&           r$   r:   MMapCache._fetch   sV   +E7!C59:=E;))CDIIt~~-4>>)	KQ7?;?#IIII ")D/7LMMJAC
1w78GQZ$..0Fwr{T^^3dnnDdiiPD &&$-7&LL"71:,a}BvhavQO MM6.) KKw'OOs7|+OO% N( ::e((LL+F845#D$6$6v$>?%{0$@A*+

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

6' !' zz%$$r'   c                   V ^8  d   QhRR/# r   r    dict[str, Any]r"   )r#   s   "r$   r%   r\      s      n r'   c                	@    V P                   P                  4       pVR  V# rb   )__dict__copyr.   states   & r$   __getstate__MMapCache.__getstate__   s     ""$'Nr'   c                    V ^8  d   QhRRRR/# r   r   r   r    r!   r"   )r#   s   "r$   r%   r\      s     & &. &T &r'   c                	f    V P                   P                  V4       V P                  4       V n        R # r^   )r   r   ra   rb   r   s   &&r$   __setstate__MMapCache.__setstate__   s"    U#^^%
r'   )rZ   rb   rY   r[   )NNN)rL   rO   rP   rQ   rR   r   r/   ra   r:   r   r   rT   __classcell__rK   s   @r$   rV   rV   a   s3    8 D& &1,<%|& &r'   rV   c                  B   a  ] tR t^tRtRtR V 3R lltR R ltRtV ;t	# )ReadAheadCachea  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               (    V ^8  d   QhRRRRRRRR/# r   r"   )r#   s   "r$   r%   ReadAheadCache.__annotate__   s(      #  s t r'   c                	R   < \         SV `  WV4       R V n        ^ V n        ^ V n        R# r'   N)r_   r/   rb   r3   rv   r.   r   r   r   rK   s   &&&&r$   r/   ReadAheadCache.__init__   s'    T2

r'   c               $    V ^8  d   QhRRRRRR/# ru   r"   )r#   s   "r$   r%   r      s!     % %J %Z %E %r'   c                	   Vf   ^ pVe   W P                   8  d   V P                   pWP                   8  g   W8  d   R# W!,
          pWP                  8  dY   W P                  8:  dI   V ;P                  ^,          un        V P                  WP                  ,
          W P                  ,
           # V P                  Tu;8:  d   V P                  8  d[   M MWV ;P
                  ^,          un        V P                  WP                  ,
          R  pV\        V4      ,          pV P                  pMV ;P
                  ^,          un        Rp\        V P                   W P                  ,           4      pV ;P                  W!,
          ,          un	        V P                  W4      V n        Wn        V P                  \        V P                  4      ,           V n        W@P                  R V ,           # r8   )r   r3   rv   r+   rb   r,   r   r   r   r-   r   )r.   r3   rv   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'   )rb   rv   r3   
rL   rO   rP   rQ   rR   r   r/   r:   rT   r   r   s   @r$   r   r      s#     D % %r'   r   c                  B   a  ] tR tRtRtRtR V 3R lltR R ltRtV ;t	# )	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               (    V ^8  d   QhRRRRRRRR/# r   r"   )r#   s   "r$   r%   FirstChunkCache.__annotate__&  s(     ( (# ( (s (t (r'   c                	F   < W8  d   Tp\         SV `  WV4       R V n        R # r^   )r_   r/   rb   r   s   &&&&r$   r/   FirstChunkCache.__init__&  s$    IT2#'
r'   c               $    V ^8  d   QhRRRRRR/# ru   r"   )r#   s   "r$   r%   r   -  s!     , ,J ,Z ,E ,r'   c                	   T;'       g    ^ pWP                   8  d   \        P                  R4       R# \        W P                   4      pWP                  8  EdC   V P
                  f   V ;P                  ^,          un        W P                  8  dD   V ;P                  V,          un        V P                  ^ V4      pVRV P                   V n        W1R # V P                  ^ V P                  4      V n        V ;P                  V P                  ,          un        V P
                  W pW P                  8  dL   V ;P                  W P                  ,
          ,          un        W@P                  V P                  V4      ,          pV ;P                  ^,          un	        V# V ;P                  ^,          un        V ;P                  W!,
          ,          un        V P                  W4      # )r   z,FirstChunkCache: requested start > file sizer'   N)
r   r   r   r   r   rb   r,   r-   r   r+   )r.   r3   rv   datar   s   &&&  r$   r:   FirstChunkCache._fetch-  sT   

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'   r   r   r   s   @r$   r   r     s#     D( (, ,r'   r   c                     a  ] tR tRtRtRtRR V 3R llltR tR R ltR	 R
 lt	R R lt
R V 3R lltR R ltRtV ;t# )
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          
     ,    V ^8  d   QhRRRRRRRRRR/# 	r   r   r   r   r   r   	maxblocksr    r!   r"   )r#   s   "r$   r%   BlockCache.__annotate__d  s;     U UU'.U69UFIU	Ur'   c                	   < \         SV `  WV4       \        P                  ! W1,          4      V n        W@n        \        P                  ! V4      ! V P                  4      V n	        R # r^   )
r_   r/   mathceilr*   r   	functools	lru_cache_fetch_block_fetch_block_cachedr.   r   r   r   r   rK   s   &&&&&r$   r/   BlockCache.__init__d  sJ     	T2yy!12"#,#6#6y#A$BSBS#T r'   c                6    V P                   P                  4       # 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                   V ^8  d   QhRR/# r   r"   )r#   s   "r$   r%   r   w  s      n r'   c                	$    V P                   pVR  V# )r   r   r   s   & r$   r   BlockCache.__getstate__w  s    '(r'   c                    V ^8  d   QhRRRR/# r   r"   )r#   s   "r$   r%   r   |  s     
 
. 
T 
r'   c                	    V P                   P                  V4       \        P                  ! VR ,          4      ! V P                  4      V n        R# )r   N)r   r   r   r   r   r   r   s   &&r$   r   BlockCache.__setstate__|  s:    U##,#6#6u[7I#J$
 r'   c               $    V ^8  d   QhRRRRRR/# ru   r"   )r#   s   "r$   r%   r     s!     

 

J 

Z 

E 

r'   c                	    Vf   ^ pVf   V P                   pWP                   8  g   W8  d   R# V P                  WWP                  ,          V^,
          V P                  ,          4      # r8   )r   _read_cacher   )r.   r3   rv   s   &&&r$   r:   BlockCache._fetch  sY    =E;))CII/#'dnn1L
 	
r'   c                    V ^8  d   QhRRRR/# )r   block_numberr   r    r6   r"   )r#   s   "r$   r%   r     s        r'   c                b  < WP                   8  d   \        RV RV P                    R24      hWP                  ,          pW P                  ,           pV ;P                  W2,
          ,          un        V ;P                  ^,          un        \
        P                  RV4       \        SV `!  W#4      pV# )-
Fetch the block of data for `block_number`.
'block_number=(' is greater than the number of blocks (r   zBlockCache fetching block %d)	r*   
ValueErrorr   r-   r,   r   infor_   r:   )r.   r   r3   rv   block_contentsrK   s   &&   r$   r   BlockCache._fetch_block  s     ,,&  /))-a9 
 ~~-nn$""ck1"12LA3r'   c          
     ,    V ^8  d   QhRRRRRRRRRR/# r   r3   r   rv   start_block_numberend_block_numberr    r6   r"   )r#   s   "r$   r%   r     4     (! (!(!"(!8;(!OR(!	(!r'   c           	        WP                   ,          pW P                   ,          pV^ 8X  d   V P                   pV ;P                  ^,          un        W48X  d   V P                  V4      pWuV # V P                  V4      VR .pVP                  \	        V P                  \        V^,           V4      4      4       VP                  V P                  V4      RV 4       RP                  V4      # 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.
Nr'   r   r+   r   extendr   r   r   join	r.   r3   rv   r   r   	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*       )rL   rO   rP   rQ   rR   r   r/   r   r   r   r:   r   r   rT   r   r   s   @r$   r   r   K  sC    , DU U	5



 $(! (!r'   r   c                  ^   a  ] tR tRt$ RtRtR]R&   RR V 3R llltR R	 ltR
 R lt	Rt
V ;t# )
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.
r6   r   r   c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r   r   r   r   r   r   trimboolr    r!   r"   )r#   s   "r$   r%   BytesCache.__annotate__  s4      '.69AE	r'   c                	^   < \         SV `  WV4       R V n        RV n        RV n        W@n        R# r   )r_   r/   rb   r3   rv   r  )r.   r   r   r   r  rK   s   &&&&&r$   r/   BytesCache.__init__  s.     	T2
!%
#	r'   c               $    V ^8  d   QhRRRRRR/# ru   r"   )r#   s   "r$   r%   r    s&     G GJ GZ GE Gr'   c                	8	   Vf   ^ pVf   V P                   pWP                   8  g   W8  d   R# V P                  ev   WP                  8  df   V P                  eX   W P                  8  dH   WP                  ,
          pV ;P                  ^,          un        V P                  W3V,           V,
           # V P
                  '       d(   \        V P                   W P
                  ,           4      pMTpWA8X  g   WP                   8  d   R# V P                  e   WP                  8  du   V P                  e   W P                  8  dW   V ;P                  WA,
          ,          un        V ;P                  ^,          un        V P                  W4      V n        Wn        EMV P                  f   Q hV P                  f   Q hV ;P                  ^,          un        WP                  8  d   V P                  e#   V P                  V,
          V P
                  8  d>   V ;P                  WA,
          ,          un        V P                  W4      V n        Wn        EMWV ;P                  V P                  V,
          ,          un        V P                  WP                  4      pWn        WPP                  ,           V n        MV P                  e   W@P                  8  d   V P                  V P                   8  d   MW P                  ,
          V P
                  8  d=   V ;P                  WA,
          ,          un        V P                  W4      V n        Wn        M]V ;P                  W@P                  ,
          ,          un        V P                  V P                  V4      pV P                  V,           V n        V P                  \        V P                  4      ,           V n        WP                  ,
          pV P                  W3V,           V,
           pV P                  '       d   V P                  V P                  ,
          V P
                  ^,           ,          pV^8  dP   V ;P                  V P
                  V,          ,          un        V P                  V P
                  V,          R  V n        V# r8   )r   r3   rv   r+   rb   r   r   r-   r,   r   r   r  )r.   r3   rv   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99988djj(dnnq.@ACQw

dnns22
!ZZ(<(>?

r'   c                   V ^8  d   QhRR/# )r   r    r   r"   )r#   s   "r$   r%   r  ,  s       r'   c                	,    \        V P                  4      # r^   )r   rb   r?   s   &r$   __len__BytesCache.__len__,  s    4::r'   )rb   rv   r3   r  )T)rL   rO   rP   rQ   rR   r   rS   r/   r:   r  rT   r   r   s   @r$   r  r    s/    
 "D-! GR r'   r  c                  R   a  ] tR tRt$ RtRtR]R&   RR V 3R llltR R	 ltR
t	V ;t
# )AllBytesi0  z!Cache entire contents of the fileallr   r   c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r   r   r4   r   zFetcher | Noner   r   zbytes | Noner    r!   r"   )r#   s   "r$   r%   AllBytes.__annotate__5  s<         	
  
r'   c                	   < \         SV `  WV4       VfY   V ;P                  ^,          un        V ;P                  V P                  ,          un        V P                  ^ V P                  4      pW@n        R # r^   )r_   r/   r,   r-   r   r   r   )r.   r   r   r   r   rK   s   &&&&&r$   r/   AllBytes.__init__5  sU     	T2<OOq O&&$))3&<<499-D	r'   c               $    V ^8  d   QhRRRRRR/# r2   r"   )r#   s   "r$   r%   r"  C  s!     % %J %j %U %r'   c                	P    V ;P                   ^,          un         V P                  W # )r   )r+   r   r9   s   &&&r$   r:   AllBytes._fetchC  s    !yy$$r'   )r   )NNNN)rL   rO   rP   rQ   rR   r   rS   r/   r:   rT   r   r   s   @r$   r  r  0  s$    +D- % %r'   r  c                     a  ] tR tRt$ RtRtR]R&   RR V 3R lllt]R 4       t	]	P                  R	 4       t	]R
 4       t]P                  R 4       tR R ltRtV ;t# )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               0    V ^8  d   QhRRRRRRRRRR	R
R/# )r   r   r   r   r   r   r   z#dict[tuple[int, int], bytes] | Nonestrictr  r   r   r"   )r#   s   "r$   r%   KnownPartsOfAFile.__annotate__a  sF        	
 2  r'   c                	  < \         SV `  WV4       WPn        V'       d   \        VP	                  4       4      pV^ ,          .pVP                  V^ ,          4      .p	VR,           Fv  w  rVR,          w  rW8X  d.   W3VR&   V	R;;,          VP                  W34      ,          uu&   KC  VP                  W34       V	P                  VP                  W34      4       Kx  	  \        \        W4      4      V n	        R# / V n	        R# )r   :r   NNNr   )
r_   r/   r,  sortedkeyspopr   dictzipr   )r.   r   r   r   r   r,  r   old_offsetsoffsetsrZ   r3   r5   start0stop0rK   s   &&&&&&,       r$   r/   KnownPartsOfAFile.__init__a  s     	T2  -K"1~&Ghh{1~./F*2 '>#).GBK2J$((E="99JNNE=1MM$((E="9:  / S12DIDIr'   c                	:    \        R  V P                   4       4      # )c              3  N   "   T F  q^,          V^ ,          ,
          x  K  	  R# 5ir   r"   )r|   r   s   & r$   r~   )KnownPartsOfAFile.size.<locals>.<genexpr>  s     2	1Q4!A$;;	s   #%)r   r   r?   s   &r$   r   KnownPartsOfAFile.size  s    2		222r'   c                	    R # r^   r"   r.   values   &&r$   r   r<        r'   c                	,    \        V P                  4      # r^   )r   r   r?   s   &r$   r*   KnownPartsOfAFile.nblocks  s    499~r'   c                	    R # r^   r"   r>  s   &&r$   r*   rB    r@  r'   c               $    V ^8  d   QhRRRRRR/# r2   r"   )r#   s   "r$   r%   r-    s!     , ,J ,j ,U ,r'   c                	   \         P                  R W4       Vf   ^ pVf   V P                  pV ;P                  W!,
          ,          un        RpRp^ p\	        V P
                  4       EF  w  rgYau;8:  d   V8  d\   M MXYbu;8:  d   V8:  dK   M MGW,
          pV ;P                  ^,          un        V P
                  Wg3,          WV,           V,
           u # W&8:  d    EMFV'       dN   We8  dH   V ;P                  ^,          un        V P                  '       d   \        hVRWe,
          ,          ,          pYau;8:  d   V8  dL   M MHV ;P                  ^,          un        W,
          pV P
                  Wg3,          WV,           V,
           pRpMW8  d;   W'8  d5   V ;P                  ^,          un        W0P
                  Wg3,          ,          pMQYbu;8:  d   V8:  dD   M M@V ;P                  ^,          un        W0P
                  Wg3,          RW&,
           ,           pVu # TpEK  	  V ;P                  ^,          un        V'       d+   V P                  '       g   VRW%,
          ,          ,           pV# \        h)zKnown parts request %s %sNr'   F    T)
r   r   r   r-   r/  r   r+   r,   r,  r   )	r.   r3   r5   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)rL   rO   rP   rQ   rR   r   rS   r/   propertyr   setterr*   r:   rT   r   r   s   @r$   r)  r)  H  s    , "D-! < 3 3 
[[    ^^ , ,r'   r)  c                  p    ] tR tRtRt ! R R]4      tRR R lltR R ltR	 R
 lt	R R lt
R R ltRtR# )UpdatableLRUi  z\
Custom implementation of LRU cache that allows updating keys

Used by BackgroundBlockCache
c                  @    ] tR tRt$ R]R&   R]R&   R]R&   R]R&   RtR# )	UpdatableLRU.CacheInfoi  r   hitsmissesmaxsizecurrsizer"   N)rL   rO   rP   rQ   rS   rT   r"   r'   r$   	CacheInforR    s    	r'   rW  c               $    V ^8  d   QhRRRRRR/# )r   funczCallable[P, T]max_sizer   r    r!   r"   )r#   s   "r$   r%   UpdatableLRU.__annotate__  s!     & &^ &s &T &r'   c                	    \         P                  ! 4       V n        Wn        W n        ^ V n        ^ V n        \        P                  ! 4       V n	        R# r)   )
collectionsr   _cache_func	_max_size_hits_misses	threadingLock_lock)r.   rY  rZ  s   &&&r$   r/   UpdatableLRU.__init__  s8    +6+B+B+D
!
^^%
r'   c               $    V ^8  d   QhRRRRRR/# )r   argszP.argskwargszP.kwargsr    r   r"   )r#   s   "r$   r%   r[    s!      f  Q r'   c                	   V'       d   \        R VP                  4        24      hV P                  ;_uu_ 4        WP                  9   dR   V P                  P	                  V4       V ;P
                  ^,          un        V P                  V,          uuRRR4       #  RRR4       V P                  ! V/ VB pV P                  ;_uu_ 4        W0P                  V&   V ;P                  ^,          un        \        V P                  4      V P                  8  d   V P                  P                  RR7       RRR4       V#   + '       g   i     L; i  + '       g   i     T# ; i)z Got unexpected keyword argument NFlast)	TypeErrorr0  re  r^  move_to_endra  r_  rb  r   r`  popitem)r.   rh  ri  results   &*, r$   __call__UpdatableLRU.__call__  s    >v{{}oNOOZZZ{{"''-

a
{{4(	 Z"  T,V,ZZZ &KKLLAL4;;$..0###/	   Z Z s   AD<
A(E<E	E 	c                    V ^8  d   QhRRRR/# )r   rh  r   r    r  r"   )r#   s   "r$   r%   r[    s     ' '3 '4 'r'   c                	    V P                   ;_uu_ 4        WP                  9   uuR R R 4       #   + '       g   i     R # ; ir^   )re  r^  )r.   rh  s   &*r$   is_key_cachedUpdatableLRU.is_key_cached  s!    ZZZ;;& ZZZs   .?	c               $    V ^8  d   QhRRRRRR/# )r   rp  r   rh  r   r    r!   r"   )r#   s   "r$   r%   r[    s!     0 0a 0 0 0r'   c                	   V P                   ;_uu_ 4        WP                  V&   \        V P                  4      V P                  8  d   V P                  P	                  R R7       RRR4       R#   + '       g   i     R# ; i)Frk  N)re  r^  r   r`  ro  )r.   rp  rh  s   &&*r$   add_keyUpdatableLRU.add_key  sM    ZZZ &KK4;;$..0###/ ZZZs   AA..A?	c                   V ^8  d   QhRR/# r   r    rR  r"   )r#   s   "r$   r%   r[    s      2 r'   c           	     	    V P                   ;_uu_ 4        V P                  V P                  \        V P                  4      V P
                  V P                  R 7      uuRRR4       #   + '       g   i     R# ; i))rU  rV  rS  rT  N)re  rW  r`  r   r^  ra  rb  r?   s   &r$   r   UpdatableLRU.cache_info  sI    ZZZ>>T[[)ZZ||	 "  ZZZs   AA&&A7	)r^  r_  ra  re  r`  rb  N)   )rL   rO   rP   rQ   rR   r   rW  r/   rq  ru  ry  r   rT   r"   r'   r$   rP  rP    s1    J &&'0 r'   rP  c                     a  ] tR tRt$ RtRtR]R&   RR V 3R llltR R	 ltR
 R lt	R R lt
R R ltRR V 3R llltR R ltRtV ;t# )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          
     ,    V ^8  d   QhRRRRRRRRRR/# r   r"   )r#   s   "r$   r%   !BackgroundBlockCache.__annotate__  s4     3 33'.3693FI3	3r'   c                	  < \         SV `  WV4       \        P                  ! W1,          4      V n        W@n        \        V P                  V4      V n        \        ^R7      V n
        RV n        RV n        \        P                  ! 4       V n        R# )r   max_workersN)r_   r/   r   r   r*   r   rP  r   r   r   _thread_executor_fetch_future_block_number_fetch_futurerc  rd  _fetch_future_lockr   s   &&&&&r$   r/   BackgroundBlockCache.__init__  sm     	T2yy!12"#/0A0A9#M  2q A6:'37"+.."2r'   c                   V ^8  d   QhRR/# r|  r"   )r#   s   "r$   r%   r  #  s     	5 	52 	5r'   c                6    V P                   P                  4       # r   r   r?   s   &r$   r   BackgroundBlockCache.cache_info#  r   r'   c                   V ^8  d   QhRR/# r   r"   )r#   s   "r$   r%   r  .  s      n r'   c                	<    V P                   pVR  VR VR VR VR V# )r   r  r  r  r  r   r   s   & r$   r   !BackgroundBlockCache.__getstate__.  s<    '($%.//"&'r'   c                   V ^8  d   QhRR/# r=   r"   )r#   s   "r$   r%   r  7  s     3 3T 3r'   c                	    V P                   P                  V4       \        V P                  VR ,          4      V n        \        ^R7      V n        RV n        RV n        \        P                  ! 4       V n        R# )r   r  N)r   r   rP  r   r   r   r  r  r  rc  rd  r  r   s   &&r$   r   !BackgroundBlockCache.__setstate__7  sZ    U##/0A0A5CU#V  2q A*.'!"+.."2r'   c               $    V ^8  d   QhRRRRRR/# ru   r"   )r#   s   "r$   r%   r  ?  s&     J
 J
J J
Z J
E J
r'   c                	V   Vf   ^ pVf   V P                   pWP                   8  g   W8  d   R# WP                  ,          pW P                  ,          pR pR pV P                  ;_uu_ 4        V P                  e   V P                  f   Q hV P                  P                  4       '       dc   \        P                  R4       V P                  P                  V P                  P                  4       V P                  4       R V n        R V n        MW\        VV P                  u;8*  ;'       d    V8*  Mu 4      pV'       d'   V P                  pV P                  pR V n        R V n        R R R 4       Ve@   \        P                  R4       V P                  P                  VP                  4       V4       \        W4^,           4       F  pV P                  V4       K  	  V^,           p	V P                  ;_uu_ 4        V P                  fd   WP                  8:  dT   V P                  P                  V	4      '       g3   Wn        V P                  P!                  V P"                  V	R4      V n        R R R 4       V P%                  VVVVR7      #   + '       g   i     EL*; i  + '       g   i     L9; i)Nr'   z3BlockCache joined background fetch without waiting.z(BlockCache waiting for background fetch.async)r   r   )r   r   r  r  r  doner   r   r   ry  rp  r  r   r*   ru  r  submitr   r   )
r.   r3   rv   r   r   fetch_future_block_numberfetch_future	must_joinr   end_block_plus_1s
   &&&       r$   r:   BackgroundBlockCache._fetch?  sQ   =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+   +>J*BJ=&J5?J52JJ	J(	c               $    V ^8  d   QhRRRRRR/# )r   r   r   log_inforD   r    r6   r"   )r#   s   "r$   r%   r    s!         r'   c                b  < WP                   8  d   \        RV RV P                    R24      hWP                  ,          pW0P                  ,           p\        P	                  RW!4       V ;P
                  WC,
          ,          un        V ;P                  ^,          un        \        SV `!  W44      pV# )r   r   r   r   z!BlockCache fetching block (%s) %d)	r*   r   r   r   r   r-   r,   r_   r:   )r.   r   r  r3   rv   r   rK   s   &&&   r$   r   !BackgroundBlockCache._fetch_block  s     ,,&  /))-a9 
 ~~-nn$7P""ck1"13r'   c          
     ,    V ^8  d   QhRRRRRRRRRR/# r   r"   )r#   s   "r$   r%   r    r   r'   c           	        WP                   ,          pW P                   ,          pV ;P                  ^,          un        W48X  d   V P                  V4      pWuV # V P                  V4      VR .pVP                  \	        V P                  \        V^,           V4      4      4       VP                  V P                  V4      RV 4       RP                  V4      # 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   r  r  r  r  r   r*   r	  )sync)rL   rO   rP   rQ   rR   r   rS   r/   r   r   r   r:   r   r   rT   r   r   s   @r$   r  r    sH    2 'D-&3 3	53J
X $(! (!r'   r  z!dict[str | None, type[BaseCache]]cachesc               $    V ^8  d   QhRRRRRR/# )r   clsztype[BaseCache]clobberr  r    r!   r"   )r#   s   "r$   r%   r%     s!       $ 4 r'   c                    V P                   pV'       g)   V\        9   d   \        RV: R\        V,           24      hV \        V&   R# )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   r  r   )r  r  r   s   && r$   register_cacher    s=     88Dtv~+D83Fvd|nUVVF4Lr'   )F)4__conditional_annotations__
__future__r   r]  r   loggingr   ri   rc  r   collections.abcr   concurrent.futuresr   r   	itertoolsr   operatorr	   typingr
   r   r   r   r   r   rW   typing_extensionsr   r   r   	getLoggerr   r   r6   r   listMultiFetcherr   rV   r   r   r   r  r  r)  rP  r  r  rS   r  c)r  s   @r$   <module>r     sv   " "     	  # $ 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'   