+
    7&Ïjc  ã                   óÂ   € ^ RI t ^ RIt^ RIt^ RIHt ^RIHt ^RIHt ^RI	H
t
 ]P                  ! ]4      t ! R R4      t ! R R	4      t ! R
 R4      t ! R R4      tR# )é    N)Údeque)Úasyn)Úsync_teardown)Ú_fast_slicec                   óš   a € ] tR t^t o RtRR ltV 3R lR lt]V 3R lR l4       t]V 3R lR l4       t	]V 3R	 lR
 l4       t
R tRtV tR# )ÚRunningAverageTrackerz«Tracks a running average of values over a sliding window.

This is used to monitor read sizes and adaptively scale the
prefetching strategy based on recent user behavior.
c                ób   € \         P                  RV4       \        VR7      V n        ^ V n        R# )zInitializes the tracker with a specific window size.

Args:
    maxlen (int): The maximum number of historical values to keep.
z2Initializing RunningAverageTracker with maxlen: %d©ÚmaxlenN)ÚloggerÚdebugr   Ú_historyÚ_sum)Úselfr   s   &&ÚK/opt/data/cache/scratch/pip-target-elquwxdg/lib/python/fsspec/prefetcher.pyÚ__init__ÚRunningAverageTracker.__init__   s&   € ô 	�‰ÐIÈ6ÔRÜ VÔ,ˆŒØˆŽ	ó    c                ó    <€ V ^8„  d   QhRS[ /# )é   Úvalue©Úint)ÚformatÚ__classdict__s   "€r   Ú__annotate__Ú"RunningAverageTracker.__annotate__   s   ø€ ÷ 
ñ 
™ñ 
r   c                ó‚  € V^ 8:  d   \        R4      h\        V P                  4      V P                  P                  8X  d+   V ;P                  V P                  ^ ,          ,          un        V P                  P                  V4       V ;P                  V,          un        \        P                  RWP                  4       R# )z…Adds a new value to the sliding window and updates the rolling sum.

Args:
    value (int): The integer value to add to the history.
zDInternal error, RunningAverageTracker tried inserting negative valuez2RunningAverageTracker added value: %d, new sum: %dN)Ú
ValueErrorÚlenr   r   r   Úappendr   r   )r   r   s   &&r   ÚaddÚRunningAverageTracker.add   s„   € ð �AŒ:ÜØVóð ô ˆt�}‰}Ó §¡×!5Ñ!5Ô5Ø�IŠI˜Ÿ™ qÕ)Õ)�Ià�‰×Ñ˜UÔ#Ø�	Š	�UÕ�	Ü�‰Ø@À%ÏÉö	
r   c                ó    <€ V ^8„  d   QhRS[ /# ©r   Úreturnr   )r   r   s   "€r   r   r   2   s   ø€ ÷ 	"ñ 	"™ñ 	"r   c                ód   € \        V P                  4      pV^ 8X  d   R# V P                  V,          # )zsCalculates and returns the current running average.

Returns:
    int: The integer average of the current history.
i   )r    r   r   ©r   Úcounts   & r   ÚaverageÚRunningAverageTracker.average1   s.   € ô �D—M‘MÓ"ˆØ�AŒ:ØÐØ�y‰y˜EÕ!Ð!r   c                ó    <€ V ^8„  d   QhRS[ /# r%   )Úbool)r   r   s   "€r   r   r   >   s   ø€ ÷ +ñ +™Tñ +r   c                ó€   € \        V P                  4      pV^8  d   R# \        \        V P                  4      4      ^8„  # )z8Determines if the history contains distinct chunk sizes.F)r    r   Úsetr(   s   & r   Úis_variableÚ!RunningAverageTracker.is_variable=   s5   € ô �D—M‘MÓ"ˆØ�1Œ9Ùä”3�t—}‘}Ó%Ó&¨Ñ*Ð*r   c                ó    <€ V ^8„  d   QhRS[ /# r%   r   )r   r   s   "€r   r   r   G   s   ø€ ÷ !ñ !™Cñ !r   c                ób   € V P                   '       g   \        R4      hV P                   R,          # )z-Returns the most recent entry in the history.zNo entry found in historyéÿÿÿÿ)r   ÚRuntimeError©r   s   &r   Ú
last_valueÚ RunningAverageTracker.last_valueF   s(   € ð �}�}ˆ}ÜÐ:Ó;Ð;à�}‰}˜RÕ Ð r   c                ór   € \         P                  R4       V P                  P                  4        ^ V n        R# )z.Clears the history and resets the sum to zero.z'Clearing RunningAverageTracker history.N)r   r   r   Úclearr   r6   s   &r   r:   ÚRunningAverageTracker.clearN   s&   € ä�‰Ð>Ô?Ø�‰×ÑÔØˆŽ	r   )r   r   N)é
   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r"   Úpropertyr*   r0   r7   r:   Ú__static_attributes__Ú__classdictcell__©r   s   @r   r   r      s_   ø‡ € ñô÷
ð 
ð& ÷	"ó ð	"ð ÷+ó ð+ð ÷!ó ð!÷ð r   r   c                   ó¢   a € ] tR t^Ut o RtRtRt^tRtRV 3R lR llt	]
V 3R lR l4       tR tR tV 3R	 lR
 ltR tV 3R lR ltR tRtV tR# )ÚPrefetchProducerzúBackground worker that fetches sequential blocks of data.

This class handles the network requests. It spawns asynchronous tasks
to fetch data ahead of the user's current reading position and
places those task promises into a queue for the consumer.
Nc                óh   <€ V ^8„  d   QhRS[ RS[ RS[P                  RS[P                  RRRS[RR	/# )
r   ÚsizeÚconcurrencyÚqueueÚwakeup_eventÚconsumerÚPrefetchConsumerÚtrackerÚorchestratorÚBackgroundPrefetcher)r   ÚasyncioÚQueueÚEventr   )r   r   s   "€r   r   ÚPrefetchProducer.__annotate__w   s[   ø€ ÷ -#ñ -#ñ ð-#ñ ð	-#ñ
 �}‰}ð-#ñ —m‘mð-#ð %ð-#ñ 'ð-#ð -ñ-#r   c
                ó  € \         P                  RVVV	4       Wn        W n        W0n        W@n        WPn        W`n        Wpn        \        P                  ! V4      V n        W�n        ^ V n        RV n        \        4       V n        RV n        R# )aÒ  Initializes the background producer.

Args:
    fetcher (Callable): A coroutine function to fetch bytes from a remote source.
    size (int): Total size of the file being fetched.
    concurrency (int): Maximum number of concurrent fetch tasks.
    queue (asyncio.Queue): The shared queue to push download tasks into.
    wakeup_event (asyncio.Event): Event used to wake the producer from an idle state.
    consumer (PrefetchConsumer): The consumer reading the prefetched chunks.
    tracker (RunningAverageTracker): Tracker for history of read sizes.
    orchestrator (BackgroundPrefetcher): The parent object managing the operation.
    user_max_prefetch_size (int, optional): A hard limit for prefetch size overrides.
zQInitializing PrefetchProducer: size=%d, concurrency=%d, user_max_prefetch_size=%sFN)r   r   ÚfetcherrI   rJ   rK   rL   rM   rO   ÚweakrefÚproxyrP   Ú_user_max_prefetch_sizeÚcurrent_offsetÚ
is_stoppedr/   Ú_active_tasksÚ_producer_task)
r   rW   rI   rJ   rK   rL   rM   rO   rP   Úuser_max_prefetch_sizes
   &&&&&&&&&&r   r   ÚPrefetchProducer.__init__w   s{   € ô2 	�‰Ø_ØØØ"ô		
ð ŒØŒ	Ø&ÔØŒ
Ø(Ôà ŒØŒÜ#ŸMšM¨,Ó7ˆÔØ'=Ô$àˆÔØˆŒÜ ›UˆÔØ"ˆÖr   c                ó    <€ V ^8„  d   QhRS[ /# r%   r   )r   r   s   "€r   r   rU   §   s   ø€ ÷ Eñ E¡3ñ Er   c                ó
  € V P                   eF   \        V P                   \        ^V P                  P                  ,          V P
                  4      4      # \        ^V P                  P                  ,          V P
                  4      # )zˆCalculates the maximum prefetch size based on user intent or io size.

Returns:
    int: The maximum number of bytes to prefetch ahead.
)rZ   ÚminÚmaxrO   r*   ÚMIN_PREFETCH_SIZEr6   s   &r   Úmax_prefetch_sizeÚ"PrefetchProducer.max_prefetch_size¦   si   € ð ×'Ñ'Ò3ÜØ×,Ñ,Ü�A˜Ÿ™×,Ñ,Õ,¨d×.DÑ.DÓEóð ô �1�t—|‘|×+Ñ+Õ+¨T×-CÑ-CÓDÐDr   c                óÄ   € \         P                  R4       RV n        V P                  P	                  4        \
        P                  ! V P                  4       4      V n        R# )zlStarts the background producer loop.

This clears any previous wakeup events and spawns the main loop task.
zStarting PrefetchProducer loop.FN)	r   r   r\   rL   r:   rR   Úcreate_taskÚ_loopr^   r6   s   &r   ÚstartÚPrefetchProducer.start´   sC   € ô
 	�‰Ð6Ô7ØˆŒØ×Ñ×ÑÔ!Ü%×1Ò1°$·*±*³,Ó?ˆÖr   c              ƒ  óz  "  € \         P                  R\        V P                  4      4       RV n        V P
                  P                  4        . pV P                  '       dV   V P                  P                  4       '       g6   V P                  P                  4        VP                  V P                  4       VP                  R \        V P                  4       4       4       V P                  P                  4        ^ pV P                  P                  4       '       gƒ    V P                  P!                  4       p\#        V\$        P&                  4      '       d=   VP                  4       '       d'   VP)                  4       '       g   VP+                  4        V^,          pK¢  V^ 8”  d   \         P                  RV4       V'       d>   \         P                  R\        V4      4       \$        P.                  ! VRR/ G Rj  x€L
  V P
                  P                  4        R#   \$        P,                   d     K–  i ; i L<5i)z Cancels all active fetch tasks and shuts down the producer loop.

This method ensures the queue is flushed and waits for cancelled
tasks to finish cleaning up.
z1Stopping PrefetchProducer. Active fetch tasks: %dTc              3   óT   "  € T F  qP                  4       '       d   K  Vx € K   	  R # 5i©N)Údone)Ú.0Útasks   & r   Ú	<genexpr>Ú(PrefetchProducer.stop.<locals>.<genexpr>Ï   s   é € ð 
Ù5�T¿Y¹Y¿[�DŠDÓ5ùs   ‚(ž
(z5Cleared %d leftover items from the queue during stop.z8Waiting for %d cancelled tasks to finish their teardown.Úreturn_exceptionsN)r   r   r    r]   r\   rL   r/   r^   rp   Úcancelr!   ÚextendÚlistr:   rK   ÚemptyÚ
get_nowaitÚ
isinstancerR   ÚTaskÚ	cancelledÚ	exceptionÚ
QueueEmptyÚgather)r   Útasks_to_waitÚcleared_itemsÚitems   &   r   ÚstopÚPrefetchProducer.stop¾   s³  é € ô 	�‰Ø?ÄÀT×EWÑEWÓAXô	
ð ˆŒØ×Ñ×ÑÔàˆØ××Ð t×':Ñ':×'?Ñ'?×'AÒ'AØ×Ñ×&Ñ&Ô(Ø× Ñ  ×!4Ñ!4Ô5à×Ññ 
Ü! $×"4Ñ"4Ô5ó
ô 	
ð 	×Ñ× Ñ Ô"ð ˆØ—*‘*×"Ñ"×$Ò$ð
Ø—z‘z×,Ñ,Ó.�ä˜t¤W§\¡\×2Ò2ØŸ	™	ŸšØ ŸN™N×,Ò,à—N‘NÔ$Ø Õ"’ð ˜1ÔÜ�L‰LØGÈô÷ Ü�L‰LØJÜ�MÓ"ôô —.’. -ÐHÀ4ÑH×HÐHà×Ñ×ÑÖ!øô ×%Ñ%ô Úðúñ IùsP   ‚A>H;ÂBH;ÄAH Å.H ÆH Æ&H;Ç8H;Ç<H9Ç= H;ÈH6È2H;È5H6È6H;c                ó    <€ V ^8„  d   QhRS[ /# ©r   Ú
new_offsetr   )r   r   s   "€r   r   rU   ô   s   ø€ ÷ 	ñ 	©ñ 	r   c              ƒ  óš   "  € \         P                  RV4       V P                  4       G Rj  x€L
  Wn        V P	                  4        R#  L5i)z™Stops current tasks and restarts the background loop at a new byte offset.

Args:
    new_offset (int): The new byte position to start prefetching from.
z-Restarting PrefetchProducer at new offset: %dN)r   r   r„   r[   rk   ©r   rˆ   s   &&r   ÚrestartÚPrefetchProducer.restartô   s9   é € ô 	�‰ÐDÀjÔQØ�i‰i‹k×ÐØ(ÔØ�
‰
Žñ 	ùs   ‚*A¬A	­Ac              ƒ  óz  "  € \         P                  R4        V P                  '       gk   V P                  P	                  4       G Rj  x€L
  V P                  P                  4        V P                  '       d   R# V P                  4       G Rj  x€L
  K|  R#  LN L
  \        P                   d    \         P                  R4        R# \         dg   p\         P                  R4       RT n        T P                  P                  T4       T P                  P                  T4      G Rj  x€L 
   Rp?R# Rp?ii ; i5i)zFThe main background loop that delegates calculations and spawns tasks.z.PrefetchProducer internal loop is now running.Nz$PrefetchProducer loop was cancelled.z6PrefetchProducer loop encountered an unexpected error.T)r   r   r\   rL   Úwaitr:   Ú_process_prefetch_cyclerR   ÚCancelledErrorÚ	Exceptionr~   rP   Ú	set_errorrK   Úput©r   Úes   & r   rj   ÚPrefetchProducer._loopÿ   sà   é € ä�‰ÐEÔFð	$Ø—o—o�oØ×'Ñ'×,Ñ,Ó.×.Ð.Ø×!Ñ!×'Ñ'Ô)à—?—?�?Ùà×2Ñ2Ó4×4Ò4ñ &Ù.ñ 5øä×%Ñ%ô 	AÜ�L‰LÐ?×@Üô 	$Ü×ÑÐUÔVØ"ˆDŒOØ×Ñ×'Ñ'¨Ô*Ø—*‘*—.‘. Ó#×#×#ûð		$üs‚   ‚D;™B «B ÁBÁ	/B Á9D;Á;B ÂBÂB ÂD;ÂB ÂB Â*D8ÃD;ÃD8ÃD8ÃAD3Ä'D*Ä(D3Ä-D;Ä3D8Ä8D;c                ó:   <€ V ^8„  d   QhRS[ S[S[S[3,          /# r%   )Útupler   )r   r   s   "€r   r   rU     s   ø€ ÷ .?ñ .?©E±#±s¹C°-Õ,@ñ .?r   c                ón  € V P                   P                  pV P                  P                  pV P                   P                  pV P                   P
                  pV P                  RJ;'       d    WP                  8„  pV'       d   WP                  8”  g	   V'       d   \        P                  R4       ^pM,W P                  8  d   ^pMW P                  ,
          ^,           pV P                  P                  4       '       g   V^8X  d   TpMTp\        Wg,          V P                  4      pV P                  P                  V,           V P                  P                   8  d2   V P                  P                   V P                  P                  ,
          pV'       d   Tp	MW‡,          V,          p	V	^ 8X  d   Tp	W‡V	3# )z�
Evaluates current trackers and state to determine sizes.

Returns:
    tuple: (prefetch_size, io_size, effective_prefetch_size)
NzTLarge IO detected (variable > 64MB or > user max). Disabling background prefetching.)rO   r*   rM   Úsequential_streakr0   r7   rZ   ÚVARIABLE_IO_THRESHOLDr   r   ÚMIN_STREAKS_FOR_PREFETCHINGrK   ry   rc   rf   ÚoffsetÚtarget_offset)
r   Úavg_io_sizeÚstreakr0   Úlast_read_sizeÚexceeds_user_maxÚprefetch_multiplierÚio_sizeÚprefetch_sizeÚeffective_prefetch_sizes
   &         r   Ú_calculate_prefetch_paramsÚ+PrefetchProducer._calculate_prefetch_params  sf  € ð —l‘l×*Ñ*ˆØ—‘×0Ñ0ˆØ—l‘l×.Ñ.ˆØŸ™×0Ñ0ˆð ×(Ñ(°Ð4÷ ;ð ;Ø×:Ñ:Ñ:ð 	÷ ˜K×*DÑ*DÔDßÜ�L‰LØfôð #$ÑØ×6Ñ6Ô6Ø"#Ñà"(×+KÑ+KÕ"KÈaÕ"OÐà�:‰:×Ñ×ÒÐ!4¸Ô!9Ø$‰Gà!ˆGäÐ/Õ9¸4×;QÑ;QÓRˆØ�=‰=×Ñ -Õ/°$·-±-×2MÑ2MÔMØ ŸM™M×7Ñ7¸$¿-¹-×:NÑ:NÕNˆMçØ&3Ñ#à'4Õ'?À7Õ&JÐ#Ø&¨!Ô+Ø*7Ð'àÐ'>Ð>Ð>r   c              ƒ  óÖ  "  € V P                  4       w  rp\        P                  RV P                  V P                  P
                  V4       V P                  '       EgN   V P                  V P                  P
                  ,
          V8  Ed!   V P                  V P                  8  Ed   V P                  P
                  pV P                  V P                  ,
          pVV P                  V,
          ,
          pWP                  8¼  d4   W`P                  8¼  d"   \        \        V P                  V4      V4      pMEMt\        W%4      pWg8  d(   V P                  P                  '       g   Wa8X  d   TpMEM<V P                  P                  pW€P                  8  d   V P                  p	M7\        V P                  \        ^WpP                  ,          V,          4      4      p	\        P                  RV P                  VV	4       \         P"                  ! V P%                  V P                  WyR7      4      p
V P&                  P)                  V
4       V
P+                  V P&                  P,                  4       V P.                  P1                  V
4      G Rj  x€L
  V ;P                  V,          un        EK`  V P                  V P                  8¼  d   \        P                  R4       RV n        R# R#  L[5i)z1Executes a single cycle of enqueuing fetch tasks.zFProducer awake. Current offset: %d, User offset: %d, Prefetch size: %dz;Spawning fetch task. Offset: %d, Size: %d, Split Factor: %d)Úsplit_factorNz.Producer reached EOF. Exiting background loop.T)r§   r   r   r[   rM   r�   r\   rI   ÚMIN_CHUNK_SIZErc   rd   rO   r0   rš   rœ   rJ   rR   ri   rW   r]   r"   Úadd_done_callbackÚdiscardrK   r“   )r   r¥   r¤   r¦   Úuser_offsetÚspace_remainingÚprefetch_space_availableÚactual_sizer    ÚsfactorÚdownload_tasks   &          r   r�   Ú(PrefetchProducer._process_prefetch_cycleD  sN  é € ð ×+Ñ+Ó-ñ 	8ˆÐ 7ô 	�‰ØTØ×ÑØ�M‰M× Ñ Øô		
ð ——‘Ø×$Ñ$ t§}¡}×';Ñ';Õ;¸}ÕLØ×#Ñ# d§i¡iÕ/àŸ-™-×.Ñ.ˆKØ"Ÿi™i¨$×*=Ñ*=Õ=ˆOØ'4Ø×#Ñ# kÕ1õ(Ð$ð × 3Ñ 3Ô3Ø+×/BÑ/BÔBÜ"%Ü˜D×/Ñ/°Ó9¸?ó#‘Kñ ä! 'Ó;�à'Ô5à—L‘L×,×,Ð,Ø/Ô@à":‘Káà—]‘]×4Ñ4ˆFØ×8Ñ8Ô8Ø×*Ñ*‘äØ×$Ñ$ÜØØ#×&6Ñ&6Õ6Ð:QÕQóó�ô �L‰LØMØ×#Ñ#ØØô	ô $×/Ò/Ø—‘˜T×0Ñ0°+�ÓTóˆMð ×Ñ×"Ñ" =Ô1Ø×+Ñ+¨D×,>Ñ,>×,FÑ,FÔGà—*‘*—.‘. Ó/×/Ð/Ø×Ò ;Õ.×Ðà×Ñ $§)¡)Ô+Ü�L‰LÐIÔJØ"ˆDŽOñ ,ñ 0ùs!   ‚AK)ÁDK)Å%D&K)ÊK'ÊAK))r]   r^   rZ   rJ   rM   r[   rW   r\   rP   rK   rI   rO   rL   i  P i   i   ro   )r=   r>   r?   r@   rA   r«   re   rœ   r›   r   rB   rf   rk   r„   r‹   rj   r§   r�   rC   rD   rE   s   @r   rG   rG   U   s|   ø‡ € ñð %€Nð *Ðð #$Ðð -Ð÷-#ò -#ð^ ÷Eó ðEò@ò4"÷l	ð 	ò$÷*.?ð .?÷`I#ð I#r   rG   c                   ó„   a € ] tR tRt o RtV 3R lR ltV 3R lR ltR tV 3R lR	 ltV 3R
 lR lt	V 3R lR lt
