o
    Vګe                     @   sH   G d d dZ G dd de ZG dd de ZG dd de Ze ZdS )	c                   @   sl   e Zd ZdZdddZdd Zdd	 ZdddZdddZdd Z	dd Z
dd Zdd ZedddZdS )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)``
    N    c                 K   s    || _ || _|p	i | _|| _d S N)sizevaluehookskw)selfr   r   r   kwargs r
   g/vol/project/2023/60021/g236002117/DeepSeek-Coder/venv/lib/python3.10/site-packages/fsspec/callbacks.py__init__   s   

zCallback.__init__c                 C      || _ |   dS )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   r
   r
   r   set_size   s   zCallback.set_sizec                 C   r   )z
        Set the internal value state

        Triggers ``call()``

        Parameters
        ----------
        value: int
        Nr   r   )r   r   r
   r
   r   absolute_update*   s   
zCallback.absolute_update   c                 C   s   |  j |7  _ |   dS )z
        Delta increment the internal counter

        Triggers ``call()``

        Parameters
        ----------
        inc: int
        Nr   r   incr
   r
   r   relative_update7   s   
zCallback.relative_updatec                 K   sz   | j sdS | j }|| |r&|| j vrdS | j | | j| jfi |S | j  p,g D ]}|| j| jfi | q-dS )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   hookr
   r
   r   r   D   s   


zCallback.callc                 c   s    |D ]	}|    |V  qdS )z
        Wrap an iterable to call ``relative_update`` on each iterations

        Parameters
        ----------
        iterable: Iterable
            The iterable that is being wrapped
        N)r   )r   iterableitemr
   r
   r   wrap[   s
   	zCallback.wrapc                 C   s   dS )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   path_1path_2r	   r
   r
   r   branchh   s   zCallback.branchc                 O      d S r   r
   )r   ___r
   r
   r   no_op      zCallback.no_opc                 C   s   | j S )zP
        If undefined methods are called on this class, nothing happens
        )r&   )r   r   r
   r
   r   __getattr__   s   zCallback.__getattr__c                 C   s   |du r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.
        N)_DEFAULT_CALLBACK)clsmaybe_callbackr
   r
   r   as_callback   s   zCallback.as_callback)Nr   Nr   r   )__name__
__module____qualname____doc__r   r   r   r   r   r   r"   r&   r(   classmethodr,   r
   r
   r
   r   r      s    


r   c                   @   s   e Zd ZdZdd ZdS )NoOpCallbackz>
    This implementation of Callback does exactly nothing
    c                 O   r#   r   r
   )r   argsr	   r
   r
   r   r      r'   zNoOpCallback.callN)r.   r/   r0   r1   r   r
   r
   r
   r   r3      s    r3   c                       s2   e Zd ZdZd	 fdd	Zdd Zdd Z  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                    s   || _ t jdi | d S )Nr
   )chrsuperr   )r   chr_to_printr	   	__class__r
   r   r      s   zDotPrinterCallback.__init__c                 C   s   t d|d< dS )z;Mutate kwargs to add new instance with different print char.callbackN)r5   r   r
   r
   r   r"      s   zDotPrinterCallback.branchc                 K   s   t | jdd dS )zJust outputs a character )endN)printr7   )r   r	   r
   r
   r   r      s   zDotPrinterCallback.call)r6   )r.   r/   r0   r1   r   r"   r   __classcell__r
   r
   r:   r   r5      s
    r5   c                       s<   e Zd ZdZd fdd	Zdd Zddd	Zd
d Z  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"}),
        )
    Nc              
      sV   z	dd l }|| _W n ty } ztd|d }~ww |pi | _t j|i | d S )Nr   z0Using TqdmCallback requires tqdm to be installed)tqdm_tqdmImportError_tqdm_kwargsr8   r   )r   tqdm_kwargsr4   r	   rC   excer:   r
   r   r      s   

zTqdmCallback.__init__c                 C   s   | j jdd|i| j| _d S )Ntotalr
   )rD   rC   rF   r   r
   r
   r   r      s   zTqdmCallback.set_sizer   c                 C   s   | j | d S r   )rC   r   r   r
   r
   r   r      s   zTqdmCallback.relative_updatec                 C   s   | j   d | _ d S r   )rC   close)r   r
   r
   r   __del__   s   

zTqdmCallback.__del__r   r-   )	r.   r/   r0   r1   r   r   r   rK   rA   r
   r
   r:   r   rB      s    !
rB   N)r   r3   r5   rB   r)   r
   r
   r
   r   <module>   s     	
: