ó
    Ð]jú#  ã                   óx   • S SK Jr   " S S5      r " S S\5      r " S S\5      r " S S	\5      r\" 5       =rrg
)é    )Úwrapsc                   óŒ   • \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rSS jrSS jrS rS rS rS r\SS j5       rSrg)ÚCallbacké   ah  
Base class and interface for callback mechanism

This class can be used directly for monitoring file transfers by
providing ``callback=Callback(hooks=...)`` (see the ``hooks`` argument,
below), or subclassed for more specialised behaviour.

Parameters
----------
size: int (optional)
    Nominal quantity for the value that corresponds to a complete
    transfer, e.g., total number of tiles or total number of
    bytes
value: int (0)
    Starting internal counter value
hooks: dict or None
    A dict of named functions to be called on each update. The signature
    of these must be ``f(size, value, **kwargs)``
Nc                 óH   • Xl         X l        U=(       d    0 U l        X@l        g ©N)ÚsizeÚvalueÚhooksÚkw)Úselfr	   r
   r   Úkwargss        ÚM/home/mande/repo/quber/.venv/lib/python3.13/site-packages/fsspec/callbacks.pyÚ__init__ÚCallback.__init__   s   € ØŒ	ØŒ
Ø—[˜bˆŒ
Ø�ó    c                 ó   • U $ r   © ©r   s    r   Ú	__enter__ÚCallback.__enter__   s   € Øˆr   c                 ó$   • U R                  5         g r   ©Úclose)r   Úexc_argss     r   Ú__exit__ÚCallback.__exit__"   s   € Ø�
‰
�r   c                 ó   • g)zClose callback.Nr   r   s    r   r   ÚCallback.close%   s   � r   c                 óR   • U R                  XU5        UR                  S[        5      $ )aê  
Return callback for child transfers

If this callback is operating at a higher level, e.g., put, which may
trigger transfers that can also be monitored. The function returns a callback
that has to be passed to the child method, e.g., put_file,
as `callback=` argument.

The implementation uses `callback.branch` for compatibility.
When implementing callbacks, it is recommended to override this function instead
of `branch` and avoid calling `super().branched(...)`.

Prefer using this function over `branch`.

Parameters
----------
path_1: str
    Child's source path
path_2: str
    Child's destination path
**kwargs:
    Arbitrary keyword arguments

Returns
-------
callback: Callback
    A callback instance to be passed to the child method
Úcallback)ÚbranchÚpopÚDEFAULT_CALLBACK©r   Úpath_1Úpath_2r   s       r   ÚbranchedÚCallback.branched(   s$   € ð: 	�‰�F FÔ+à�z‰z˜*Ô&6Ó7Ð7r   c                 óD   ^ ^• [        T5      S[        4UU 4S jj5       nU$ )z9
Wraps a coroutine, and pass a new child callback to it.
Úpath2c              ›   ó’   >#   • TR                   " X40 UD6 nT" X4SU0UD6I S h  v•N sS S S 5        $  N! , (       d  f       g = f7f)Nr!   )r(   )Úpath1r+   r   ÚchildÚfnr   s       €€r   ÚfuncÚ"Callback.branch_coro.<locals>.funcN   sA   øé € à—’˜uÑ6¨vÒ6¸%Ù ÑG°uÐGÀÑG×G÷ 7Ñ6ÙG÷ 7Õ6üs%   ƒA—6¦4§6ª
A´6¶
AÁ A)r   Ústr)r   r/   r0   s   `` r   Úbranch_coroÚCallback.branch_coroI   s,   ù€ ô
 
ˆr‹ð	H¤S÷ 	Hó 
ð	Hð ˆr   c                 ó0   • Xl         U R                  5         g)z§
Set the internal maximum size attribute

Usually called if not initially set at instantiation. Note that this
triggers a ``call()``.

Parameters
----------
size: int
N)r	   Úcall)r   r	   s     r   Úset_sizeÚCallback.set_sizeU   s   € ð Œ	Ø�	‰	�r   c                 ó0   • Xl         U R                  5         g)zU
Set the internal value state

Triggers ``call()``

Parameters
----------
value: int
N©r
   r6   )r   r
   s     r   Úabsolute_updateÚCallback.absolute_updatec   s   € ð Œ
Ø�	‰	�r   c                 óN   • U =R                   U-  sl         U R                  5         g)z[
Delta increment the internal counter

Triggers ``call()``

Parameters
----------
inc: int
Nr:   )r   Úincs     r   Úrelative_updateÚCallback.relative_updatep   s   € ð 	�
Š
�cÑ�
Ø�	‰	�r   c                 ó’  • U R                   (       d  gU R                  R                  5       nUR                  U5        U(       a;  XR                   ;  a  gU R                   U   " U R                  U R
                  40 UD6$ U R                   R                  5       =(       d    /  H!  nU" U R                  U R
                  40 UD6  M#     g)zÕ
Execute hook(s) with current state

Each function is passed the internal size and current value

Parameters
----------
hook_name: str or None
    If given, execute on this hook
kwargs: passed on to (all) hook(s)
N)r   r   ÚcopyÚupdater	   r
   Úvalues)r   Ú	hook_namer   r   Úhooks        r   r6   ÚCallback.call}   s’   € ð �z�zØØ�W‰W�\‰\‹^ˆØ
�	‰	�&ÔÞØ§
¡
Ó*ØØ—:‘:˜iÒ(¨¯©°D·J±JÑEÀ"ÑEÐEØ—J‘J×%Ñ%Ó'×-¨2Ò-ˆDÙ�—‘˜DŸJ™JÑ-¨"Ô-ò .r   c              #   óF   #   • U H  nU R                  5         Uv •  M     g7f)z’
Wrap an iterable to call ``relative_update`` on each iterations

Parameters
----------
iterable: Iterable
    The iterable that is being wrapped
N)r?   )r   ÚiterableÚitems      r   ÚwrapÚCallback.wrap”   s"   é € ó ˆDØ× Ñ Ô"ØŒJò ùs   ‚!c                 ó   • g)a»  
Set callbacks for child transfers

If this callback is operating at a higher level, e.g., put, which may
trigger transfers that can also be monitored. The passed kwargs are
to be *mutated* to add ``callback=``, if this class supports branching
to children.

Parameters
----------
path_1: str
    Child's source path
path_2: str
    Child's destination path
kwargs: dict
    arguments passed to child method, e.g., put_file.

Returns
-------

Nr   r%   s       r   r"   ÚCallback.branch¡   s   € ð, r   c                 ó   • g r   r   )r   Ú_Ú__s      r   Úno_opÚCallback.no_op¹   s   € Ør   c                 ó   • U R                   $ )z@
If undefined methods are called on this class, nothing happens
)rR   )r   rJ   s     r   Ú__getattr__ÚCallback.__getattr__¼   s   € ð �z‰zÐr   c                 ó   • Uc  [         $ U$ )zäTransform callback=... into Callback instance

For the special value of ``None``, return the global instance of
``NoOpCallback``. This is an alternative to including
``callback=DEFAULT_CALLBACK`` directly in a method signature.
)r$   )ÚclsÚmaybe_callbacks     r   Úas_callbackÚCallback.as_callbackÂ   s   € ð Ñ!Ü#Ð#ØÐr   )r   r   r	   r
   )Nr   N)é   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r   r(   r3   r7   r;   r?   r6   rK   r"   rR   rU   ÚclassmethodrZ   Ú__static_attributes__r   r   r   r   r      sb   † ñô(òòòò8òB
òòôô.ò.òò0òð ó	ó ó	r   r   c                   ó   • \ rS rSrSrS rSrg)ÚNoOpCallbackéÏ   z6
This implementation of Callback does exactly nothing
c                 ó   • g r   r   ©r   Úargsr   s      r   r6   ÚNoOpCallback.callÔ   s   € Ør   r   N)r]   r^   r_   r`   ra   r6   rc   r   r   r   re   re   Ï   s   † ñõr   re   c                   ó<   ^ • \ rS rSrSrSU 4S jjrS rS rSrU =r	$ )ÚDotPrinterCallbackéØ   z´
Simple example Callback implementation

Almost identical to Callback with a hook that prints a char; here we
demonstrate how the outer layer may print "#" and the inner layer "."
c                 ó2   >• Xl         [        TU ]  " S0 UD6  g )Nr   )ÚchrÚsuperr   )r   Úchr_to_printr   Ú	__class__s      €r   r   ÚDotPrinterCallback.__init__à   s   ø€ ØŒÜ‰ÒÑ"˜6Ó"r   c                 ó    • [        S5      US'   g)z;Mutate kwargs to add new instance with different print charÚ.r!   N)rl   r%   s       r   r"   ÚDotPrinterCallback.branchä   s   € ä/°Ó4ˆˆzÒr   c                 ó,   • [        U R                  SS9  g)zJust outputs a characterÚ )ÚendN)Úprintro   )r   r   s     r   r6   ÚDotPrinterCallback.callè   s   € äˆd�h‰h˜BÓr   )ro   )Ú#)
r]   r^   r_   r`   ra   r   r"   r6   rc   Ú__classcell__©rr   s   @r   rl   rl   Ø   s   ø† ñ÷#ò5÷ ð  r   rl   c                   óB   ^ • \ rS rSrSrSU 4S jjrS rS rS rSr	U =r
$ )	ÚTqdmCallbackéí   a7  
A callback to display a progress bar using tqdm

