U
    ¬9%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
   úO/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/fsspec/callbacks.pyÚ__init__   s    
zCallback.__init__c                 C   s   || _ |  ¡  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   s   || _ |  ¡  dS )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   sr   | j s
dS | j ¡ }| |¡ |rH|| j kr0dS | j | | j| jf|ŽS | j  ¡ pTg D ]}|| j| jf|Ž qVd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   Zpath_1Zpath_2r	   r
   r
   r   Úbranchh   s    zCallback.branchc                 O   s   d S r   r
   )r   Ú_Ú__r
   r
   r   Úno_op€   s    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k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)ÚclsZmaybe_callbackr
   r
   r   Úas_callback‰   s    zCallback.as_callback)Nr   N)r   )N)N)Ú__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   s   d S r   r
   )r   Úargsr	   r
   r
   r   r   ›   s    zNoOpCallback.callN)r'   r(   r)   r*   r   r
   r
   r
   r   r,   –   s   r,   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f |Ž d S r   )ÚchrÚsuperr   )r   Z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)r.   r   r
   r
   r   r   «   s    zDotPrinterCallback.branchc                 K   s   t | jdd dS )zJust outputs a characterÚ )ÚendN)Úprintr0   )r   r	   r
   r
   r   r   ¯   s    zDotPrinterCallback.call)r/   )r'   r(   r)   r*   r   r   r   Ú__classcell__r
   r
   r2   r   r.   Ÿ   s   r.   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              
      s\   zdd l }|| _W n, tk
r> } ztdƒ|‚W 5 d }~X Y nX |pFi | _tƒ j||Ž d S )Nr   z0Using TqdmCallback requires tqdm to be installed)ÚtqdmÚ_tqdmÚImportErrorÚ_tqdm_kwargsr1   r   )r   Ztqdm_kwargsr-   r	   r;   Zexcer2   r
   r   r   Ö   s    
ÿþ
zTqdmCallback.__init__c                 C   s   | j jf d|i| j—Ž| _d S )NÚtotal)r<   r;   r>   r   r
   r
   r   r   ã   s    zTqdmCallback.set_sizer   c                 C   s   | j  |¡ d S r   )r;   r   r   r
   r
   r   r   æ   s    zTqdmCallback.relative_updatec                 C   s   | j  ¡  d | _ d S r   )r;   Úclose)r   r
   r
   r   Ú__del__é   s    
zTqdmCallback.__del__)N)r   )	r'   r(   r)   r*   r   r   r   rA   r9   r
   r
   r2   r   r:   ´   s
   !
r:   N)r   r,   r.   r:   r$   r
   r
   r
   r   Ú<module>   s
    	: