
    7ThC                     6   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKJrJr  SSKJr  SSKJr  SSKJr  SSKJrJrJr  SS	KJr  \R6                  " S
S5      r " S S\5      rS r " S S\S9r  " S S\!5      r" " S S\ \"5      r#g)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                       \ rS rSrSrSrg)CacheWarning   z:Warning to capture dump failures except for PicklingError. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       N/var/www/auris/envauris/lib/python3.13/site-packages/joblib/_store_backends.pyr   r      s    Dr   r   c                     [        [        R                  " 5       5      nSR                  X[        R
                  " 5       5      nU" X5        U$ )z>Writes an object into a unique file in a concurrency-safe way.z{}.thread-{}-pid-{})id	threadingcurrent_threadformatosgetpid)object_to_writefilename
write_func	thread_idtemporary_filenames        r   concurrency_safe_writer&      s<    9++-.I.55h299;W3r   c                       \ rS rSrSrSr\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
\" 5       4S j5       rSrg)StoreBackendBase(   zZHelper Abstract Base Class which defines all methods that
a StorageBackend must implement.Nc                     g)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_itemStoreBackendBase._open_item.       r   c                     g)aU  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_existsStoreBackendBase._item_existsA   r0   r   c                     g)zMoves 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_itemStoreBackendBase._move_itemR   r0   r   c                     g)zCreates a location on the store.

Parameters
----------
location: string
    The location in the store. On a filesystem, this corresponds to a
    directory.
