� <��g�#���ddlmZGd�d��ZGd�de��ZGd�de��ZGd�d e��Ze��xZZd S) �)�wrapsc��eZdZdZdd�Zd�Zd�Zd�Zd�Zd �Z d �Z d �Z dd �Z dd�Z d�Zd�Zd�Zd�Zedd���ZdS)�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)`` Nrc �B�||_||_|pi|_||_dS�N)�size�value�hooks�kw)�selfrr r �kwargss �`/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/fsspec/callbacks.py�__init__zCallback.__init__s&���� ��� ��[�b�� ������c��|Sr��r s r� __enter__zCallback.__enter__s��� rc�.�|���dSr��close)r �exc_argss r�__exit__zCallback.__exit__"s�� � � � � � � � rc��dS)zClose callback.Nrrs rrzCallback.close%s���rc �f�|�|||��|�dt��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�branchedzCallback.branched(s/��: � � �F�F�F�+�+�+��z�z�*�&6�7�7�7rc�P���t���dtf��fd� ��}|S)zI Wraps a coroutine, and pass a new child callback to it. �path2c��~�K��j||fi|��5}�||fd|i|���d{V��cddd��S#1swxYwYdS)Nr)r#)�path1r%r �child�fnr s ��r�funcz"Callback.branch_coro.<locals>.funcNs���������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� Hs �2�6�6)r�str)r r)r*s`` r� branch_corozCallback.branch_coroIsO���� �r��� H�S� H� H� H� H� H� H� �� H�� rc�<�||_|���dS)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 rs r�set_sizezCallback.set_sizeUs���� � � � � � � � � rc�<�||_|���dS)z� Set the internal value state Triggers ``call()`` Parameters ---------- value: int N�r r.)r r s r�absolute_updatezCallback.absolute_updatecs���� � � � � � � � � r�c�N�|xj|z c_|���dS)z� Delta increment the internal counter Triggers ``call()`` Parameters ---------- inc: int Nr1)r �incs r�relative_updatezCallback.relative_updateps%�� � � �c�� � � � � � � � � � rc �0�|jsdS|j���}|�|��|r*||jvrdS|j||j|jfi|��S|j���pgD]}||j|jfi|���dS)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�updaterr �values)r � hook_namer r �hooks rr.z Callback.call}s����z� � �F� �W�\�\�^�^�� � � �&���� � F��� �*�*���(�4�:�i�(���D�J�E�E�"�E�E� E��J�%�%�'�'�-�2� .� .�D� �D���D�J� -� -�"� -� -� -� -� .� .rc#�DK�|D]}|���|V��dS)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� � rc��dS)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 ------- Nrr s rrzCallback.branch�s ��,�trc��dSrr)r �_�__s r�no_opzCallback.no_op�s�� �rc��|jS)zP If undefined methods are called on this class, nothing happens )rE)r r?s r� __getattr__zCallback.__getattr__�s ���z�rc��|�tS|S)aTransform 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_callbackzCallback.as_callback�s�� � !�#� #��r)NrN)r3r)�__name__� __module__� __qualname__�__doc__rrrrr#r,r/r2r6r.r@rrErG� classmethodrKrrrrrs ��������(���� ���������8�8�8�B � � � � � � � � � � � � �.�.�.�.�. � � ����0 � � ���� � � � ��[� � � rrc��eZdZdZd�ZdS)� NoOpCallbackz> This implementation of Callback does exactly nothing c��dSrr�r �argsr s rr.zNoOpCallback.call�s���trN)rLrMrNrOr.rrrrRrR�s-������������rrRc�0��eZdZdZd�fd� Zd�Zd�Z�xZS)�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��jdi|��dS)Nr)�chr�superr)r � chr_to_printr � __class__s �rrzDotPrinterCallback.__init__�s-�����������"�"�6�"�"�"�"�"rc�*�td��|d<dS)z;Mutate kwargs to add new instance with different print char�.rN)rWr s rrzDotPrinterCallback.branch�s��/��4�4��z���rc �2�t|jd���dS)zJust outputs a character�)�endN)�printrZ)r r s rr.zDotPrinterCallback.call�s�� �d�h�B������r)rX)rLrMrNrOrrr.� __classcell__�r]s@rrWrW�se���������#�#�#�#�#�#�5�5�5� � � � � � � rrWc�6��eZdZdZd�fd� Zd�Zd�Zd�Z�xZS)� 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���� ddlm}n"#t$r}td��|�d}~wwxYw|�d|��|_|pi|_d|_t ��j|i|��dS)Nr)�tqdmz0Using TqdmCallback requires tqdm to be installed�tqdm_cls)ri� ImportErrorr� _tqdm_cls� _tqdm_kwargsr[r)r � tqdm_kwargsrUr ri�excer]s �rrzTqdmCallback.__init__'s���� � !� !� !� !� !� !� !��� � � ��B���� ����� ����  ���J��5�5���'�-�2����� ������$�)�&�)�)�)�)�)s� � )�$�)c���|j�|jdd|ji|j��|_|j|j_|j�|j|jjz ��dS)N�totalr)rirlrrmrqr9r �nrTs rr.zTqdmCallback.call5s_�� �9� �&���L�L�T�Y�L�$�:K�L�L�D�I��)�� �� � �����d�i�k�1�2�2�2�2�2rc�X�|j�"|j���d|_dSdSr)rirrs rrzTqdmCallback.close;s/�� �9� � �I�O�O� � � ��D�I�I�I� !� rc�*�|���Srrrs r�__del__zTqdmCallback.__del__@s���z�z�|�|�rr) rLrMrNrOrr.rrurdres@rrgrg�su�������7�7�r *� *� *� *� *� *�3�3�3� ��� ������rrgN)� functoolsrrrRrWrgr�_DEFAULT_CALLBACKrrr�<module>rxs���������H�H�H�H�H�H�H�H�V�����8���� � � � � �� � � �*T�T�T�T�T�8�T�T�T�n(4�|�~�~�5��$�$�$r
Memory