
    0;jiE                     Z   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlmZmZ ddlmZ ddlmZ ddlmZ ddlmZmZmZ dd	lmZ  ej        d
d          Z G d de          Zd Z  G d de          Z! G d de"          Z# G d de!e#          Z$dS )z.Storage providers backends for Memory caching.    N)ABCMetaabstractmethod)PicklingError   )numpy_pickle)concurrency_safe_rename)memstr_to_bytesmkdirp
rm_subdirs)format_timeCacheItemInfozpath size last_accessc                       e Zd ZdZdS )CacheWarningz:Warning to capture dump failures except for PicklingError.N)__name__
__module____qualname____doc__     P/root/voice-cloning/.venv/lib/python3.11/site-packages/joblib/_store_backends.pyr   r      s        DDDr   r   c                     t          t          j                              }| dt          j                    j         dt          j                     d| } || |           |S )z>Writes an object into a unique file in a concurrency-safe way..-)id	threadingcurrent_threaduuiduuid4hexosgetpid)object_to_writefilename
write_func	thread_idtemporary_filenames        r   concurrency_safe_writer'       sf     9+--..I$SStz||'7SS")++SS	SSJ 2333r   c                       e Zd ZdZdZed             Zed             Zed             Zed             Z	ed             Z
ed             Zed	 e            fd
            ZdS )StoreBackendBasez^Helper Abstract Base Class which defines all methods that
    a StorageBackend must implement.Nc                     dS )a  Opens an item on the store and return a file-like object.

        This method is private and only used by the StoreBackendMixin object.

        Parameters
        ----------
        f: a file-like object
            The file-like object where an item is stored and retrieved
        mode: string, optional
            the mode in which the file-like object is opened allowed valued are
            'rb', 'wb'

        Returns
        -------
        a file-like object
        Nr   )selffmodes      r   
_open_itemzStoreBackendBase._open_item5         r   c                     dS )a  Checks if an item location exists in the store.

        This method is private and only used by the StoreBackendMixin object.

        Parameters
        ----------
        location: string
            The location of an item. On a filesystem, this corresponds to the
            absolute path, including the filename, of a file.

        Returns
        -------
        True if the item exists, False otherwise
        Nr   r+   locations     r   _item_existszStoreBackendBase._item_existsH   r/   r   c                     dS )a-  Moves an item from src to dst in the store.

        This method is private and only used by the StoreBackendMixin object.

        Parameters
        ----------
        src: string
            The source location of an item
        dst: string
            The destination location of an item
        Nr   )r+   srcdsts      r   
_move_itemzStoreBackendBase._move_itemY   r/   r   c                     dS )zCreates a location on the store.

        Parameters
        ----------
        location: string
            The location in the store. On a filesystem, this corresponds to a
            directory.
        Nr   r1   s     r   create_locationz StoreBackendBase.create_locationg   r/   r   c                     dS )zClears a location on the store.

        Parameters
        ----------
        location: string
            The location in the store. On a filesystem, this corresponds to a
            directory or a filename absolute path
        Nr   r1   s     r   clear_locationzStoreBackendBase.clear_locationr   r/   r   c                     dS )zReturns the whole list of items available in the store.

        Returns
        -------
        The list of items identified by their ids (e.g filename in a
        filesystem).
        Nr   r+   s    r   	get_itemszStoreBackendBase.get_items}   r/   r   r   c                     dS )a  Configures the store.

        Parameters
        ----------
        location: string
            The base location used by the store. On a filesystem, this
            corresponds to a directory.
        verbose: int
            The level of verbosity of the store
        backend_options: dict
            Contains a dictionary of named parameters used to configure the
            store backend.
        Nr   )r+   r2   verbosebackend_optionss       r   	configurezStoreBackendBase.configure   r/   r   )r   r   r   r   r2   r   r.   r3   r7   r9   r;   r>   dictrB   r   r   r   r)   r)   /   s        ( ( H  ^$   ^    ^   ^   ^   ^ *+TTVV    ^  r   r)   )	metaclassc                       e Zd ZdZddZddZd Zd Zd Zd	 Z	d
 Z