RtV tR# )rN   i�  zÚConsumes prefetched chunks from the queue and manages byte slicing.

This class pulls data out of the shared queue and slices it into the
exact byte sizes requested by the user. It also manages the local block buffer.
c                óX   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[RR/# )r   rK   rL   rO   rP   rQ   )rR   rS   rT   r   )r   r   s   "€r   r   ÚPrefetchConsumer.__annotate__—  s;   ø€ ÷ $ñ $á�}‰}ð$ñ —m‘mð$ñ 'ð	$ð
 -ñ$r   c                óÐ   € \         P                  R4       Wn        W n        W0n        \
        P                  ! V4      V n        ^ V n        ^ V n	        ^ V n
        RV n        ^ V n        R# )a\  Initializes the consumer.

Args:
    queue (asyncio.Queue): The shared queue containing fetch tasks.
    wakeup_event (asyncio.Event): Event used to wake the producer when more data is needed.
    tracker (RunningAverageTracker): Tracker for history of read sizes.
    orchestrator (BackgroundPrefetcher): The parent object managing the operation.
zInitializing PrefetchConsumer.r   N)r   r   rK   rL   rO   rX   rY   rP   rš   r�   rž   Ú_current_blockÚ_current_block_idx)r   rK   rL   rO   rP   s   &&&&&r   r   ÚPrefetchConsumer.__init__—  sY   € ô 	�‰Ð5Ô6ØŒ
Ø(ÔØŒÜ#ŸMšM¨,Ó7ˆÔØ!"ˆÔØˆŒØˆÔØ!ˆÔØ"#ˆÖr   c                ó    <€ V ^8„  d   QhRS[ /# r‡   r   )r   r   s   "€r   r   r·   ±  s   ø€ ÷ $ñ $™sñ $r   c                ót   € \         P                  RV4       Wn        Wn        ^ V n        RV n        ^ V n        R# )z�Clears the buffer and resets the internal offset for a hard seek.

Args:
    new_offset (int): The byte position the consumer is jumping to.
zDConsumer executing hard seek to offset %d. Clearing internal buffer.r   N)r   r   r�   rž   rš   r¹   rº   rŠ   s   &&r   ÚseekÚPrefetchConsumer.seek±  s;   € ô 	�‰ØRØô	
ð !ŒØ'ÔØ!"ˆÔØ!ˆÔØ"#ˆÖr   c                óL   € \         P                  R4       RV n        ^ V n        R# )zADiscards the local byte buffer. Useful during shutdown or resets.z$Consumer local block buffer cleared.r   N)r   r   r¹   rº   r6   s   &r   Úclear_bufferÚPrefetchConsumer.clear_bufferÁ  s   € ä�‰Ð;Ô<Ø!ˆÔØ"#ˆÖr   c                ó<   <€ V ^8„  d   QhRS[ RS[RS[S[,          /# )r   rI   Ú	save_datar&   )r   r-   rx   Úbytes)r   r   s   "€r   r   r·   Ç  s+   ø€ ÷ añ a¡3ð a±4ð a¹DÁ½Kñ ar   c              ƒ  óf  "  € V^ 8:  d   . # . p^ pV P                   V,           V n        WA8  EdŸ   \        V P                  4      V P                  ,
          pRpV'       EgZ   V P
                  P                  RJ ;'       g!    V P
                  P                  P                  pV'       d9   V P                  P                  4       '       d   \        P                  R4        V# V P                  P                  4       '       d0   \        P                  R4       V P                  P                  4        V P                  P                  4       G Rj  x€L
 p\        V\         4      '       d4   \        P#                  RV4       V P
                  P%                  V4       Vh VG Rj  x€L
 p	V ;P&                  ^,          un        V P&                  \(        P*                  8¼  d»   V P
                  P,                  RJ;'       d.    V P.                  P0                  V P
                  P,                  8„  p
V P.                  P2                  ;'       d(    V P.                  P0                  \(        P4                  8„  pV'       g   V
'       g   RpM\        P                  R4       W�n        ^ V n        \        V P                  4      pV P                  '       g    V# W,
          p\=        WÕ4      pV'       dƒ   V\        V P                  4      8X  d   V P                  ^ 8X  d   V P                  pM9\6        P>                  ! \@        V P                  V P                  V4      G Rj  x€L
 pVPC                  V4       V ;P                  V,          un        WN,          pV ;P                   V,          un         V'       g   EKˆ  V P                  P                  4        EK¥  V#  ELƒ EL2  \6        P8                   d    h \          d8   p\        P;                  R4       T P
                  P%                  T4       ThRp?ii ; i LÙ5i)	z…Internal method to advance the offset and optionally extract data.

