§
    dŠtjú#  ã                   ó˜   — d dl mZ  G d„ d¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ d	e¦  «        Z e¦   «         xZZd
S )é    )Úwrapsc                   ó„   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd„ Zd	„ Z	d
„ Z
d„ Zdd„Zdd„Zd„ Zd„ Zd„ Zd„ Ze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)``
    Nr   c                 óB   — || _         || _        |pi | _        || _        d S ©N)ÚsizeÚvalueÚhooksÚkw)Úselfr   r	   r
   Úkwargss        úN/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/fsspec/callbacks.pyÚ__init__zCallback.__init__   s&   € ØˆŒ	ØˆŒ
Ø�[˜bˆŒ
ØˆŒˆˆó    c                 ó   — | S r   © ©r   s    r   Ú	__enter__zCallback.__enter__   s   € Øˆr   c                 ó.   — |                       ¦   «          d S r   ©Úclose)r   Úexc_argss     r   Ú__exit__zCallback.__exit__"   s   € Ø�
Š
‰Œˆˆˆr   c                 ó   — dS )zClose callback.Nr   r   s    r   r   zCallback.close%   s   € € € r   c                 óf   — |                       |||¦  «         |                     dt          ¦  «        S )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   ÚbranchedzCallback.branched(   s/   € ð: 	�Š�F˜F FÑ+Ô+Ð+à�zŠz˜*Õ&6Ñ7Ô7Ð7r   c                 óP   ‡ ‡— t          ‰¦  «        dt          fˆˆ fd„¦   «         }|S )zI
        Wraps a coroutine, and pass a new child callback to it.
        Úpath2c              ›   ó~   •K  —  ‰j         | |fi |¤Ž5 } ‰| |fd|i|¤Žƒ d {V —†cd d d ¦  «         S # 1 swxY w Y   d S )Nr   )r#   )Úpath1r%   r   ÚchildÚfnr   s       €€r   Úfuncz"Callback.branch_coro.<locals>.funcN   sÅ   øè è € à�”˜u eÐ6Ð6¨vÐ6Ð6ð H¸%Ø˜R  uÐGÐG°uÐGÀÐGÐGÐGÐGÐGÐGÐGÐGðHð Hð Hð Hñ Hô Hð Hð Hð Hð Hð Hð Høøøð Hð Hð Hð Hð Hð Hs   “2²6¹6)r   Ústr)r   r)   r*   s   `` r   Úbranch_corozCallback.branch_coroI   sO   øø€ õ
 
ˆr‰Œð	H¥Sð 	Hð 	Hð 	Hð 	Hð 	Hð 	Hñ 
Œð	Hð ˆr   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   s     r   Úset_sizezCallback.set_sizeU   s   € ð ˆŒ	Ø�	Š	‰Œˆˆˆr   c                 ó<   — || _         |                      ¦   «          dS )z…
        Set the internal value state

        Triggers ``call()``

        Parameters
        ----------
        value: int
        N©r	   r.   )r   r	   s     r   Úabsolute_updatezCallback.absolute_updatec   s   € ð ˆŒ
Ø�	Š	‰Œˆˆˆr   é   c                 óN   — | xj         |z  c_         |                      ¦   «          dS )z‹
        Delta increment the internal counter

        Triggers ``call()``

        Parameters
        ----------
        inc: int
        Nr1   )r   Úincs     r   Úrelative_updatezCallback.relative_updatep   s%   € ð 	ˆ
Œ
�cÑˆ
Œ
Ø�	Š	‰Œˆˆˆr   c                 ó0  — | 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 |¤Ž Œ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   Úhooks        r   r.   zCallback.call}   sÁ   € ð Œzð 	ØˆFØŒW�\Š\‰^Œ^ˆØ
�	Š	�&ÑÔÐØð 	FØ ¤
Ð*Ð*Ø�Ø(�4”:˜iÔ(¨¬°D´JÐEÐEÀ"ÐEÐEÐEØ”J×%Ò%Ñ'Ô'Ð-¨2ð 	.ð 	.ˆDØˆD�”˜DœJÐ-Ð-¨"Ð-Ð-Ð-Ð-ð	.ð 	.r   c              #   óD   K  — |D ]}|                       ¦   «          |V — ŒdS )zÂ
        Wrap an iterable to call ``relative_update`` on each iterations

        Parameters
        ----------
        iterable: Iterable
            The iterable that is being wrapped
        N)r6   )r   ÚiterableÚitems      r   ÚwrapzCallback.wrap”   s>   è è € ð ð 	ð 	ˆDØ× Ò Ñ"Ô"Ð"ØˆJˆJˆJˆJð	ð 	r   c                 ó   — 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    s       r   r   zCallback.branch¡   s	   € ð, ˆtr   c                 ó   — d S 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
        )rE   )r   r?   s     r   Ú__getattr__zCallback.__getattr__¼   s   € ð ŒzÐ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.
        )r   )ÚclsÚmaybe_callbacks     r   Úas_callbackzCallback.as_callbackÂ   s   € ð Ð!Ý#Ð#ØÐr   )Nr   N)r3   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r#   r,   r/   r2   r6   r.   r@   r   rE   rG   ÚclassmethodrK   r   r   r   r   r      s   € € € € € ðð ð(ð ð ð ðð ð ðð ð ðð ð ð8ð 8ð 8ðB
