
    7Th#                     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        H/var/www/auris/envauris/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$    : 	FF+zz*&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6v6%GuGGG 76G 76s%   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     zzWW\\^
		&

*::i(DJJE"EEJJ%%'-2-DDJJ-"- .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     zzr   c                     Uc  [         $ U$ )zTransform 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    (8B
..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    dhhB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`    99LTYYL$:K:KLDI))				diikk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&    99 IIOODI !r   c                 "    U R                  5       $ r   r   r   s    r   __del__TqdmCallback.__del__@  s    zz|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   