Handles queue exhaustion, producer wakeups, and streak tracking.
FNzConsumer reached EOF.z#Queue is empty. Waking up producer.z#Consumer retrieved an exception: %sTzfSuppressing proactive producer wakeup due to massive variable workload or exceeding user max prefetch.zConsumer caught an error.)"r�   rž   r    r¹   rº   rP   Úproducerr\   rK   ry   r   r   rL   r/   Úgetr{   r‘   Úerrorr’   rš   rG   rœ   rf   rO   r*   r0   r›   rR   r�   r~   rc   Ú	to_threadr   r!   )r   rI   rÄ   ÚchunksÚ	processedÚ	availableÚtrigger_wakeupÚis_producer_stoppedrr   Úblockr¢   Úis_massive_variabler•   ÚneededÚtakeÚchunks   &&&             r   Ú_advanceÚPrefetchConsumer._advanceÇ  sj  é € ð
 �1Œ9ØˆIàˆØˆ	Ø!Ÿ[™[¨4Õ/ˆÔàÕÜ˜D×/Ñ/Ó0°4×3JÑ3JÕJˆIØ"ˆNç�9à×%Ñ%×.Ñ.°$Ð6÷ =ð =Ø×(Ñ(×1Ñ1×<Ñ<ð $÷ '¨4¯:©:×+;Ñ+;×+=Ò+=Ü—L‘LÐ!8Ô9ØðT ˆðQ —:‘:×#Ñ#×%Ò%Ü—L‘LÐ!FÔGØ×%Ñ%×)Ñ)Ô+à!ŸZ™ZŸ^™^Ó-×-�ä˜d¤I×.Ò.Ü—L‘LÐ!FÈÔMØ×%Ñ%×/Ñ/°Ô5Ø�Jð%Ø"&ŸJ�Eà×*Ò*¨aÕ/Õ*à×.Ñ.Ü+×GÑGôHð !×-Ñ-×?Ñ?ÀtÐK÷ Bð BØ $§¡× 4Ñ 4Ø"×/Ñ/×AÑAñ!Bð )ð !ŸL™L×4Ñ4÷ Eð EØ $§¡× 4Ñ 4Ü.×DÑDñ!Eð ,÷ !4×7GØ-1™Nä"ŸL™Lð!Lôð
 +0Ô'Ø./�DÔ+Ü # D×$7Ñ$7Ó 8�Ið ×&×&Ð&Øð* ˆð' Õ%ˆFÜ�vÓ)ˆDçØœ3˜t×2Ñ2Ó3Ô3¸×8OÑ8OÐSTÔ8TØ ×/Ñ/‘Eô #*×"3Ò"3Ü# T×%8Ñ%8¸$×:QÑ:QÐSWó#÷ �Eð —‘˜eÔ$à×#Ò# tÕ+Õ#ØÕˆIØ�KŠK˜4Õ�KßŠ~Ø×!Ñ!×%Ñ%×'àˆòI .ò 'øô> ×-Ñ-ô ØÜ ô Ü×$Ñ$Ð%@ÔAØ×%Ñ%×/Ñ/°Ô2Ø�Gûðúñ ùsœ   ‚A<P1Á?(P1Â(P1Ã7P1Ä AP1ÅOÅAP1ÆO Æ OÆ!AO Ç<A
O É/O É7O É?:O Ê9P1ËB
P1ÍP/ÍAP1Î0 P1ÏO ÏP,Ï4P,Ï52P'Ð'P,Ð,P1c                ó&   <€ V ^8„  d   QhRS[ RS[/# )r   rI   r&   ©r   rÅ   )r   r   s   "€r   r   r·   *  s   ø€ ÷ 9ñ 9¡#ð 9©%ñ 9r   c              ƒ  óò   "  € V^ 8:  d   R# V P                  VRR7      G Rj  x€L
 pV'       g   R# \        V4      ^8X  d
   V^ ,          # \        P                  ! RP                  V4      G Rj  x€L
 #  LP L5i)aœ  Pulls exactly 'size' bytes from the local block or the task queue.

If the local block is exhausted, this will wait on the queue for the next
available chunk of data.

Args:
    size (int): The exact number of bytes to retrieve.

Returns:
    bytes: The requested bytes. This may be shorter than 'size' if EOF is reached.

Raises:
    Exception: Re-raises any exceptions encountered by the producer fetch tasks.
r   T©rÄ   N)rÕ   r    rR   rÊ   Újoin)r   rI   rË   s   && r   ÚconsumeÚPrefetchConsumer.consume*  sf   é € ð �1Œ9Ùà—}‘} T°T�}Ó:×:ˆçÙäˆv‹;˜!ÔØ˜!•9Ðä×&Ò& s§x¡x°Ó8×8Ð8ñ ;ñ 9ùs&   ‚ A7¢A3£A7¯?A7Á.A5Á/A7Á5A7c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   rI   r&   Nr   )r   r   s   "€r   r   r·   F  s   ø€ ÷ 3ñ 3™sð 3 tñ 3r   c              ƒ  óH   "  € V P                  VRR7      G Rj  x€L
  R#  L5i)z7Advances the consumer offset without allocating memory.FrÚ   N)rÕ   )r   rI   s   &&r   ÚskipÚPrefetchConsumer.skipF  s   é € à�m‰m˜D¨EˆmÓ2×2Ô2ùs   ‚"™ š")	r¹   rº   r�   rP   rK   rš   rž   rO   rL   N)r=   r>   r?   r@   rA   r   r¾   rÁ   rÕ   rÜ   rà   rC   rD   rE   s   @r   rN   rN   �  sD   ø‡ € ñ÷$ð $÷4$ð $ò $÷að a÷F9ð 9÷83ö 3r   rN   c                   óÆ   a € ] tR tRt o RtRtRV 3R lR lltR tR tR t	R	 t
