Ë
    F^(hú#  ã                   óx   — 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y
)é    )Ú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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        úN/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/fsspec/callbacks.pyÚ__init__zCallback.__init__   s"   € ØˆŒ	ØˆŒ
Ø’[˜bˆŒ
Øˆ�ó    c                 ó   — | S r   © ©r   s    r   Ú	__enter__zCallback.__enter__   s   € Øˆr   c                 ó$   — | j                  «        y r   ©Úclose)r   Úexc_argss     r   Ú__exit__zCallback.__exit__"   s   € Ø�
‰
�r   c                  ó   — y)zClose callback.Nr   r   s    r   r   zCallback.close%   s   � r   c                 óT   — | j                  |||«       |j                  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Ð7r   c                 ó@   ‡ ‡— 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 {  –—† cd d d «       S 7 Œ# 1 sw Y   y xY w­w)Nr   )r#   )Úpath1r%   r   ÚchildÚfnr   s       €€r   Úfuncz"Callback.branch_coro.<locals>.funcN   sW   øè ø€ à�—‘˜u eÑ6¨vÑ6ð H¸%Ù  uÑG°uÐGÀÑG×G÷Hñ HØGø÷Hð Hüs$   ƒA˜8¨6©8¬
A¶8¸A½A)r   Ústr)r   r)   r*   s   `` r   Úbranch_corozCallback.branch_coroI   s,   ù€ ô
 
ˆr‹ð	H¤Sõ 	Hó 
ð	Hð ˆr   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_sizeU   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_updatec   s   € ð ˆŒ
Ø�	‰	�r   c                 óN   — | xj                   |z  c_         | j                  «        y)z‹
        Delta increment the internal counter

        Triggers ``call()``

        Parameters
        ----------
        inc: int
        Nr1   )r   Úincs     r   Úrelative_updatezCallback.relative_updatep   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.call}   s˜   € ð �zŠzØØ�W‰W�\‰\‹^ˆØ
�	‰	�&ÔÙØ §
¡
Ñ*ØØ(�4—:‘:˜iÑ(¨¯©°D·J±JÑEÀ"ÑEÐEØ—J‘J×%Ñ%Ó'Ò-¨2ò 	.ˆDÙ�—‘˜DŸJ™JÑ-¨"Ó-ñ	.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)r5   )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
        -------

        Nr   r    s       r   r   zCallback.branch¡   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
        )rD   )r   r>   s     r   Ú__getattr__zCallback.__getattr__¼   s   € ð �z‰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)é   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r#   r,   r/   r2   r5   r.   r?   r   rD   rF   ÚclassmethodrJ   r   r   r   r   r      sb   „ ñó(òòòò8òB
òòóó.ò.òò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)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                 ó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ú.r   N)rW   r    s       r   r   zDotPrinterCallback.branchä   s   € ä/°Ó4ˆˆzÒr   c                 ó2   — t        | j                  d¬«       y)zJust outputs a characterÚ )ÚendN)ÚprintrY   )r   r   s     r   r.   zDotPrinterCallback.callè   s   € äˆd�h‰h˜BÖr   )ú#)rL   rM   rN   rO   r   r   r.   Ú__classcell__©r\   s   @r   rW   rW   Ø   s   ø„ ñõ#ò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)
    c                 ó¾   •— 	 ddl m } |j                  d|«      | _        |xs i | _        d | _         t        ‰| �  |i |¤Ž y # t        $ r}t        d«      |‚d }~ww xY w)Nr   )Útqdmz0Using TqdmCallback requires tqdm to be installedÚtqdm_cls)ri   ÚImportErrorr   Ú	_tqdm_clsÚ_tqdm_kwargsrZ   r   )r   Útqdm_kwargsrU   r   ri   Úexcer\   s         €r   r   zTqdmCallback.__init__'  sj   ø€ ð	Ý!ð  Ÿ™ J°Ó5ˆŒØ'Ò-¨2ˆÔØˆŒ	Ü‰Ñ˜$Ð) &Ó)øô ò 	ÜØBóàðûð	ús   ƒA Á	AÁAÁAc                 ó$  — | j                   €- | j                  dd| j                  i| j                  ¤Ž| _         | j                  | j                   _        | j                   j                  | j                  | j                   j                  z
  «       y )NÚtotalr   )ri   rl   r   rm   rq   r8   r	   ÚnrT   s      r   r.   zTqdmCallback.call5  sb   € Ø�9‰9ÐØ&˜Ÿ™ÑL¨T¯Y©YÐL¸$×:KÑ:KÑLˆDŒIØŸ)™)ˆ�	‰	ŒØ�	‰	×Ñ˜Ÿ™ d§i¡i§k¡kÑ1Õ2r   c                 ó`   — | j                   �"| j                   j                  «        d | _         y y r   )ri   r   r   s    r   r   zTqdmCallback.close;  s&   € Ø�9‰9Ð Ø�I‰I�O‰OÔØˆD�Ið !r   c                 ó"   — | j                  «       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   í   s   ø„ ñ7õr*ò3òö
r   rg   N)Ú	functoolsr   r   rR   rW   rg   r   Ú_DEFAULT_CALLBACKr   r   r   ú<module>rx      sL   ðÝ ÷Hñ HôV�8ô ô ˜ô  ô*T�8ô Tñn (4£~Ð 5Ð Ñ$r   