Parameters
----------
tqdm_kwargs : dict, (optional)
    Any argument accepted by the tqdm constructor.
    See the `tqdm doc <https://tqdm.github.io/docs/tqdm/#__init__>`_.
    Will be forwarded to `tqdm_cls`.
tqdm_cls: (optional)
    subclass of `tqdm.tqdm`. If not passed, it will default to `tqdm.tqdm`.

Examples
--------
>>> import fsspec
>>> from fsspec.callbacks import TqdmCallback
>>> fs = fsspec.filesystem("memory")
>>> path2distant_data = "/your-path"
>>> fs.upload(
        ".",
        path2distant_data,
        recursive=True,
        callback=TqdmCallback(),
    )

You can forward args to tqdm using the ``tqdm_kwargs`` parameter.

>>> fs.upload(
        ".",
        path2distant_data,
        recursive=True,
        callback=TqdmCallback(tqdm_kwargs={"desc": "Your tqdm description"}),
    )

You can also customize the progress bar by passing a subclass of `tqdm`.

.. code-block:: python

    class TqdmFormat(tqdm):
        '''Provides a `total_time` format parameter'''
        @property
        def format_dict(self):
            d = super().format_dict
            total_time = d["elapsed"] * (d["total"] or 0) / max(d["n"], 1)
            d.update(total_time=self.format_interval(total_time) + " in total")
            return d

>>> with TqdmCallback(
        tqdm_kwargs={
            "desc": "desc",
            "bar_format": "{total_time}: {percentage:.0f}%|{bar}{r_bar}",
        },
        tqdm_cls=TqdmFormat,
    ) as callback:
        fs.upload(".", path2distant_data, recursive=True, callback=callback)
c                 óÌ   >•  SSK J n  UR                  SU5      U l        U=(       d    0 U l        S U l         [
        TU ]  " U0 UD6  g ! [         a  n[        S5      UeS nAff = f)Nr   )Útqdmz0Using TqdmCallback requires tqdm to be installedÚtqdm_cls)rƒ   ÚImportErrorr#   Ú	_tqdm_clsÚ_tqdm_kwargsrp   r   )r   Útqdm_kwargsri   r   rƒ   Úexcerr   s         €r   r   ÚTqdmCallback.__init__'  sj   ø€ ð	Ý!ð  Ÿ™ J°Ó5ˆŒØ'×-¨2ˆÔØˆŒ	Ü‰Ò˜$Ð) &Ó)øô ó 	ÜØBóàðûð	ús   ƒA Á
A#ÁAÁA#c                 ó&  • U R                   c-  U R                  " SSU R                  0U R                  D6U l         U R                  U R                   l        U R                   R                  U R                  U R                   R                  -
  5        g )NÚtotalr   )rƒ   r†   r	   r‡   rŒ   rC   r
   Únrh   s      r   r6   ÚTqdmCallback.call5  s`   € Ø�9‰9ÑØŸšÑL¨T¯Y©YÐL¸$×:KÑ:KÑLˆDŒIØŸ)™)ˆ�	‰	ŒØ�	‰	×Ñ˜Ÿ™ d§i¡i§k¡kÑ1Õ2r   c                 ób   • U R                   b"  U R                   R                  5         S U l         g g r   )rƒ   r   r   s    r   r   ÚTqdmCallback.close;  s&   € Ø�9‰9Ñ Ø�I‰I�O‰OÔØˆD�Ið !r   c                 ó"   • U R                  5       $ r   r   r   s    r   Ú__del__ÚTqdmCallback.__del__@  s   € Ø�z‰z‹|Ðr   )r†   r‡   rƒ   r   )r]   r^   r_   r`   ra   r   r6   r   r’   rc   r}   r~   s   @r   r€   r€   í   s"   ø† ñ7÷r*ò3ò÷
ð r   r€   N)Ú	functoolsr   r   re   rl   r€   r$   Ú_DEFAULT_CALLBACKr   r   r   Ú<module>r–      sL   ðÝ ÷Hñ HôV�8ô ô ˜ô  ô*T�8ô Tñn (4£~Ð 5Ð Ñ$r   