Nr   r2   s     r   create_location StoreBackendBase.create_location`   r0   r   c                     g)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   r2   s     r   clear_locationStoreBackendBase.clear_locationk   r0   r   c                     g)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_itemsStoreBackendBase.get_itemsv   r0   r   r   c                     g)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+   r3   verbosebackend_optionss       r   	configureStoreBackendBase.configure   r0   r   r   )r   r   r   r   r   r3   r   r.   r4   r9   r<   r?   rC   dictrH   r   r   r   r   r(   r(   (   s    ( H $            *+TV  r   r(   )	metaclassc                       \ rS rSrSrSS jrSS jrS rS rS r	S	 r
S
 rS rS rSS jrS rS rS rSS jrSS jrS rS rSrg)StoreBackendMixin   aq  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.
Nc                    [         R                  R                  " U R                  /UQ76 nUS:  a  Ub0  SR	                  [        [        R                  " 5       U-
  5      5      OSn[         R                  R                  US   5      nUbC  SU;   a=  SR                  S US   R                  5        5       5      nUS	R	                  U5      -  nS
R	                  Xg5      n	US:  a  [        SR	                  U	5      5        O[        SR	                  X5      5        [        U S5      (       d  SOU R                  n
[         R                  R                  US5      nU R                  U5      (       d  [        SU-  5      eU
c3  U R                  US5       n[        R                   " U5      nSSS5        U$ [        R                   " XS9nU$ ! , (       d  f       W$ = f)z:Load an item from the store given its id as a list of str.r   Nz{: <16} r   
input_argsz, c              3   @   #    U  H  nS R                   " U6 v   M     g7f)z{}={}N)r   .0items     r   	<genexpr>.StoreBackendMixin.load_item.<locals>.<genexpr>   s      #6TdGNND)6Ts   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)rY   )r   pathjoinr3   r   r   timebasenameitemsprinthasattrrY   r4   KeyErrorr.   r   load)r+   call_idrF   	timestampmetadata	full_path	ts_string	signaturekwargsmsgrY   r"   r,   rU   s                 r   	load_itemStoreBackendMixin.load_item   s   GGLL99	Q; (   TYY[9-D!EF 
 ((4I#(@ #6>|6L6R6R6T#  V]]622	*11)GC|hooc*+n++C;< 'k : :D	77<<	<8  **46>?  40A#((+ 1   $$XCD	 10 s   G


Gc                   ^   [         R                  R                  " T R                  /UQ76 nT R	                  U5      (       d  T R                  U5        [         R                  R                  US5      nUS:  a  [        SU-  5        U 4S jnT R                  X%U5        g! [         a)  n[        R                  " SU S3[        5         SnAgSnAff = f)z;Dump an item in the store at the id given as a list of str.rZ   rX   zPersisting in %sc                 
  > TR                  US5       n [        R                  " XTR                  S9  S S S 5        g ! [         a)  n[
        R                  " SU S3[        5         S nAN7S nAff = f! , (       d  f       g = f)Nwb)compresszjUnable to cache to disk: failed to pickle output. In version 1.5 this will raise an exception. Exception: .)r.   r   dumprr   r   warningswarnFutureWarning)to_writedest_filenamer,   er+   s       r   r#   /StoreBackendMixin.dump_item.<locals>.write_func   sv    __]D9Q	$))(N :9 )  556Cq: *	  :9s,   A4>
A1A,'A4,A11A44
Bz`Unable to cache to disk. Possibly a race condition in the creation of the directory. Exception: rs   N)r   r\   r]   r3   r4   r<   ra   _concurrency_safe_write	Exceptionru   rv   r   )r+   re   rU   rF   	item_pathr"   r#   rz   s   `       r   	dump_itemStoreBackendMixin.dump_item   s    	T]]=W=I$$Y//$$Y/ww||I|<H|(945 ((D 	MM99:1> 	s   BB" "
C,CCc                     [         R                  R                  " U R                  /UQ76 nU R	                  U5      (       a  U R                  U5        gg)z1Clear the item at the id, given as a list of str.Nr   r\   r]   r3   r4   r?   )r+   re   r~   s      r   
clear_itemStoreBackendMixin.clear_item   A    GGLL99	Y''	* (r   c                     [         R                  R                  " U R                  /UQ76 n[         R                  R                  US5      nU R	                  U5      $ )z<Check if there is an item at the id, given as a list of str.rZ   )r   r\   r]   r3   r4   )r+   re   r~   r"   s       r   contains_itemStoreBackendMixin.contains_item   sB    GGLL99	77<<	<8  **r   c                 \    S[         R                  R                  " U R                  /UQ76 0$ )zReturn information about item.r3   r   r\   r]   r3   r+   re   s     r   get_item_infoStoreBackendMixin.get_item_info   #    BGGLLAABBr   c                 l    [         R                  R                  " U R                  /UQ76 n[         R                  R                  US5      nU R	                  US5       n[
        R                  " UR                  5       R                  S5      5      sSSS5        $ ! , (       d  f       g= f!   0 s $ = f)z"Return actual metadata of an item.metadata.jsonr[   utf-8N)	r   r\   r]   r3   r.   jsonloadsreaddecode)r+   re   r~   r"   r,   s        r   get_metadataStoreBackendMixin.get_metadata   sx    	T]]=W=Iww||I?H40Azz!&&(//'":; 100	Is*   AB- 3B	B- 
B*&B- *B- -B3c                    ^   [         R                  R                  " T R                  /UQ76 nT R	                  U5        [         R                  R                  US5      nU 4S jnT R                  X$U5        g!    g= f)z Store metadata of a computation.r   c                    > TR                  US5       nUR                  [        R                  " U 5      R	                  S5      5        S S S 5        g ! , (       d  f       g = f)Nrq   r   )r.   writer   dumpsencode)rx   ry   r,   r+   s      r   r#   4StoreBackendMixin.store_metadata.<locals>.write_func  s?    __]D9QGGDJJx077@A :99s   5A
A N)r   r\   r]   r3   r<   r|   )r+   re   rg   r~   r"   r#   s   `     r   store_metadata StoreBackendMixin.store_metadata   sg    	T]]=W=I  +ww||I?HB ((ZH	s   A4A8 8A<c                 z    [         R                  R                  " U R                  /UQ76 nU R	                  U5      $ )z,Check cached function is available in store.)r   r\   r]   r3   object_existsr+   re   	func_paths      r   contains_pathStoreBackendMixin.contains_path  s.    GGLL99	!!),,r   c                     [         R                  R                  " U R                  /UQ76 nU R	                  U5      (       a  U R                  U5        gg)z0Clear all items with a common path in the store.Nr   r   s      r   
clear_pathStoreBackendMixin.clear_path  r   r   c                    [         R                  R                  " U R                  /UQ76 nU R	                  U5      (       d  U R                  U5        Ub\  [         R                  R                  US5      nU R                  US5       nUR                  UR                  S5      5        SSS5        gg! , (       d  f       g= f)&Store the code of the cached function.Nfunc_code.pyrq   r   )	r   r\   r]   r3   r4   r<   r.   r   r   )r+   re   	func_coder   r"   r,   s         r   store_cached_func_code(StoreBackendMixin.store_cached_func_code  s    GGLL99	  ++  + ww||I~>H40A	((12 10 !00s   !B33
Cc                    [         R                  R                  " U R                  /UQSP76 n U R	                  US5       nUR                  5       R                  S5      sSSS5        $ ! , (       d  f       g= f!   e = f)r   r   r[   r   N)r   r\   r]   r3   r.   r   r   )r+   re   r"   r,   s       r   get_cached_func_code&StoreBackendMixin.get_cached_func_code!  s^    77<<HHH	40Avvxw/ 100	s)   A; A* 	A; *
A84A; 8A; ;A>c                 \    S[         R                  R                  " U R                  /UQ76 0$ )z?Return information related to the cached function if it exists.r3   r   r   s     r   get_cached_func_info&StoreBackendMixin.get_cached_func_info*  r   r   c                 :    U R                  U R                  5        g)zClear the whole store content.N)r?   r3   rB   s    r   clearStoreBackendMixin.clear.  s    DMM*r   c                     U R                  XU5      nU HI  nU R                  S:  a  [        SR                  U5      5         U R	                  UR
                  5        MK     g! [         a     M[  f = f)zH
Remove the store's oldest files to enforce item, byte, and age limits.
rX   zDeleting item {0}N)_get_items_to_deleterF   ra   r   r?   r\   OSError)r+   bytes_limititems_limit	age_limititems_to_deleterU   s         r   enforce_store_limits&StoreBackendMixin.enforce_store_limits2  sm     33KiX#D||b )0067##DII.	 $
  
 s   A##
A10A1c                    [        U[        5      (       a  [        U5      nU R                  5       nU(       d  / $ [	        S U 5       5      nUb  XQ-
  nOSnUb  [        U5      U-
  nOSnUbS  [        S U 5       5      nUR                  5       S:  a  [        S5      e[        R                  R                  5       U-
  n	OSn	US::  a  US::  a  U	b  WU	:  a  / $ UR                  [        R                  " S5      S9  / n
SnSnU HF  nX:  a  X:  a  U	b  XR                  :  a    U
$ U
R                  U5        XR                   -  nUS-  nMH     U
$ )	zG
Get items to delete to keep the store under size, file, & age limits.
c              3   8   #    U  H  oR                   v   M     g 7fN)sizerS   s     r   rV   9StoreBackendMixin._get_items_to_delete.<locals>.<genexpr>O  s     /99   Nr   c              3   8   #    U  H  oR                   v   M     g 7fr   )last_accessrS   s     r   rV   r   \  s     @%$--%r   z(age_limit has to be a positive timedeltar   )keyr   )
isinstancestrr	   rC   sumlenmintotal_seconds
ValueErrordatetimenowsortoperator
attrgetterr   appendr   )r+   r   r   r   r`   r   to_delete_sizeto_delete_items
older_itemdeadliner   size_so_faritems_so_farrU   s                 r   r   &StoreBackendMixin._get_items_to_deleteD  sj    k3'')+6K I///"!/NN"!%j;6OO @%@@J&&(1, !KLL((,,.:HH a1$!Z(%:I 	

x**=9
:D. 3%4D4D)D 	 ""4(99$KAL  r   c                 >    [        XU5      nU R                  XB5        g)z7Writes an object into a file in a concurrency-safe way.N)r&   r9   )r+   rx   r"   r#   r%   s        r   r|   )StoreBackendMixin._concurrency_safe_write  s    3H
S*5r   c                 ^    SR                  U R                  R                  U R                  S9$ )z/Printable representation of the store location.z#{class_name}(location="{location}"))
class_namer3   )r   	__class__r   r3   rB   s    r   __repr__StoreBackendMixin.__repr__  s-    4;;~~.. < 
 	
r   r   )r   NN)r   r   )NN)r   r   r   r   r   rm   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r|   r   r   r   r   r   rM   rM      s`    %N>++C-
+	3C+$:x6

r   rM   c                       \ rS rSrSr\" \5      r\" \R                  R                  5      r\" \5      rS rS rS rS	S jrSrg)
FileSystemStoreBackendi  z7A StoreBackend used with local or network file systems.c                 d    XR                   :X  a  [        U5        g[        R                  " USS9  g)zDelete location on store.T)ignore_errorsN)r3   r   shutilrmtreer2   s     r   r?   %FileSystemStoreBackend.clear_location  s"    }}$x MM($7r   c                     [        U5        g)zCreate object location on storeN)r
   r2   s     r   r<   &FileSystemStoreBackend.create_location  s
    xr   c                    / n[         R                  " U R                  5       GH   u  p#n[        R                  " S[         R
                  R                  U5      5      nU(       d  MD  [         R
                  R                  US5      n [         R
                  R                  U5      n[        R                  R                  U5      n U Vs/ s H"  n[         R
                  R                  X(5      PM$     n	n[        S U	 5       5      n
UR                  [        X*U5      5        GM     U$ ! [         a6     [         R
                  R                  U5      n N! [         a      GMB  f = ff = fs  snf ! [         a     GM]  f = f)z7Returns the whole list of items available in the store.z[a-f0-9]{32}rZ   c              3   `   #    U  H$  n[         R                  R                  U5      v   M&     g 7fr   )r   r\   getsize)rT   fns     r   rV   3FileSystemStoreBackend.get_items.<locals>.<genexpr>  s      !O""''//""5"5s   ,.)r   walkr3   rematchr\   r_   r]   getatimer   r   fromtimestampr   r   r   )r+   r`   dirpath_	filenamesis_cache_hash_diroutput_filenamer   r   full_filenamesdirsizes              r   rC    FileSystemStoreBackend.get_items  s5   %'WWT]]%;!G	 "9I9I'9R S  "$'',,w"E!"$''"2"2?"CK '//==kJJS%T)Bbggll7&?)N%T!!O!OOG ]7[IJ1 &<4 '  !!&(gg&6&6w&?" ! !! &U  	sN   D*E2)E-4E2*
E*5E
E& E*%E&&E*-E22
F FNc                    Uc  0 nXl         [        R                  R                  U R                   5      (       d  [	        U R                   5        [        R                  R                  U5      (       aB  [        R                  R                  U5      S:X  a  [        R                  R                  U5      OUn[        [        R                  R                  US5      S5       nUR                  S5        UR                  S5        SSS5        UR                  SS5      U l        UR                  S	5      nU R                  (       a  Ub  [        R                  " S
SS9  X`l        X l        g! , (       d  f       Nl= f)zcConfigure the store backend.

For this backend, valid store options are 'compress' and 'mmap_mode'
Njoblibz
.gitignorewz## Created by joblib automatically.
z*
rr   FrY   zSCompressed items cannot be memmapped in a filesystem store. Option will be ignored.   )
stacklevel)r3   r   r\   existsr
   dirnamer_   openr]   r   getrr   ru   rv   rY   rF   )r+   r3   rF   rG   cache_directoryfilerY   s          r   rH    FileSystemStoreBackend.configure  s   
 " O !ww~~dmm,,4==! wwx((RWW-=-=h-G8-S GGOOH% 	
 "'',,=sCtJJ=>JJu D
 (++J> $''4	==Y2MM< #% DCs   !#E**
E8)rr   r3   rY   rF   )r   N)r   r   r   r   r   staticmethodr  r.   r   r\   r  r4   r   r9   r?   r<   rC   rH   r   r   r   r   r   r     sA    Ad#J/L56J8@*r   r   )$r   collectionsr   r   r   r   os.pathr   r   r   r^   ru   abcr   r   pickler   rP   r   	backportsr   diskr	   r
   r   loggerr   
namedtupler   Warningr   r&   r(   objectrM   r   r   r   r   <module>r     s    4     	  	     '    . 5 5 &&8OP	7 	f fRx
 x
v\-/@ \r   