ð 
ð 
ðð ð ðð ð ðð ð ð ð.ð .ð .ð .ð.ð ð ðð ð ð0ð ð ðð ð ð ð	ð 	ð 	ñ „[ð	ð 	ð 	r   r   c                   ó   — e Zd ZdZd„ ZdS )ÚNoOpCallbackz>
    This implementation of Callback does exactly nothing
    c                 ó   — d S r   r   ©r   Úargsr   s      r   r.   zNoOpCallback.callÔ   s   € Øˆtr   N)rL   rM   rN   rO   r.   r   r   r   rR   rR   Ï   s-   € € € € € ðð ðð ð ð ð r   rR   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                 óH   •— || _          t          ¦   «         j        di |¤Ž d S )Nr   )ÚchrÚsuperr   )r   Úchr_to_printr   Ú	__class__s      €r   r   zDotPrinterCallback.__init__à   s-   ø€ ØˆŒØ�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"Ð"Ð"r   c                 ó*   — t          d¦  «        |d<   dS )z;Mutate kwargs to add new instance with different print charú.r   N)rW   r    s       r   r   zDotPrinterCallback.branchä   s   € å/°Ñ4Ô4ˆˆzÑÐÐr   c                 ó2   — t          | j        d¬¦  «         dS )zJust outputs a characterÚ )ÚendN)ÚprintrZ   )r   r   s     r   r.   zDotPrinterCallback.callè   s   € åˆdŒh˜BÐÑÔÐÐÐr   )rX   )rL   rM   rN   rO   r   r   r.   Ú__classcell__©r]   s   @r   rW   rW   Ø   se   ø€ € € € € ðð ð#ð #ð #ð #ð #ð #ð5ð 5ð 5ð ð  ð  ð  ð  ð  ð  r   rW   c                   ó6   ‡ — e Zd ZdZdˆ fd„	Zd„ Zd„ Zd„ Zˆ xZS )ÚTqdmCallbackaó  
    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)
    Nc                 óä   •— 	 ddl m } n"# t          $ r}t          d¦  «        |‚d }~ww xY w|                     d|¦  «        | _        |pi | _        d | _          t          ¦   «         j        |i |¤Ž d S )Nr   )Útqdmz0Using TqdmCallback requires tqdm to be installedÚtqdm_cls)ri   ÚImportErrorr   Ú	_tqdm_clsÚ_tqdm_kwargsr[   r   )r   Útqdm_kwargsrU   r   ri   Úexcer]   s         €r   r   zTqdmCallback.__init__'  s¡   ø€ ð	Ø!Ð!Ð!Ð!Ð!Ð!Ð!øåð 	ð 	ð 	ÝØBñô àðøøøøð	øøøð
  Ÿš J°Ñ5Ô5ˆŒØ'Ð-¨2ˆÔØˆŒ	Ø�‰ŒÔ˜$Ð) &Ð)Ð)Ð)Ð)Ð)s   ƒ
 Š
)”$¤)c                 óÊ   — | j         € | j        dd| j        i| j        ¤Ž| _         | j        | j         _        | j                              | j        | j         j        z
  ¦  «         d S )NÚtotalr   )ri   rl   r   rm   rq   r9   r	   ÚnrT   s      r   r.   zTqdmCallback.call5  s_   € ØŒ9ÐØ&˜œÐLÐL¨T¬YÐL¸$Ô:KÐLÐLˆDŒIØœ)ˆŒ	ŒØŒ	×Ò˜œ d¤i¤kÑ1Ñ2Ô2Ð2Ð2Ð2r   c                 óX   — | j         �"| j                              ¦   «          d | _         d S d S r   )ri   r   r   s    r   r   zTqdmCallback.close;  s/   € ØŒ9Ð ØŒI�OŠOÑÔÐØˆDŒIˆIˆIð !Ð r   c                 ó*   — |                       ¦   «         S r   r   r   s    r   Ú__del__zTqdmCallback.__del__@  s   € Ø�zŠz‰|Œ|Ðr   r   )	rL   rM   rN   rO   r   r.   r   ru   rd   re   s   @r   rg   rg   í   su   ø€ € € € € ð7ð 7ðr*ð *ð *ð *ð *ð *ð3ð 3ð 3ðð ð ð
ð ð ð ð ð ð r   rg   N)Ú	functoolsr   r   rR   rW   rg   r   Ú_DEFAULT_CALLBACKr   r   r   ú<module>rx      sé   ðØ Ð Ð Ð Ð Ð ðHð Hð Hð Hð Hñ Hô Hð HðVð ð ð ð �8ñ ô ð ð ð  ð  ð  ð  ˜ñ  ô  ð  ð*Tð Tð Tð Tð T�8ñ Tô Tð Tðn (4 |¡~¤~Ð 5Ð Ð$Ð$Ð$r   