d Zd ZddZd Zd Zd ZddZddZd Zd ZdS )StoreBackendMixina  Class providing all logic for managing the store in a generic way.

    The StoreBackend subclass has to implement 3 methods: create_location,
    clear_location and configure. The StoreBackend also has to provide
    a private _open_item, _item_exists and _move_item methods. The _open_item
    method has to have the same signature as the builtin open and return a
    file-like object.
    r   Nc                    t          j        j        | j        g|R  }|dk    r|6d                    t          t          j                    |z
                      nd}t           j                            |d                   }|Sd|v rOd                    d |d                                         D                       }|d	                    |          z  }d
                    ||          }	|dk     r#t          d                    |	                     n#t          d                    |	|                     t          | d          sdn| j        }
t           j                            |d          }|                     |          st          d|z            |
C|                     |d          5 }t          j        |          }ddd           n# 1 swxY w Y   nt          j        ||
          }|S )z:Load an item from the store given its id as a list of str.r   Nz{: <16} r   
input_argsz, c              3   *   K   | ]} d j         | V  dS )z{}={}N)format.0items     r   	<genexpr>z.StoreBackendMixin.load_item.<locals>.<genexpr>   s<       # #.2NGND)# # # # # #r   z({})z[Memory]{}: Loading {}
   z{0}...z{0} from {1}	mmap_mode
output.pklzANon-existing item (may have been cleared).
File %s does not existrb)rQ   )r    pathjoinr2   rK   r   timebasenameitemsprinthasattrrQ   r3   KeyErrorr.   r   load)r+   call_idr@   	timestampmetadata	full_path	ts_string	signaturekwargsmsgrQ   r#   r,   rN   s                 r   	load_itemzStoreBackendMixin.load_item   s:   GL9999	Q;; (   TY[[9-D!E!EFFF 
 ((44I#(@(@ # #6>|6L6R6R6T6T# # #   V]]6222	*11)YGGC||hooc**++++n++C;;<<< 'k : :NDD	7<<	<88  ** 	46>?   400 ,A#(++, , , , , , , , , , , , , , ,  $XCCCDs   2GGGc                     	 t          j        j         j        g|R  }                     |          s                     |           t           j                            |d          }|dk    rt          d|z              fd}                     |||           dS # t          $ r)}t          j
        d| dt                     Y d}~dS d}~ww xY w)z;Dump an item in the store at the id given as a list of str.rR   rP   zPersisting in %sc                                         |d          5 }	 t          j        | |j                   n5# t          $ r(}t          j        d| dt                     Y d }~nd }~ww xY wd d d            d S # 1 swxY w Y   d S )Nwb)compresszjUnable to cache to disk: failed to pickle output. In version 1.5 this will raise an exception. Exception: r   )r.   r   dumpri   r   warningswarnFutureWarning)to_writedest_filenamer,   er+   s       r   r$   z/StoreBackendMixin.dump_item.<locals>.write_func   s   __]D99 
