� I�g˵�� �dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlmZddlmZddlmZmZddlmZmZmZmZmZddlmZmZmZd Z d �Z!Gd �d e"��Z#d eiZ$d�Z%d d�Z&d�Z'ej(��Z)Gd�de��Z*Gd�de+��Z,Gd�de+��Z-Gd�de-��Z.Gd�de��Z/Gd�de/��Z0Gd�de��Z1 d!d�Z2dS)"zo A context object for caching a function's return value each time it is called with the same input arguments. �N�)�hashing)� CacheWarning)�FileSystemStoreBackend�StoreBackendBase)� filter_args� format_call�format_signature� get_func_code� get_func_name)�Logger� format_time�pformatz # first line:c��|�t��rb|�d��}t|dt t��d���}d�|dd���}nd}||fS)zZ Extract the first line information from the function code text if available. � rNr�����)� startswith�FIRST_LINE_TEXT�split�int�len�join)� func_code� first_lines �]/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/joblib/memory.py�extract_first_liner2sz�����O�,�,���O�O�D�)�)� ���1��c�/�&:�&:�&;�&;�<�=�=� ��I�I�i����m�,�,� � �� � �j� � �c��eZdZdZdS)�JobLibCollisionWarningzF Warn that there might be a collision between names of functions. N)�__name__� __module__� __qualname__�__doc__�rrrr?s���������rr�localc���t|t��s"td�|�����|�t |t ��s"td�|�����|t |<dS)a�Extend available store backends. The Memory, MemorizeResult and MemorizeFunc objects are designed to be agnostic to the type of store used behind. By default, the local file system is used but this function gives the possibility to extend joblib's memory pattern with other types of storage such as cloud storage (S3, GCS, OpenStack, HadoopFS, etc) or blob DBs. Parameters ---------- backend_name: str The name identifying the store backend being registered. For example, 'local' is used with FileSystemStoreBackend. backend: StoreBackendBase subclass The name of a class that implements the StoreBackendBase interface. z3Store backend name should be a string, '{0}' given.Nz;Store backend should inherit StoreBackendBase, '{0}' given.)� isinstance�str� ValueError�format� issubclassr�_STORE_BACKENDS)� backend_name�backends r�register_store_backendr/Gs���$ �l�C� (� (�>��(�(.��|�(<�(<�>�>� >���j��2B�C�C���(�(.��w���9�9� 9�%,�O�L�!�!�!rc�H�|�i}t|tj��rt|��}t|t��r|St|t��r�d}t j�|��}t� ��D]\}}||kr |��}�|�#td� ||�����|� |||���|S|�7tjd� |jj��t"��dS)z7Return the correct store object for the given location.Nz#Unknown location {0} or backend {1}��verbose�backend_optionszdInstantiating a backend using a {} as a location is not supported by joblib. Returning None instead.)r'�pathlib�Pathr(r�os�path� expanduserr,�items� TypeErrorr*� configure�warnings�warn� __class__r � UserWarning)r.�locationr2r3�obj� backend_key� backend_objs r�_store_backend_factoryrDdsD�������(�G�L�)�)�!��x�=�=���(�,�-�-�;��� �H�c� "� "�;����7�%�%�h�/�/��)8�(=�(=�(?�(?� $� $� $�K���+�%�%�!�k�m�m��� �;��A�H�H�$�g�/�/�0�0� 0� � � �h��&5� � 7� 7� 7�� � � �� � ;�;A�6��"�+�<-�<-�.9� ;� ;� ;� �4rc�V�t|��\}}tjjg|�|�R�S)z:Build a roughly unique identifier for the cached function.)r r6r7r)�func�modules�funcnames r�_build_func_identifierrI�s1��%�d�+�+��G�X� �7�<� +�� +�(� +� +� +�+rc��eZdZdZ dd�Zed���Zed���Zed���Zed ���Z d �Z d �Z d �Z d �Z dS)�MemorizedResultalObject representing a cached value. Attributes ---------- location: str The location of joblib cache. Depends on the store backend used. func: function or str function whose output is cached. The string case is intended only for instantiation based on the output of repr() on another instance. (namely eval(repr(memorized_instance)) works). argument_hash: str hash of the function arguments. backend: str Type of store backend for reading/writing cache files. Default is 'local'. mmap_mode: {None, 'r+', 'r', 'w+', 'c'} The memmapping mode used when loading from cache numpy arrays. See numpy.load for the meaning of the different values. verbose: int verbosity level (0 means no message). timestamp, metadata: string for internal use only. r%Nrc�0�tj|��||_t|||���|_||_|�||_n$|j�|j��|_|j�dd��|_ ||_ ||_ dS)N�r2�duration) r �__init__�_call_idrD� store_backend� mmap_mode�metadata� get_metadata�getrNr2� timestamp)�selfr@�call_idr.rRr2rVrSs rrOzMemorizedResult.__init__�s����������� �3�G�X�<C�E�E�E���"��� � �$�D�M�M� �.�;�;�D�M�J�J�D�M�� �)�)�*�d�;�;�� ��� �"����rc��|jS�N)�func_id�rWs rrFzMemorizedResult.func�s ���|�rc��|jdS�Nr�rPr\s rr[zMemorizedResult.func_id�����}�Q��rc��|jdS)Nrr_r\s r�args_idzMemorizedResult.args_id�r`rc�H�tjdtd���|jS)Nz�The 'argument_hash' attribute has been deprecated in version 0.12 and will be removed in version 0.14. Use `args_id` attribute instead.��� stacklevel)r<r=�DeprecationWarningrbr\s r� argument_hashzMemorizedResult.argument_hash�s1��� � /� �1�  .� .� .� .� �|�rc �� |j�|j|j|j|j���S#t $rN}td�tj j |jj g|j�R�����}||�d}~wwxYw)z$Read value from cache and return it.)rVrSr2zaError while trying to load a MemorizedResult's value. It seems that this folder is corrupted : {}N) rQ� load_itemrPrVrSr2r)�KeyErrorr*r6r7rr@)rW�exc�new_excs rrUzMemorizedResult.get�s��� #��%�/�/�� ��.���� � 0��� �� � #� #� #��>�>D�f��G�L��!3�!<�M�t�}�M�M�M�?O�?O�P�P�G��s� "�����  #���s�14� B �A B�B c�D�|j�|j��dS)zClear value from cacheN)rQ� clear_itemrPr\s r�clearzMemorizedResult.clear�s!�� ��%�%�d�m�4�4�4�4�4rc�R�dj|jj|jjg|j�R�S)Nz*{}(location="{}", func="{}", args_id="{}"))r*r>r rQr@rPr\s r�__repr__zMemorizedResult.__repr__�s9��B�;�B� �N� #�T�%7�%@� � �]� � � � rc�B�|j���}d|d<|S)NrV��__dict__�copy�rW�states r� __getstate__zMemorizedResult.__getstate__�s$��� �"�"�$�$��!��k��� r)r%NrNN)r r!r"r#rO�propertyrFr[rbrhrUrprrryr$rrrKrK�s���������:FJ�59�#�#�#�#�"����X��� � ��X� �� � ��X� �����X��#�#�#� 5�5�5� � � � ����rrKc�:�eZdZdZdZd�Zd�Zd�Zd�Zd�Z d�Z d S) �NotMemorizedResultzxClass representing an arbitrary value. This class is a replacement for MemorizedResult when there is no cache. ��value�validc�"�||_d|_dS)NTr})rWr~s rrOzNotMemorizedResult.__init__����� ��� � � rc�<�|jr|jStd���)NzNo value stored.)rr~rkr\s rrUzNotMemorizedResult.get s#�� �:� /��:� ��-�.�.� .rc�"�d|_d|_dS�NF�rr~r\s rrpzNotMemorizedResult.clearr�rc��|jr3d�|jjt |j�����S|jjdzS)Nz{class_name}({value}))� class_namer~z with no value)rr*r>r rr~r\s rrrzNotMemorizedResult.__repr__sO�� �:� >�+��V�t�~�'>�")�$�*�"5�"5��7�7� 8��>�*�-=�=� =rc� �|j|jd�S)Nr�r�r\s rryzNotMemorizedResult.__getstate__s����d�j�9�9�9rc�:�|d|_|d|_dS)Nrr~r�rws r� __setstate__zNotMemorizedResult.__setstate__ s���7�^�� ��7�^�� � � rN) r r!r"r#� __slots__rOrUrprrryr�r$rrr|r|�s��������#�I����/�/�/� ���>�>�>�:�:�:�$�$�$�$�$rr|c�>�eZdZdZd�Zd�Zd�Zd�Zd d�Zd�Z d �Z d S) �NotMemorizedFuncaNo-op object decorating a function. This class replaces MemorizedFunc when there is no cache. It provides an identical API but does not write anything on disk. Attributes ---------- func: callable Original undecorated function. c��||_dSrZ�rF)rWrFs rrOzNotMemorizedFunc.__init__4s ���� � � rc��|j|i|��SrZr��rW�args�kwargss r�__call__zNotMemorizedFunc.__call__7s���t�y�$�)�&�)�)�)rc�6�t|j|i|����SrZ�r|rFr�s r�call_and_shelvez NotMemorizedFunc.call_and_shelve:s!��!�)�$�)�T�"<�V�"<�"<�=�=�=rc�L�d�|jj|j��S)Nz {0}(func={1}))r*r>r rFr\s rrrzNotMemorizedFunc.__repr__=s���%�%�d�n�&=�t�y�I�I�IrTc��dSrZr$�rWr=s rrpzNotMemorizedFunc.clear@s�� �rc� �|j|i|��ifSrZr�r�s r�callzNotMemorizedFunc.callDs���t�y�$�)�&�)�)�2�-�-rc��dSr�r$r�s r�check_call_in_cachez$NotMemorizedFunc.check_call_in_cacheGs���urN�T) r r!r"r#rOr�r�rrrpr�r�r$rrr�r�(s������� � ����*�*�*�>�>�>�J�J�J� � � � �.�.�.�����rr�c��eZdZd�ZdS)�AsyncNotMemorizedFuncc��FK�t|j|i|���d{V����SrZr�r�s rr�z%AsyncNotMemorizedFunc.call_and_shelveOs7����!� �� �4�(B�6�(B�(B�"B�"B�"B�"B�"B�"B�C�C�CrN)r r!r"r�r$rrr�r�Ns(������D�D�D�D�Drr�c��eZdZdZ d d�Zd�Zd�Zed ���Zd �Z d �Z d �Z d �Z d�Z d�Zd�Zd!d�Zd"d�Zd�Zd#d�Zd�Zd�Z d$d�Zd%d�Zd%d�Zd&d�Zd�ZdS)'� MemorizedFuncajCallable object decorating a function for caching its return value each time it is called. Methods are provided to inspect the cache or clean it. Attributes ---------- func: callable The original, undecorated, function. location: string The location of joblib cache. Depends on the store backend used. backend: str Type of store backend for reading/writing cache files. Default is 'local', in which case the location is the path to a disk storage. ignore: list or None List of variable names to ignore when choosing whether to recompute. mmap_mode: {None, 'r+', 'r', 'w+', 'c'} The memmapping mode used when loading from cache numpy arrays. See numpy.load for the meaning of the different values. compress: boolean, or integer Whether to zip the stored data on disk. If an integer is given, it should be between 1 and 9, and sets the amount of compression. Note that compressed arrays cannot be read by memmapping. verbose: int, optional The verbosity flag, controls messages that are issued as the function is evaluated. cache_validation_callback: callable, optional Callable to check if a result in cache is valid or is to be recomputed. When the function is called with arguments for which a cache exists, the callback is called with the cache entry's metadata as its sole argument. If it returns True, the cached result is returned, else the cache for these arguments is cleared and the result is recomputed. r%NFrc ���tj|��||_||_||_| |_t |��|_|�|ng|_||_ t|||t||������|_ |j � |j � |jg��|�|ntj��|_ t!j||��n#t$$rYnwxYwt'j|��rTt+j���|��} | �ddd��} t3jdd| ��} n|j} d| z|_d|_d|_dS) N��compressrRr1rz rz.�zMemoized version of %s)r rOrRr�rF�cache_validation_callbackrIr[�ignore�_verboserD�dictrQ�store_cached_func_code�timerV� functools�update_wrapper� Exception�inspect� isfunction�pydoc�TextDoc�document�replace�re�subr#�_func_code_info� _func_code_id) rWrFr@r.r�rRr�r2rVr��docs rrOzMemorizedFunc.__init__�s��� ������"��� �� ��� �)B��&�-�d�3�3�� � &� 2�f�f��� ��� �4�G�X�<C�DH�AI�BK�EM�EM�EM�6�6�6��� � � )� � � 5� 5�t�|�n� E� E� E�&/�&;��������� � � $�T�4� 0� 0� 0� 0��� � � � �D� ���� � �d� #� #� ��-�/�/�*�*�4�0�0�C��+�+�d�F�A�.�.�C��&��"�c�*�*�C�C��,�C�/�#�5�� �#���!����s�C� C%�$C%c��|�d���sdS|j�|��sdS|j�|��}|j�1|�|��s|j�|��dSdS)a�Check if the function call is cached and valid for given arguments. - Compare the function code with the one from the cached function, asserting if it has changed. - Check if the function call is present in the cache. - Call `cache_validation_callback` for user define cache validation. Returns True if the function call is in cache and can be used, and returns False otherwise. �reFNT)�_check_previous_func_coderQ� contains_itemrTr�ro�rWrXrSs r�_is_in_cache_and_validz$MemorizedFunc._is_in_cache_and_valid�s����-�-��-�;�;� ��5��!�/�/��8�8� ��5��%�2�2�7�;�;�� � *� 6��2�2�8�<�<� 7� � � )� )�'� 2� 2� 2��5��trc ��|j|i|��}|j|f}t|j��\}}|j�|jg��}|d} |jdkrktjtj ���t|jg|�Ri|��\}} |� tj d|�d| �d|�d| �d� ����|�|��r�|r|�|��ifS t!j��} |�|��} |jd kr+|�t!j��| z d � ��| ifS#t&$rUt|jg|�Ri|��\}} |�d �| t-j������YnwxYw|jd kr|�d|�d|�d| ����|�||||��S)a�Call wrapped function and cache result, or read cache if available. This function returns the wrapped function output or a reference to the cached result. Arguments: ---------- args, kwargs: list and dict input arguments for wrapped function shelving: bool True when called via the call_and_shelve function. Returns ------- output: Output of the wrapped function if shelving is false, or a MemorizedResult reference to the value if shelving is true. metadata: dict containing the metadata associated with the call. r@�)�levelz" Querying z( with signature z*. (argument hash z1) The store location is z. r�z cache loaded )�contextz*Exception while loading results for {} {}� zComputing func z, argument hash z in location )� _get_args_idr[r rFrQ�get_cached_func_infor��logging� basicConfig�INFOr �info�textwrap�dedentr��_get_memorized_resultr�� _load_item�_print_durationr�r=r*� traceback� format_exc�_call) rWr�r��shelvingrbrX�_� func_name� func_infor@� signature� start_time�outputs r� _cached_callzMemorizedFunc._cached_call�s���,$�$�#�T�4�V�4�4���<��)��$�T�Y�/�/� ��9��&�;�;�T�\�N�K�K� ��Z�(�� �=�B� � � � �g�l� 3� 3� 3� 3�+�D�I�G��G�G�G��G�G�L�A�y� �I�I����"+���"���)0� �� 08� ��� � � � � � � &� &�w� /� /� O�� ?��1�1�'�:�:�B�>�>� O�!�Y�[�[� �����1�1���=�1�$�$��(�(�����z�)A�1@�)�B�B�B��r�z�!��� O� O� O�/�� �K�D�K�K�K�F�K�K� ��9�� � �$�$*�F�9�i�6J�6L�6L�$M�$M�O�O�O�O�O� O���� �=�2� � � �I�I�*�)�*�*�W�*�*�'�*�*� � � � �z�z�'�4���:�:�:s�;A!E�AF<�;F<c��t|jd��rO|j�t|jj��|_n)t|jj��|jkrd|_|j�t |j��|_|jS)N�__code__)�hasattrrFr��idr�r�r r\s r�func_code_infozMemorizedFunc.func_code_infos��� �4�9�j� )� )� ,��!�)�%'�� �(:�%;�%;��"�"��D�I�&�'�'�4�+=�=�=�'+��$� � � '�$1���#;�#;�D� ��#�#rc�>�|�||d���dS)a\Call wrapped function, cache result and return a reference. This method returns a reference to the cached result instead of the result itself. The reference object is small and pickeable, allowing to send or store it easily. Call .get() on reference object to get result. Returns ------- cached_result: MemorizedResult or NotMemorizedResult reference to the value returned by the wrapped function. The class "NotMemorizedResult" is used when there is no cache activated (e.g. location=None in Memory). T�r�r�r�r�s rr�zMemorizedFunc.call_and_shelve-s$�� � � ��v�� �=�=�a�@�@rc�>�|�||d���dS�NFr�rr�r�s rr�zMemorizedFunc.__call__?s"��� � ��v�� �>�>�q�A�Arc�Z�|j}|j���}d|d<d|d<|S)NrVr�)r�rurv)rWr�rxs rryzMemorizedFunc.__getstate__Cs<�� � ��� �"�"�$�$��!��k��"&��o��� rc�^�|j|j|i|��f}|j�|��S)a\Check if function call is in the memory cache. Does not call the function or do any work besides func inspection and arg hashing. Returns ------- is_call_in_cache: bool Whether or not the result of the function has been cached for the input arguments that have been passed. )r[r�rQr��rWr�r�rXs rr�z!MemorizedFunc.check_call_in_cacheSs:���<�!2��!2�D�!C�F�!C�!C�D���!�/�/��8�8�8rc�p�tjt|j|j||��|jdu���S)z,Return the input parameter hash of a result.N)� coerce_mmap)r�hashrrFr�rRr�s rr�zMemorizedFunc._get_args_idfs=���|�K�� �4�;��f�M�M�(,��d�(B�D�D�D� Drc��tt|jdd����}t|j��t|j��|fS)z'Hash a function to key the online cacher�N)r��getattrrFr�)rW� func_code_hs r� _hash_funczMemorizedFunc._hash_funcks:���7�4�9�j�$�?�?�@�@� ��$�)�}�}�d�4�9�o�o�{�:�:rc��dt||fz}|j�|jg|��t |jd��o|jjdk}|r7|���} |t|j<dS#t$rYdSwxYwdS)z= Write the function code and the filename to a file. z%s %i %sr �<lambda>N) rrQr�r[r�rFr r��_FUNCTION_HASHESr:)rWrr�is_named_callable� func_hashs r�_write_func_codezMemorizedFunc._write_func_codeps���!�O�Z��#K�K� � ��1�1�4�<�.�)�L�L�L�%�T�Y� �;�;�>�!�Y�/�:�=� � � ����)�)�I� �.7� ���+�+�+��� � � ���� ����  � s�+A<�< B � B rdc ��� |jtvr,|���}|t|jkrdSn#t$rYnwxYw|j\}}} t |j�|jg����\}}n.#ttf$r|� ||��YdSwxYw||krdSt|jdd���\}} ||cxkrdksn| dkrV|dksd� | ||��} n| } tjt!d� | ����|���||k�s4|��1t"j�|��r�t|jd� ��\}} t)|�d ����} t-j|��5} | ���|d z |d z | zd z �} d d d ��n #1swxYwYd �| ��} | ���|���k}n|�d��}|r,tjt!d| ||| ||fz��|���|jdkrGt|jd� ��\}} |�d� | |j����|�d���dS)z� stacklevel is the depth a which this function is called, to issue useful warnings to the user. TF)� resolv_alias�win_charactersrr�z {0} ({1}:{2})z0Cannot detect name collisions for function '{0}'reN)r�rrr�z <doctest zHPossible name collisions between functions '%s' (%s:%i) and '%s' (%s:%i)r�z-Function {0} (identified by {1}) has changed.)r=)rFr�r�r:r�rrQ�get_cached_func_coder[�IOError�OSErrorr�r r*r<r=rr6r7�existsrr�tokenize�open� readlinesr�rstriprr�rp)rWrfr�r� source_filer� old_func_code�old_first_liner�r��func_description� num_lines�f�on_disk_func_code�possible_collisions rr�z'MemorizedFunc._check_previous_func_code�s��� ��y�,�,�,�!�O�O�-�-� �� 0��� ;�;�;��4���� � � � �D� ����.2�-@�*� �;� � �,>��"�7�7����G�G�-I�-I� )�M�>�>����!� � � � � !� !�)�Z� 8� 8� 8��5�5� ���� �I� %� %��4� %�T�Y�U�49�;�;�;� ��9� �Z� -� -� -� -�2� -� -� -� -��j�1H�1H���#�#�$3�%+�V�I�{�,6�&8�&8�!� �$-� � �M�0�B���(�)�)�+�+�7A� C� C� C� C���+�+� �0G��w�~�~�k�*�*� I�,�T�Y�U�K�K�K� ��9�� ���� 5� 5�6�6� ��]�;�/�/�O�1�()� � � � �&��*�>�A�+=� �+I�A�+M�M�)O�%�O�O�O�O�O�O�O�O�O�O�O����O�O�O�O�%'�G�G�,=�$>�$>�!�&7�&>�&>�&@�&@�&3�&:�&:�&<�&<�'=�"�"�&1�%;�%;�K�%H�%H�"�!� +�� �4�4�� �^�� �Z�9�9�:�:� *� +�+�+�+� �=�2� � �(����G�G�G�L�A�y� �I�I�� �&��D�L�9�9� ;� ;� ;� � � �� �����us3�8=� A � A �0B � 'B5�4B5�=)G2�2G6�9G6Tc���|j}|jdkr|r|�d|z��|j�|g��|j\}}}|�||��dS)zEmpty the function's cache.rz(Clearing function cache identified by %sN)r[r�r=rQ� clear_pathr�r�)rWr=r[rr�rs rrpzMemorizedFunc.clear�sw���,�� �=�1� � �� � �I�I�@�7�J� K� K� K� ��%�%�w�k�2�2�2�#'�#6� � �1�j� ���i��4�4�4�4�4rc�X�|j|j|i|��f}|�|||��S)aForce the execution of the function with the given arguments. The output values will be persisted, i.e., the cache will be updated with any new values. Parameters ---------- *args: arguments The arguments. **kwargs: keyword arguments Keyword arguments. Returns ------- output : object The output of the function call. metadata : dict The metadata associated with the call. )r[r�r�r�s rr�zMemorizedFunc.call�s;��(�<�!2��!2�D�!C�F�!C�!C�D���z�z�'�4��0�0�0rc��|�||��tj��}|j|i|��}|�||||||��SrZ�� _before_callr�rF� _after_call�rWrXr�r�r�r�r�s rr�zMemorizedFunc._call�s^�� ���$��'�'�'��Y�[�[� ����D�+�F�+�+�������v�x� &� �4�4� 4rc�f�|jdkr%tt|j||����dSdSr^)r��printr rFr�s rrzMemorizedFunc._before_calls9�� �=�1� � � �+�d�i��v�6�6� 7� 7� 7� 7� 7� � rc�X�|j�|||j���tj��|z }|jdkr|�|��|�||||��}|r|�||��|fS|j�|�||��}||fS)NrMr) rQ� dump_itemr�r�r��_persist_inputr�rRr�) rWrXr�r�r�r�r�rNrSs rrzMemorizedFunc._after_call s��� ��$�$�W�f�d�m�$�L�L�L��9�;�;��+�� �=�1� � � � � �� *� *� *��&�&�x��$��G�G�� � K��-�-�g�x�@�@�(�J� J� �>� %��_�_�W�h�7�7�F��x��r��?c�f�tj��}t|j|j||��}t d�|���D����}|||d�} |j�|| ��tj��|z } | |krtj d| zd���| S)a% Save a small summary of the call using json format in the output directory. output_dir: string directory where to write metadata. duration: float time taken by hashing input arguments, calling the wrapped function and persisting its output. args, kwargs: list and dict input arguments for wrapped function this_duration_limit: float Max execution time for this function before issuing a warning. c3�>K�|]\}}|t|��fV��dSrZ)�repr)�.0�k�vs r� <genexpr>z/MemorizedFunc._persist_input.<locals>.<genexpr>0s0����I�I�4�1�a�1�d�1�g�g�,�I�I�I�I�I�Ir)rN� input_argsr�z�Persisting input arguments took %.2fs to run.If this happens often in your code, it can cause performance problems (results will be correct in all cases). The reason for this is probably some large input arguments for a wrapped function.�re) r�rrFr�r�r9rQ�store_metadatar<r=) rWrNrXr�r��this_duration_limitr�� argument_dict� input_reprrS� this_durations rrzMemorizedFunc._persist_inputs���$�Y�[�[� �#�D�I�t�{�$(�&�2�2� ��I�I�=�3F�3F�3H�3H�I�I�I�I�I� �!� �J� � �� ��)�)�'�8�<�<�<�� � � �j�0� � �.� .� .� �M�>� *� *� 78�  9� 9� 9� 9��rc�N�t|j|||j|jdz ���S)Nr�rSrVr2)rKrQrVr�r�s rr�z#MemorizedFunc._get_memorized_resultJs1���t�1�7�(0�D�N�'+�}�q�'8�:�:�:� :rc�R�|j�|||j|j���S)Nr()rQrjrVr�r�s rr�zMemorizedFunc._load_itemOs3���!�+�+�G�h�6:�n�48�M�,�C�C� Crr�c ���t|j��\}}|�d|�dt|����}tt ddt |��z ��dz|z��dS)N� z- r�Pr�)r rFrr�maxr)rWrNr�r��name�msgs rr�zMemorizedFunc._print_durationTsj���� �*�*���4��:�:��:�:�;�x�#8�#8�:�:�� �c�!�b�3�s�8�8�m�%�%��+�c�1�2�2�2�2�2rc�d�d�|jj|j|jj���S)Nz.{class_name}(func={func}, location={location}))r�rFr@)r*r>r rFrQr@r\s rrrzMemorizedFunc.__repr__]s6��?�F�F��~�.����'�0�G�3�3� 3r)r%NNFrNN)rdr��F)rrZ)r�)r r!r"r#rOr�r�rzr�r�r�ryr�r�r�r�r�rpr�r�rrrr�r�r�rrr$rrr�r�Vs�������+�+�`@D�FJ�+/�("�("�("�("�T���8G;�G;�G;�R�$�$��X�$�,A�A�A�$B�B�B���� 9� 9� 9�&D�D�D� ;�;�;� ���0R�R�R�R�h5�5�5�5�1�1�1�24�4�4�4�8�8�8�  �  �  � ,/�.�.�.�.�`:�:�:�:� C�C�C�C� 3�3�3�3�3�3�3�3�3rr�c�2��eZdZd�Zd�Z�fd�Zdd�Z�xZS)�AsyncMemorizedFuncc��K�|�||d���}tj|��r|�d{V��n|}|dSr��r��asyncio� iscoroutine�rWr�r��outs rr�zAsyncMemorizedFunc.__call__hsN��������f�u��=�=��"�.�s�3�3�<�C�i�i�i�i�i�i�i����1�v� rc��K�|�||d���}tj|��r|�d{V��n|}|dS)NTr�rr5r8s rr�z"AsyncMemorizedFunc.call_and_shelvemsN��������f�t��<�<��"�.�s�3�3�<�C�i�i�i�i�i�i�i����1�v� rc��v�K�t��j|i|��}tj|��r|�d{V��n|SrZ)�superr�r6r7)rWr�r�r9r>s �rr�zAsyncMemorizedFunc.callrsG������e�g�g�l�D�+�F�+�+��#�/��4�4�=�S�y�y�y�y�y�y�y�#�=rFc��K�|�||��tj��}|j|i|���d{V��}|�||||||��SrZrrs rr�zAsyncMemorizedFunc._callvst���� ���$��'�'�'��Y�[�[� � �t�y�$�1�&�1�1�1�1�1�1�1�1����� �T�6�8�V�Z� � � rr1)r r!r"r�r�r�r�� __classcell__)r>s@rr3r3gsj���������� ��� >�>�>�>�>� � � � � � � � rr3c�N�eZdZdZ dd�Z dd�Zdd �Zdd �Zd �Zd �Z d �Z dS)�Memorya2 A context object for caching a function's return value each time it is called with the same input arguments. All values are cached on the filesystem, in a deep directory structure. Read more in the :ref:`User Guide <memory>`. Parameters ---------- location: str, pathlib.Path or None The path of the base directory to use as a data store or None. If None is given, no caching is done and the Memory object is completely transparent. This option replaces cachedir since version 0.12. backend: str, optional Type of store backend for reading/writing cache files. Default: 'local'. The 'local' backend is using regular filesystem operations to manipulate data (open, mv, etc) in the backend. mmap_mode: {None, 'r+', 'r', 'w+', 'c'}, optional The memmapping mode used when loading from cache numpy arrays. See numpy.load for the meaning of the arguments. compress: boolean, or integer, optional Whether to zip the stored data on disk. If an integer is given, it should be between 1 and 9, and sets the amount of compression. Note that compressed arrays cannot be read by memmapping. verbose: int, optional Verbosity flag, controls the debug messages that are issued as functions are evaluated. bytes_limit: int | str, optional Limit in bytes of the size of the cache. By default, the size of the cache is unlimited. When reducing the size of the cache, ``joblib`` keeps the most recently accessed items first. If a str is passed, it is converted to a number of bytes using units { K | M | G} for kilo, mega, giga. **Note:** You need to call :meth:`joblib.Memory.reduce_size` to actually reduce the cache size to be less than ``bytes_limit``. **Note:** This argument has been deprecated. One should give the value of ``bytes_limit`` directly in :meth:`joblib.Memory.reduce_size`. backend_options: dict, optional Contains a dictionary of named parameters used to configure the store backend. Nr%Frc ���tj|��||_||_t j��|_|�t jdt���||_ ||_ ||_ |�i}||_ |r|�t jdd���||_ t|t��r t j�|d��}t'|||jt)d ||d�|�����|_dS) Nz�bytes_limit argument has been deprecated. It will be removed in version 1.5. Please pass its value directly to Memory.reduce_size.)�categoryz&Compressed results cannot be memmappedrdre�joblibr�r1r$)r rOr�rRr�rVr<r=rg� bytes_limitr.r�r3r@r'r(r6r7rrDr�rQ)rWr@r.rRr�r2rDr3s rrOzMemory.__init__�s(�� �������� �"��������� � "� �M�&�,�  � � � � '����� � �� � � "� �O�.��� � (� �-� �M�B�%&� (� (� (� (�!�� � �h�� $� $� 8��w�|�|�H�h�7�7�H�3� �X�t�}� �4�(�i�4�4�#2�4�4�5�5�5����rc ���|�"t|��std|�d����|�tj|j||||���S|j�-t j|��rtnt}||��S|�|j }|dur|j }t|t��r|j}t j|��rtnt}|||j|j|||j||j|�� � S)ad Decorates the given function func to only compute its return value for input arguments not cached on disk. Parameters ---------- func: callable, optional The function to be decorated ignore: list of strings A list of arguments name to ignore in the hashing verbose: integer, optional The verbosity mode of the function. By default that of the memory object is used. mmap_mode: {None, 'r+', 'r', 'w+', 'c'}, optional The memmapping mode used when loading from cache numpy arrays. See numpy.load for the meaning of the arguments. By default that of the memory object is used. cache_validation_callback: callable, optional Callable to validate whether or not the cache is valid. When the cached function is called with arguments for which a cache exists, this callable is called with the metadata of the cached result as its sole argument. If it returns True, then the cached result is returned, else the cache for these arguments is cleared and recomputed. Returns ------- decorated_func: MemorizedFunc object The returned object is a MemorizedFunc object, that is callable (behaves like a function), but offers extra methods for cache lookup and management. See the documentation for :class:`joblib.memory.MemorizedFunc`. Nz4cache_validation_callback needs to be callable. Got �.)r�rRr2r�F)r@r.r�rRr�r2rVr�)�callabler)r��partial�cacherQr6�iscoroutinefunctionr�r�r�rRr'r�rFr3r.r�rV)rWrFr�r2rRr��clss rrIz Memory.cache�sF��D &� 1��6�7�7� 2��4�0�4�4�4��� � �<��$�� �6�#��*C� ��� � � � %��1�$�7�7�)�(�(�(� ��3�t�9�9� � �?��m�G� �� � ���I� �d�M� *� *� ��9�D��-�d�3�3�"�!�!�!� ��s� �4�-�t�|��Y����t�~�&?�  � � � rTc��|r|�d��|j�4|j���t���dSdS)z- Erase the complete cache directory. zFlushing completely the cacheN)r=rQrpr�r�s rrpz Memory.clear&s_�� � 7� �I�I�5� 6� 6� 6� � � )� � � $� $� &� &� &� � "� "� $� $� $� $� $� *� )rc�r�|�|j}|j�dS|�|�|�dS|j�|||��dS)a�Remove cache elements to make the cache fit its limits. The limitation can impose that the cache size fits in ``bytes_limit``, that the number of cache items is no more than ``items_limit``, and that all files in cache are not older than ``age_limit``. Parameters ---------- bytes_limit: int | str, optional Limit in bytes of the size of the cache. By default, the size of the cache is unlimited. When reducing the size of the cache, ``joblib`` keeps the most recently accessed items first. If a str is passed, it is converted to a number of bytes using units { K | M | G} for kilo, mega, giga. items_limit: int, optional Number of items to limit the cache to. By default, the number of items in the cache is unlimited. When reducing the size of the cache, ``joblib`` keeps the most recently accessed items first. age_limit: datetime.timedelta, optional Maximum age of items to limit the cache to. When reducing the size of the cache, any items last accessed more than the given length of time ago are deleted. N)rDrQ�enforce_store_limits)rWrD� items_limit� age_limits r� reduce_sizezMemory.reduce_size4sc��4 � ��*�K� � � %� �F� � �;�#6�9�;L� �F� ��/�/� ��i� � � � � rc�V�|j�||i|��S|�|��|i|��S)a Eval function func with arguments `*args` and `**kwargs`, in the context of the memory. This method works similarly to the builtin `apply`, except that the function is called only if the cache is not up to date. )rQrI)rWrFr�r�s r�evalz Memory.eval^sC�� � � %��4��(��(�(� (��t�z�z�$����0��0�0�0rc�j�d�|jj|j�dn |jj���S)Nz!{class_name}(location={location}))r�r@)r*r>r rQr@r\s rrrzMemory.__repr__os=��2�9�9��~�.�"�0�8�d�d��-�6�:�9�9� 9rc�B�|j���}d|d<|S)zf We don't store the timestamp when pickling, to avoid the hash depending from it. NrVrtrws rryzMemory.__getstate__us&��� �"�"�$�$��!��k��� r)Nr%NFrNN)NNNFNr�)NNN) r r!r"r#rOrIrprQrSrrryr$rrr@r@�s�������6�6�v/6�HL�!%� 5� 5� 5� 5�DEJ�(,�D �D �D �D �L %� %� %� %�( �( �( �( �T 1� 1� 1�"9�9�9� ����rr@c �H��tj|||||||�����fd�}|S)z�Helper cache_validation_callback to force recompute after a duration. Parameters ---------- days, seconds, microseconds, milliseconds, minutes, hours, weeks: numbers argument passed to a timedelta. )�days�seconds� microseconds� milliseconds�minutes�hours�weeksc�l��tj��|dz }|����kS)Nr�)r�� total_seconds)rS�computation_age�deltas �rr�z0expires_after.<locals>.cache_validation_callback�s/����)�+�+���(8�8����!4�!4�!6�!6�6�6r)�datetime� timedelta) rWrXrYrZr[r\r]r�ras @r� expires_afterrd�sM��� � � �7��!�7�%�u� � � �E� 7�7�7�7�7� %�$r)rN)rrrrrrr)3r#r6rbr�r�r�r6r4r�r�r�r�r�r�r<�weakrefr�r�_store_backendsrrr� func_inspectrr r r r �loggerr rrrrr?rr,r/rDrI�WeakKeyDictionaryr�rK�objectr|r�r�r�r3r@rdr$rr�<module>rksC������������������������ � � � ����� � � � � � � � ����� � � � �����������������������)�)�)�)�)�)�E�E�E�E�E�E�E�E�9�9�9�9�9�9�9�9�9�9�9�9�9�9�0�0�0�0�0�0�0�0�0�0�!�� !� !� !������[���� �2�3��,�,�,�:%�%�%�%�P,�,�,�-�7�,�.�.�� a�a�a�a�a�f�a�a�a�H#$�#$�#$�#$�#$��#$�#$�#$�R � � � � �v� � � �LD�D�D�D�D�,�D�D�D�K3�K3�K3�K3�K3�F�K3�K3�K3�b � � � � �� � � �6y�y�y�y�y�V�y�y�y�@NO�!"�%�%�%�%�%�%r
Memory