
    "h                     h     G d  d      Z  G d de       Z G d de       Z G d de       Z e       Zy)	c                   ^    e Zd ZdZddZd Zd ZddZddZd Z	d	 Z
d
 Zd Zedd       Zy)Callbacka  
    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                 D    || _         || _        |xs i | _        || _        y N)sizevaluehookskw)selfr   r   r   kwargss        M/var/www/html/sandstorm/venv/lib/python3.12/site-packages/fsspec/callbacks.py__init__zCallback.__init__   s"    	
[b
    c                 2    || _         | j                          y)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_sizezCallback.set_size   s     			r   c                 2    || _         | j                          y)z
        Set the internal value state

        Triggers ``call()``

        Parameters
        ----------
        value: int
        Nr   r   )r
   r   s     r   absolute_updatezCallback.absolute_update*   s     
		r   c                 N    | xj                   |z  c_         | j                          y)z
        Delta increment the internal counter

        Triggers ``call()``

        Parameters
        ----------
        inc: int
        Nr   r
   incs     r   relative_updatezCallback.relative_update7   s     	

c
		r   c                 n   | j                   sy| j                  j                         }|j                  |       |r:|| j                   vry | j                   |   | j                  | j
                  fi |S | j                   j                         xs g D ]   } || j                  | j
                  fi | " y)a  
        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   r   zCallback.callD   s     zzWW\\^
		&

*(4::i(DJJE"EEJJ%%'-2 	.DDJJ-"-	.r   c              #   B   K   |D ]  }| j                          |  yw)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   wrapzCallback.wrap[   s(       	D  "J	s   c                      y)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
        -------

        N r
   path_1path_2r   s       r   branchzCallback.branchh   s    , r   c                      y r   r%   )r
   ___s      r   no_opzCallback.no_op   s    r   c                     | j                   S )zP
        If undefined methods are called on this class, nothing happens
        )r-   )r
   r"   s     r   __getattr__zCallback.__getattr__   s     zzr   c                     |t         S |S )a  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.
        )_DEFAULT_CALLBACK)clsmaybe_callbacks     r   as_callbackzCallback.as_callback   s     !$$r   )N    N   r   )__name__
__module____qualname____doc__r   r   r   r   r   r#   r)   r-   r/   classmethodr4   r%   r   r   r   r      sH    (..0 	 	r   r   c                       e Zd ZdZd Zy)NoOpCallbackz>
    This implementation of Callback does exactly nothing
    c                      y r   r%   )r
   argsr   s      r   r   zNoOpCallback.call   s    r   N)r8   r9   r:   r;   r   r%   r   r   r>   r>      s    r   r>   c                   0     e Zd ZdZd fd	Zd Zd Z xZS )DotPrinterCallbackz
    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    || _         t        |   di | y )Nr%   )chrsuperr   )r
   chr_to_printr   	__class__s      r   r   zDotPrinterCallback.__init__   s    "6"r   c                      t        d      |d<   y)z;Mutate kwargs to add new instance with different print char.callbackN)rB   r&   s       r   r)   zDotPrinterCallback.branch   s    /4zr   c                 2    t        | j                  d       y)zJust outputs a character )endN)printrD   )r
   r   s     r   r   zDotPrinterCallback.call   s    dhhBr   )#)r8   r9   r:   r;   r   r)   r   __classcell__rG   s   @r   rB   rB      s    #5 r   rB   c                   8     e Zd ZdZd fd	Zd ZddZd Z xZS )TqdmCallbackae  
    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.

    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"}),
        )
    c                     	 dd l }|| _        |xs i | _        t	        |   |i | y # t        $ r}t        d      |d }~ww xY w)Nr5   z0Using TqdmCallback requires tqdm to be installed)tqdm_tqdmImportError_tqdm_kwargsrE   r   )r
   tqdm_kwargsr@   r   rU   excerG   s         r   r   zTqdmCallback.__init__   sX    	DJ (-2$)&)  	B	s   ) 	A>Ac                 ^     | j                   j                  dd|i| j                  | _        y )Ntotalr%   )rV   rU   rX   r   s     r   r   zTqdmCallback.set_size   s&    #DJJOOD$D$2C2CD	r   c                 :    | j                   j                  |       y r   )rU   r   r   s     r   r   zTqdmCallback.relative_update   s    		r   c                 F    | j                   j                          d | _         y r   )rU   close)r
   s    r   __del__zTqdmCallback.__del__   s    			r   r   r6   )	r8   r9   r:   r;   r   r   r   r`   rP   rQ   s   @r   rS   rS      s    B*Er   rS   N)r   r>   rB   rS   r1   r%   r   r   <module>ra      sA   R Rj8    *78 7t !N r   