Q	$)(ANNNNN(    :56: : : *	       
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s7   A97A9
A)A$A9$A))A99A= A=z`Unable to cache to disk. Possibly a race condition in the creation of the directory. Exception: r   N)r    rT   rU   r2   r3   r9   rY   _concurrency_safe_write	Exceptionrk   rl   r   )r+   r]   rN   r@   	item_pathr#   r$   rp   s   `       r   	dump_itemzStoreBackendMixin.dump_item   s#   	T]=W===I$$Y// 0$$Y///w||I|<<H||(94555     ((xDDDDD 	 	 	M>9:> > >        	s   BB 
C)CCc                     t          j        j        | j        g|R  }|                     |          r|                     |           dS dS )z1Clear the item at the id, given as a list of str.Nr    rT   rU   r2   r3   r;   )r+   r]   rs   s      r   
clear_itemzStoreBackendMixin.clear_item   W    GL9999	Y'' 	+	*****	+ 	+r   c                     t          j        j        | j        g|R  }t           j                            |d          }|                     |          S )z<Check if there is an item at the id, given as a list of str.rR   )r    rT   rU   r2   r3   )r+   r]   rs   r#   s       r   contains_itemzStoreBackendMixin.contains_item   sF    GL9999	7<<	<88  ***r   c                 >    dt          j        j        | j        g|R  iS )zReturn information about item.r2   r    rT   rU   r2   r+   r]   s     r   get_item_infozStoreBackendMixin.get_item_info   #    BGLAAAABBr   c                 `   	 t          j        j        | j        g|R  }t           j                            |d          }|                     |d          5 }t          j        |                                                    d                    cddd           S # 1 swxY w Y   dS #  i cY S xY w)z"Return actual metadata of an item.metadata.jsonrS   utf-8N)	r    rT   rU   r2   r.   jsonloadsreaddecode)r+   r]   rs   r#   r,   s        r   get_metadatazStoreBackendMixin.get_metadata   s    	T]=W===Iw||I??H400 <Az!&&((//'":":;;< < < < < < < < < < < < < < < < < <	IIIs0   AB' 9BB' BB' !B"B' 'B-c                      	 t          j        j         j        g|R  }                     |           t           j                            |d          } fd}                     |||           dS #  Y dS xY w)z Store metadata of a computation.r   c                                          |d          5 }|                    t          j        |                               d                     d d d            d S # 1 swxY w Y   d S )Nrh   r   )r.   writer   dumpsencode)rn   ro   r,   r+   s      r   r$   z4StoreBackendMixin.store_metadata.<locals>.write_func
  s    __]D99 BQGGDJx0077@@AAAB B B B B B B B B B B B B B B B B Bs   ;A  A$'A$N)r    rT   rU   r2   r9   rq   )r+   r]   r_   rs   r#   r$   s   `     r   store_metadataz StoreBackendMixin.store_metadata  s    	T]=W===I  +++w||I??HB B B B B ((8ZHHHHH	DDs   A-A2 2A7c                 d    t          j        j        | j        g|R  }|                     |          S )z,Check cached function is available in store.)r    rT   rU   r2   object_existsr+   r]   	func_paths      r   contains_pathzStoreBackendMixin.contains_path  s1    GL9999	!!),,,r   c                     t          j        j        | j        g|R  }|                     |          r|                     |           dS dS )z0Clear all items with a common path in the store.Nrv   r   s      r   
clear_pathzStoreBackendMixin.clear_path  rx   r   c                    t          j        j        | j        g|R  }|                     |          s|                     |           |yt           j                            |d          }|                     |d          5 }|                    |                    d                     ddd           dS # 1 swxY w Y   dS dS )&Store the code of the cached function.Nfunc_code.pyrh   r   )	r    rT   rU   r2   r3   r9   r.   r   r   )r+   r]   	func_coder   r#   r,   s         r   store_cached_func_codez(StoreBackendMixin.store_cached_func_code  s    GL9999	  ++ 	,  +++ w||I~>>H400 3A	((112223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ! s   ?)B55B9<B9c                     t          j        j        | j        g|dR  }	 |                     |d          5 }|                                                    d          cddd           S # 1 swxY w Y   dS #   xY w)r   r   rS   r   N)r    rT   rU   r2   r.   r   r   )r+   r]   r#   r,   s       r   get_cached_func_codez&StoreBackendMixin.get_cached_func_code(  s    7<HHHHH	400 0Avvxxw//0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0	s.   A7 'A*A7 *A..A7 1A.2A7 7A:c                 >    dt          j        j        | j        g|R  iS )z?Return information related to the cached function if it exists.r2   r|   r}   s     r   get_cached_func_infoz&StoreBackendMixin.get_cached_func_info1  r   r   c                 :    |                      | j                   dS )zClear the whole store content.N)r;   r2   r=   s    r   clearzStoreBackendMixin.clear5  s    DM*****r   c                     |                      |||          }|D ]Z}| j        dk    r"t          d                    |                     	 |                     |j                   K# t          $ r Y Ww xY wdS )zX
        Remove the store's oldest files to enforce item, byte, and age limits.
        rP   zDeleting item {0}N)_get_items_to_deleter@   rY   rK   r;   rT   OSError)r+   bytes_limititems_limit	age_limititems_to_deleterN   s         r   enforce_store_limitsz&StoreBackendMixin.enforce_store_limits9  s     33KiXX# 
	 
	D|b  )0066777##DI....   
 
	 
	s   