V 3R
 lR ltV 3R lR ltR tR tV 3R lR ltV 3R lR ltR tRV 3R lR lltRtV tR# )rQ   iK  a  Orchestrator that manages reading behavior and coordinates background work.

This acts as the main public interface for the file reader. It tracks the
user's reading history, routes seek operations, and links the producer's
network tasks with the consumer's data slicing logic.
Nc                ó&   <€ V ^8„  d   QhRS[ RS[ /# )r   rI   rJ   r   )r   r   s   "€r   r   Ú!BackgroundPrefetcher.__annotate__U  s%   ø€ ÷ ^Fñ ^FÙ ð^FÙ/2ñ^Fr   c                óà  a aaa€ \         P                  RVVS4       VS n        VS n        SS n        Se)   S^ 8:  d"   \         P                  RS4       \        R4      hVS n        RS n        RS n	        ^ S n
        \        ^
R7      S n        RS n        RS n        RS n        RS n        RS n        VVV 3R lo \$        P&                  ! 4       pVS P                  J d   S P                  e	   S! 4        MTS P                  e)   V3R lp\*        P,                  ! S P                  V4       MVe   VS n        S! 4        M\)        R	4      h\         P                  R
4       R#   \(         d    Rp L i ; i)a#  Initializes the background prefetcher.