A%%
A21A2c                    t          |t                    rt          |          }|                                 }|sg S t	          d |D                       }|||z
  }nd}|t          |          |z
  }nd}|bt          d |D                       }|                                dk     rt          d          t          j	        
                                |z
  }	nd}	|dk    r|dk    r
|	||	k    rg S |                    t          j        d                     g }
d}d}|D ]A}||k    r||k    r|	|	|j        k     r n%|
                    |           ||j        z  }|dz  }B|
S )	zW
        Get items to delete to keep the store under size, file, & age limits.
        c              3   $   K   | ]}|j         V  d S N)sizerL   s     r   rO   z9StoreBackendMixin._get_items_to_delete.<locals>.<genexpr>V  s$      //49//////r   Nr   c              3   $   K   | ]}|j         V  d S r   )last_accessrL   s     r   rO   z9StoreBackendMixin._get_items_to_delete.<locals>.<genexpr>c  s%      @@$T-@@@@@@r   z(age_limit has to be a positive timedeltar   )keyr   )
isinstancestrr	   r>   sumlenmintotal_seconds
ValueErrordatetimenowsortoperator
attrgetterr   appendr   )r+   r   r   r   rX   r   to_delete_sizeto_delete_items
older_itemdeadliner   size_so_faritems_so_farrN   s                 r   r   z&StoreBackendMixin._get_items_to_deleteK  s    k3'' 	7)+66K   	I///////"!K/NNN"!%jj;6OOO @@%@@@@@J&&((1,, !KLLL(,,..:HHH a1$$!Z(%:%:I 	

x*=99
::: 
	 
	D.. O33%D4D)D)D""4(((49$KALLr   c                 T    t          |||          }|                     ||           dS )z7Writes an object into a file in a concurrency-safe way.N)r'   r7   )r+   rn   r#   r$   r&   s        r   rq   z)StoreBackendMixin._concurrency_safe_write  s/    3Hh
SS*H55555r   c                 N    d                     | j        j        | j                  S )z/Printable representation of the store location.z#{class_name}(location="{location}"))
class_namer2   )rK   	__class__r   r2   r=   s    r   __repr__zStoreBackendMixin.__repr__  s+    4;;~. < 
 
 	
r   )r   NN)r   r   )NN)r   r   r   r   re   rt   rw   rz   r~   r   r   r   r   r   r   r   r   r   r   rq   r   r   r   r   rF   rF      s>        % % % %N   >+ + ++ + +C C C    - - -
+ + +	3 	3 	3 	3  C C C+ + +   $: : : :x6 6 6

 
 
 
 
r   rF   c                       e Zd ZdZ ee          Z eej        j	                  Z
 ee          Zd Zd Zd ZddZdS )	FileSystemStoreBackendz7A StoreBackend used with local or network file systems.c                 j    || j         k    rt          |           dS t          j        |d           dS )zDelete location on store.T)ignore_errorsN)r2   r   shutilrmtreer1   s     r   r;   z%FileSystemStoreBackend.clear_location  s>    t}$$x     M($777777r   c                 $    t          |           dS )zCreate object location on storeN)r
   r1   s     r   r9   z&FileSystemStoreBackend.create_location  s    xr   c                   	 g }t          j        | j                  D ]<\  	}}t          j        dt           j                            	                    }|r t           j                            	d          }	 t           j                            |          }nB# t          $ r5 	 t           j                            	          }n# t          $ r Y Y w xY wY nw xY wt          j
                            |          }	 	fd|D             }t          d |D                       }n# t          $ r Y w xY w|                    t          	||                     >|S )z7Returns the whole list of items available in the store.z[a-f0-9]{32}rR   c                 P    g | ]"}t           j                            |          #S r   )r    rT   rU   )rM   fndirpaths     r   