Args:
    fetcher (Callable): A coroutine of the form `f(start, end)` which gets bytes from the remote.
    size (int): Total byte size of the file being read.
    concurrency (int): Number of concurrent network requests to use for large chunks.
    max_prefetch_size (int, optional): Maximum bytes to prefetch ahead of the current user offset.
    loop (asyncio.AbstractEventLoop, optional): The event loop to attach the prefetcher to.
        If executing synchronously, this should be the fsspec background loop. If executing
        asynchronously (asynchronous=True), this should be None so it can automatically
        inherit the user's currently running event loop.

Raises:
    ValueError: If max_prefetch_size is provided but is not a positive integer.
zJStarting BackgroundPrefetcher. Size: %d, Concurrency: %d, Max Prefetch: %sNz&Invalid max_prefetch_size provided: %szKmax_prefetch_size should be a positive integer to use adaptive prefetching!Fr
   c                  óæ  <€ \         P                  ! 4       Sn        \         P                  ! 4       Sn        \         P
                  ! 4       Sn        \        SP                  SP                  SP                  SR 7      Sn	        \        S SP                  SP                  SP                  SP                  SP                  SP                  SSR7	      Sn        SP                  P                  4        R# ))rK   rL   rO   rP   )	rW   rI   rJ   rK   rL   rM   rO   rP   r_   N)rR   rS   rK   rT   rL   ÚLockÚ_async_lockrN   Úread_trackerrM   rG   rI   rJ   rÇ   rk   )rW   rf   r   s   €€€r   Ú_startÚ-BackgroundPrefetcher.__init__.<locals>._startƒ  s­   ø€ ä Ÿš›ˆDŒJÜ '§¢£ˆDÔÜ&Ÿ|š|›~ˆDÔä,Ø—j‘jØ!×.Ñ.Ø×)Ñ)Ø!ô	ˆDŒMô -ØØ—Y‘YØ ×,Ñ,Ø—j‘jØ!×.Ñ.ØŸ™Ø×)Ñ)Ø!Ø'8ô
ˆDŒMð �M‰M×ÑÖ!r   c               “   ó   <"  € S ! 4        R # 5iro   © )rê   s   €r   Ú_start_wrapperÚ5BackgroundPrefetcher.__init__.<locals>._start_wrapper§  s   øé € Ù–ùs   ƒ
zNo event loop foundz-BackgroundPrefetcher initialization complete.)r   r   rI   rJ   rf   rÉ   r   ÚloopÚ_errorr\   r®   r   ré   rK   rL   rè   rM   rÇ   rR   Úget_running_loopr5   Úfsspec_asynÚsync)	r   rW   rI   rJ   rf   rð   Úcurrent_looprî   rê   s	   ff&&f&  @r   r   ÚBackgroundPrefetcher.__init__U  sQ  û€ ô$ 	�‰ØXØØØô		
ð ˆŒ	Ø&ˆÔØ!2ˆÔàÒ(Ð->À!Ô-CÜ�L‰LÐAÐCTÔUÜØ]óð ð ˆŒ	ØˆŒØˆŒØˆÔÜ1¸Ô<ˆÔàˆŒ
Ø ˆÔØˆÔØˆŒØˆŒ÷	"ð4	 Ü"×3Ò3Ó5ˆLð ˜4Ÿ9™9Ó$¨¯©Ò)>á�HØ�Y‰YÒ"õô ×Ò˜TŸY™Y¨Õ7ØÒ%à$ˆDŒIÙ�Hô Ð4Ó5Ð5ä�‰ÐDÖEøô) ô 	 ØŠLð	 ús   Â7E ÅE-Å,E-c                ó   € V # )zContext manager entry point.rí   r6   s   &r   Ú	__enter__ÚBackgroundPrefetcher.__enter__µ  s   € àˆr   c                ó&   € V P                  4        R# )zEContext manager exit point. Ensures the prefetcher is cleanly closed.N)Úclose©r   Úexc_typeÚexc_valÚexc_tbs   &&&&r   Ú__exit__ÚBackgroundPrefetcher.__exit__¹  s   € à�
‰
Žr   c              ƒ  ó   "  € V # 5i)z"Async context manager entry point.rí   r6   s   &r   Ú
__aenter__ÚBackgroundPrefetcher.__aenter__½  s
   é € àˆùs   ‚c              ƒ  óB   "  € V P                  4       G Rj  x€L
  R#  L5i)zKAsync context manager exit point. Ensures the prefetcher is cleanly closed.N)Úacloserü   s   &&&&r   Ú	__aexit__ÚBackgroundPrefetcher.__aexit__Á  s   é € à�k‰k‹m×Ôùs   ‚–—c                ó    <€ V ^8„  d   QhRS[ /# )r   r•   )r‘   )r   r   s   "€r   r   rä   Å  s   ø€ ÷ ñ ™9ñ r   c                ó>   € \         P                  R V4       Wn        R# )z2Global error state set in BackgroundPrefetcher: %sN)r   rÉ   rñ   r”   s   &&r   r’   ÚBackgroundPrefetcher.set_errorÅ  s   € Ü�‰ÐIÈ1ÔMØŽr   c                ó    <€ V ^8„  d   QhRS[ /# r‡   r   )r   r   s   "€r   r   rä   É  s   ø€ ÷ "ñ "±#ñ "r   c              ƒ  óü   "  € \         P                  R V4       RV n        V P                  P	                  V4      G Rj  x€L
  V P
                  P                  V4       V P                  P                  4        R#  L;5i)z8Handling seek request. Restarting producer at offset: %dN)	r   r   rñ   rÇ   r‹   rM   r¾   ré   r:   rŠ   s   &&r   Ú_restart_producerÚ&BackgroundPrefetcher._restart_producerÉ  s`   é € Ü�‰ØFÈ