<listcomp>z4FileSystemStoreBackend.get_items.<locals>.<listcomp>  s)    %T%T%TBbgll7B&?&?%T%T%Tr   c              3   T   K   | ]#}t           j                            |          V  $d S r   )r    rT   getsize)rM   r   s     r   rO   z3FileSystemStoreBackend.get_items.<locals>.<genexpr>  s0      !O!O""'//""5"5!O!O!O!O!O!Or   )r    walkr2   rematchrT   rW   rU   getatimer   r   fromtimestampr   r   r   )
r+   rX   _	filenamesis_cache_hash_diroutput_filenamer   full_filenamesdirsizer   s
            @r   r>   z FileSystemStoreBackend.get_items  s   %'WT]%;%; 	K 	K!GQ	 "9I9I'9R9R S S  K"$',,w"E"E!"$'"2"2?"C"CKK ! ! !!&(g&6&6w&?&?" ! ! ! ! $! '/==kJJ%T%T%T%T)%T%T%TN!!O!O!O!O!OOOGG    H	 ]7G[IIJJJsH   :B
C%CC
CCCCC<'D$$
D21D2r   Nc                    |i }|| _         t          j                            | j                   st	          | j                    t          j                            |          rBt          j                            |          dk    rt          j                            |          n|}t          j                            |d          }t          j                            |          s	 t          |d          5 }|	                    d           |	                    d           ddd           n# 1 swxY w Y   n2# t          $ r%}t          j        d| d| d	           Y d}~nd}~ww xY w|                    d
d          | _        |                    d          }| j        r|t          j        dd           || _        || _        dS )zsConfigure the store backend.

        For this backend, valid store options are 'compress' and 'mmap_mode'
        Njoblibz
.gitignorewz## Created by joblib automatically.
z*
zUnable to write z. Exception: r   ri   FrQ   zSCompressed items cannot be memmapped in a filesystem store. Option will be ignored.   )
stacklevel)r2   r    rT   existsr
   dirnamerW   rU   openr   r   rk   rl   getri   rQ   r@   )	r+   r2   r@   rA   cache_directory	gitignorefilerp   rQ   s	            r   rB   z FileSystemStoreBackend.configure  s   
 " O !w~~dm,, 	"4=!!! wx((-/W-=-=h-G-G8-S-S GOOH%%% 	
 GLL,??	w~~i(( 	OO)S)) &TJJEFFFJJu%%%& & & & & & & & & & & & & & &  O O OMMMMMMNNNNNNNNO (++J>> $''44	= 	Y2M<    #s<   'D: 7+D."D: .D22D: 5D26D: :
E)E$$E))r   N)r   r   r   r   staticmethodr   r.   r    rT   r   r3   r   r7   r;   r9   r>   rB   r   r   r   r   r     s        AAd##J<//L566J8 8 8    @/ / / / / /r   r   )%r   collectionsr   r   r   r    os.pathr   r   r   rV   r   rk   abcr   r   pickler   rH   r   	backportsr   diskr	   r
   r   loggerr   
namedtupler   Warningr   r'   r)   objectrF   r   r   r   r   <module>r      s   4 4        				  				         ' ' ' ' ' ' ' '                   . . . . . . 5 5 5 5 5 5 5 5 5 5      &&8OPP	 	 	 	 	7 	 	 	  f f f f f f f f fRx
 x
 x
 x
 x
 x
 x
 x
va a a a a-/@ a a a a ar   