ô	
ð ˆŒØ�m‰m×#Ñ# JÓ/×/Ð/Ø�‰×Ñ˜:Ô&Ø×Ñ×ÑÖ!ñ 	0ùs   ‚<A<¾A:¿<A<c           
   ƒ  óh  "  € V P                   ;_uu_4       GRj  x€L
   V P                  '       d   \        R4      h\        P	                  RW4       V P
                  '       d8   \        P                  RV4       Wn        V P                  V4      G Rj  x€L
  EM¯WP                  8w  EdŸ   V P                  P                  V P                  P                  ,
          pV P                  Tu;8  d   V P                  P                  8:  da   M M]\        P	                  RV P                  V4       WP                  ,
          pV P                  P                  V4      G Rj  x€L
  Wn        MàY1u;8:  d   V P                  P                  8  d   M M{\        P	                  RV P                  VV P                  P                  W,
          4       W,
          V P                  n        WP                  n
        WP                  n        Wn        M@\        P	                  RV P                  V4       Wn        V P                  V4      G Rj  x€L
  W!,
          pV P                   P#                  V4       V P                  P%                  V4      G Rj  x€L
 pV ;P                  \'        V4      ,          un        \        P	                  R\'        V4      4       TuuRRR4      GRj  x€L
  #  ELÌ ELT EL� L¨ Ld L  \(        P*                   d   pYpn        h Rp?i\,         ds   p\        P/                  R	4       Ypn        T P                  '       d@   T P                  P                  '       g$   T P                  P1                  4       G Rj  x€L 
  h Rp?ii ; i  + GRj  x€L 
 '       g   i     R# ; i5i)
zGCore internal async fetching logic, protected safely by the async lock.Nz"The file instance has been closed.z)Executing _async_fetch for range %d - %d.z>Recovering from error state. Restarting producer at offset: %dz1Soft seek detected. Skipping ahead from %d to %d.z\Local seek performed. User offset moved from %d to %d. Adjusting buffer index from %d to %d.z5Hard seek detected. Moving user offset from %d to %d.z*Completed _async_fetch. Returned %d bytes.z+Exception raised during asynchronous fetch.)rè   r\   r5   r   r   rñ   Úinfor®   r  rM   r�   rº   rÇ   r[   rà   rž   ré   r"   rÜ   r    rR   r�   r‘   r~   r„   )r   rk   ÚendÚblock_offsetÚskip_amountÚrequested_sizerÔ   r•   s   &&&     r   Ú_async_fetchÚ!BackgroundPrefetcher._async_fetchÒ  s·  é € à×#×#×#Ó#ðAØ—?—?�?Ü&Ð'KÓLÐLä—‘ÐHÈ%ÔUð —;—;�;Ü—K‘KØXØôð (-Ô$Ø×0Ñ0°Ó7×7Ò7Ø×.Ñ.Õ.àŸ™×,Ñ,¨t¯}©}×/OÑ/OÕOð !ð ×'Ñ'¨%ÖO°4·=±=×3OÑ3O×OÜŸ™ØOØ ×,Ñ,Ø!ôð
 ',×.>Ñ.>Õ&>˜Ø"Ÿm™m×0Ñ0°Ó=×=Ð=Ø+0Õ(Ø%ÖE°·±×1EÑ1E×EÜŸ™ðDà ×,Ñ,Ø!Ø ŸM™M×<Ñ<Ø!Õ0ôð <AÕ;O˜Ÿ™Ô8Ø/4Ÿ™Ô,Ø6;Ÿ™Ô3Ø+0Õ(äŸ™ØSØ ×,Ñ,Ø!ôð
 ,1Ô(Ø"×4Ñ4°UÓ;×;Ð;à!$¥�Ø×!Ñ!×%Ñ% nÔ5à"Ÿm™m×3Ñ3°NÓC×C�Ø× Ò ¤C¨£JÕ.Õ ä—‘ÐIÌ3ÈuË:ÔVØ÷s $×#Õ#ò 8ò >ñ, <ñ
 Dñk $øôt ×)Ñ)ô Ø”ØûÜô Ü× Ñ Ð!NÔOØ”Ø—=—=�=¨¯©×)A×)AÐ)AØŸ-™-×,Ñ,Ó.×.Ñ.Øûðú÷{ $×#×#Ñ#üsÙ   ‚N2›K'œN2ŸN¡A5K6ÂK*ÂC	K6Å K-Å!C&K6ÉK0ÉAK6ÊK2ÊAK6ËN2Ë!K4Ë"N2Ë*K6Ë-K6Ë0K6Ë2K6Ë4N2Ë6NÌLÌNÌNÌ ANÍ)NÎN	
ÎNÎNÎNÎN/	ÎNÎ
N/	Î'N/	Î)	N2c              ƒ  óÖ  "  € V P                   ;_uu_4       GRj  x€L
  \        P                  R4       V P                  '       d?   V P                  P                  '       g#   V P                  P                  4       G Rj  x€L
  V P                  P                  4        \        P                  R4       RRR4      GRj  x€L
  R#  Lª LG L
  + GRj  x€L 
 '       g   i     R# ; i5i)zâAsynchronous teardown logic protected by the async lock.

Held for the duration of teardown so a concurrent in-flight
``_async_fetch`` cannot observe a stopped producer/empty queue as
EOF and silently return a truncated read.
Nz4Signaling prefetcher stop and tearing down producer.z)BackgroundPrefetcher closed successfully.)rè   r   r   rÇ   r\   r„   rM   rÁ   r6   s   &r   Ú_async_closeÚ!BackgroundPrefetcher._async_close  sŒ   é € ð ×#×#×#Ó#Ü�L‰LÐOÔPà�}�}ˆ} T§]¡]×%=×%=Ð%=Ø—m‘m×(Ñ(Ó*×*Ð*à�M‰M×&Ñ&Ô(Ü�L‰LÐDÔE÷ $×#Ó#ñ +÷	 $×#×#Ó#üsc   ‚C)›CœC)ŸACÁ#CÂ CÂ3CÂ4C)Â?C
Ã C)ÃCÃ
C)ÃC&	ÃCÃ
C&	ÃC&	Ã 	C)c                óH   <€ V ^8„  d   QhRS[ R,          RS[ R,          RS[/# ©r   rk   Nr  r&   rØ   )r   r   s   "€r   r   rä   (  s*   ø€ ÷ 3ñ 3¡#¨¥*ð 3±3¸µ:ð 3Á%ñ 3r   c              ƒ  óV  "  € Vf   ^ pVf   V P                   p\        W P                   4      p\        P                  RW4       WP                   8¼  g   W8¼  d   R# V P                  '       d!   \        P                  R4       \        R4      hV P                  W4      G Rj  x€L
 #  L5i)z)Asynchronous API counterpart to `_fetch`.Nz7Asynchronous afetch called for bounds start=%s, end=%s.r   z=Cannot fetch data: BackgroundPrefetcher is stopped or closed.zŒThe file instance has been closed. This can occur if a close operation is executed concurrently while a read operation is still in progress.)rI   rc   r   r   r\   rÉ   r5   r  ©r   rk   r  s   &&&r   ÚafetchÚBackgroundPrefetcher.afetch(  s•   é € àŠ=ØˆEØŠ;Ø—)‘)ˆCä�#—y‘yÓ!ˆÜ�‰ØEÀuô	
ð —I‘IÔ ¤Ùà�?�?ˆ?Ü�L‰LØOôô ðXóð ð
 ×&Ñ& uÓ2×2Ð2Ñ2ùs   ‚A+B)Á.4B)Â"B'Â#B)c                óH   <€ V ^8„  d   QhRS[ R,          RS[ R,          RS[/# r  rØ   )r   r   s   "€r   r   rä   B  s/   ø€ ÷ Dñ D™3 �:ð D©C°$­Jð D¹5ñ Dr   c                óZ   € \         P                  ! V P                  V P                  W4      # )z/Synchronous API wrapper delegating to `afetch`.)ró   rô   rð   r  r  s   &&&r   ÚfetchÚBackgroundPrefetcher.fetchB  s!   € ô ×Ò §	¡	¨4¯;©;¸ÓCÐCr   c              ƒ  óP   "  € RV n         V P                  4       G Rj  x€L
  R#  L5i)z>Safely shuts down the prefetcher from an asynchronous context.TN)r\   r  r6   s   &r   r  ÚBackgroundPrefetcher.acloseG  s   é € àˆŒØ×ÑÓ!×!Ô!ùs   ‚&�$ž&c                ó.   <€ V ^8„  d   QhRS[ R,          /# )r   ÚtimeoutN)Úfloat)r   r   s   "€r   r   rä   L  s   ø€ ÷ ñ ™U T�\ñ r   c                ó  € RV n          \        V P                  V P                  VRR7       R#   \        P
                   d    \        P                  RT4        R# \         d    \        P                  RRR7        R# i ; i)a€  Safely shuts down the prefetcher from a synchronous context.

Schedules teardown on the IO loop. If the wait times out, teardown
continues in the background to let in-flight reads finish cleanly.

Args:
    timeout: Maximum seconds to wait for teardown to finish. Defaults
        to 10.0 seconds. If 0 or negative, teardown runs fire-and-forget.
        If None, waits indefinitely.
TzBackgroundPrefetcher teardown)r(  ÚdescriptionzbBackgroundPrefetcher teardown did not complete within %ss; it will keep running in the background.z,Exception while closing BackgroundPrefetcher)Úexc_infoN)	r\   r   rð   r  ró   ÚFSTimeoutErrorr   Úwarningr‘   )r   r(  s   &&r   rû   ÚBackgroundPrefetcher.closeL  sy   € ð ˆŒð	ÜØ—	‘	Ø×!Ñ!ØØ;÷	øô ×)Ñ)ô 	Ü�N‰Nð:à÷ô
 ô 	Ü�N‰NØ>Èð ÷ ð	ús   ‰#. ®+BÁBÁ%BÂ B)rè   rñ   rJ   rM   r\   rð   rf   rÇ   rK   ré   rI   r®   rL   )NN)g      $@)r=   r>   r?   r@   rA   rÇ   r   rø   r   r  r  r’   r  r  r  r  r#  r  rû   rC   rD   rE   s   @r   rQ   rQ   K  s   ø‡ € ñð €H÷^Fò ^Fò@òòò÷ð ÷"ð "òDòLF÷ 3ð 3÷4Dð Dò
"÷
÷ ð r   rQ   )rR   ÚloggingrX   Úcollectionsr   Ú r   ró   r   Úutilsr   Ú	getLoggerr=   r   r   rG   rN   rQ   rí   r   r   Ú<module>r5     s]   ðÛ Û Û Ý å !Ý Ý à	×	Ò	˜8Ó	$€÷Eñ E÷Px#ñ x#÷v	x3ñ x3÷v^ó ^r   