
    7Th\                        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rSSKrSSKrSSKrSSKJr  SSKJrJrJr  SSKJrJrJrJrJr  SSKJrJrJr  Sr S	 r! " S
 S\"5      r#S\0r$S r%SS jr&S r'\RP                  " 5       r) " S S\5      r* " S S\+5      r, " S S\+5      r- " S S\-5      r. " S S\5      r/ " S S\/5      r0 " S S\5      r1 S S jr2g)!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                     U R                  [        5      (       aF  U R                  S5      n [        U S   [	        [        5      S 5      nSR                  U SS 5      n X4$ SnX4$ )zMExtract the first line information from the function code
text if available.

r   Nr   )
startswithFIRST_LINE_TEXTsplitintlenjoin)	func_code
first_lines     E/var/www/auris/envauris/lib/python3.13/site-packages/joblib/memory.pyextract_first_liner   9   sm     O,,OOD)	1c/&:&<=>
IIim,	    
      c                       \ rS rSrSrSrg)JobLibCollisionWarningF   z@Warn that there might be a collision between names of functions. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r!   r   r   r   r   F   s    Jr   r   localc                     [        U [        5      (       d  [        SR                  U 5      5      eUb  [	        U[
        5      (       d  [        SR                  U5      5      eU[        U '   g)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_backendr2   M   sj    $ lC((AHHV
 	
 j2BCCIPP
 	
 %,OL!r   c                 2   Uc  0 n[        U[        R                  5      (       a  [        U5      n[        U[        5      (       a  U$ [        U[        5      (       a{  Sn[
        R                  R                  U5      n[        R                  5        H  u  pVX:X  d  M  U" 5       nM     Uc  [        SR                  X5      5      eUR                  XUS9  U$ Ub>  [        R                  " SR                  UR                  R                   5      ["        5        g)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)r1   locationr5   r6   objbackend_keybackend_objs          r   _store_backend_factoryrG   m   s    (GLL))x=(,--	Hc	"	"77%%h/ )8(=(=(?$K%!m )@ ;5<<XO  	hQ
		;;A6""++< 	
 r   c                 `    [        U 5      u  p[        R                  R                  " / UQUP76 $ )z:Build a roughly unique identifier for the cached function.)r   r9   r:   r   )funcmodulesfuncnames      r   _build_func_identifierrL      s*    %d+G77<<++(++r   c                   t    \ rS rSrSr     SS jr\S 5       r\S 5       r\S 5       r	S r
S	 rS
 rS rSrg)MemorizedResult   a  Object 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.
Nc                 (   [         R                  " U 5        X l        [        X1US9U l        X@l        Ub  Xpl        O*U R                  R                  U R                  5      U l        U R                  R                  SS 5      U l	        XPl
        X`l        g )Nr5   duration)r   __init___call_idrG   store_backend	mmap_modemetadataget_metadatagetrR   r5   	timestamp)selfrC   call_idr1   rV   r5   rZ   rW   s           r   rS   MemorizedResult.__init__   sr     	3GwW"$M ..;;DMMJDM))*d;"r   c                     U R                   $ N)func_idr[   s    r   rI   MemorizedResult.func   s    ||r   c                      U R                   S   $ Nr   rT   ra   s    r   r`   MemorizedResult.func_id       }}Qr   c                      U R                   S   $ )Nr   re   ra   s    r   args_idMemorizedResult.args_id   rg   r   c           	      b    U R                   R                  U R                  U R                  U R                  U R
                  S9$ ! [         a^  n[        SR                  [        R                  R                  " U R                   R                  /U R                  Q76 5      5      nX!eSnAff = f)z$Read value from cache and return it.)rZ   rW   r5   zaError while trying to load a MemorizedResult's value. It seems that this folder is corrupted : {}N)rU   	load_itemrT   rZ   rW   r5   r,   KeyErrorr-   r9   r:   r   rC   )r[   excnew_excs      r   rY   MemorizedResult.get   s    	#%%//..	 0    	#>>DfGGLL!3!3!<!<Mt}}M?G "	#s   AA 
B.AB))B.c                 N    U R                   R                  U R                  5        g)zClear value from cacheN)rU   
clear_itemrT   ra   s    r   clearMemorizedResult.clear   s    %%dmm4r   c                     SR                   " U R                  R                  U R                  R                  /U R
                  Q76 $ )Nz*{}(location="{}", func="{}", args_id="{}"))r-   rA   r"   rU   rC   rT   ra   s    r   __repr__MemorizedResult.__repr__   s<    ;BBNN##T%7%7%@%@
CG==
 	
r   c                 D    U R                   R                  5       nS US'   U$ )NrZ   __dict__copyr[   states     r   __getstate__MemorizedResult.__getstate__  s#    ""$!kr   )rT   rR   rW   rV   rU   rZ   r5   )r(   Nr   NN)r"   r#   r$   r%   r&   rS   propertyrI   r`   ri   rY   rs   rv   r~   r'   r!   r   r   rN   rN      sn    D #0          #$5

r   rN   c                   @    \ rS rSrSrSrS rS rS rS r	S r
S	 rS
rg)NotMemorizedResulti  zpClass representing an arbitrary value.

This class is a replacement for MemorizedResult when there is no cache.
valuevalidc                     Xl         SU l        g )NTr   )r[   r   s     r   rS   NotMemorizedResult.__init__  s    

r   c                 R    U R                   (       a  U R                  $ [        S5      e)NzNo value stored.)r   r   rm   ra   s    r   rY   NotMemorizedResult.get  s    ::::-..r   c                      SU l         S U l        g NFr   r   ra   s    r   rs   NotMemorizedResult.clear  s    

r   c                     U R                   (       a7  SR                  U R                  R                  [	        U R
                  5      S9$ U R                  R                  S-   $ )Nz{class_name}({value}))
class_namer   z with no value)r   r-   rA   r"   r   r   ra   s    r   rv   NotMemorizedResult.__repr__!  sQ    ::*11>>22'$**:M 2   >>**-===r   c                 4    U R                   U R                  S.$ )Nr   r   ra   s    r   r~   NotMemorizedResult.__getstate__*  s    djj99r   c                 ,    US   U l         US   U l        g )Nr   r   r   r|   s     r   __setstate__NotMemorizedResult.__setstate__-  s    7^
7^
r   r   N)r"   r#   r$   r%   r&   	__slots__rS   rY   rs   rv   r~   r   r'   r!   r   r   r   r     s,    
 #I/>:$r   r   c                   F    \ 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g)NotMemorizedFunci5  zNo-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                     Xl         g r_   rI   )r[   rI   s     r   rS   NotMemorizedFunc.__init__B  s    	r   c                 &    U R                   " U0 UD6$ r_   r   r[   argskwargss      r   __call__NotMemorizedFunc.__call__E  s    yy$)&))r   c                 8    [        U R                  " U0 UD65      $ r_   r   rI   r   s      r   call_and_shelve NotMemorizedFunc.call_and_shelveH  s    !$))T"<V"<==r   c                 b    SR                  U R                  R                  U R                  5      $ )Nz{0}(func={1}))r-   rA   r"   rI   ra   s    r   rv   NotMemorizedFunc.__repr__K  s#    %%dnn&=&=tyyIIr   c                     g r_   r!   r[   r@   s     r   rs   NotMemorizedFunc.clearN  s    r   c                 *    U R                   " U0 UD60 4$ r_   r   r   s      r   callNotMemorizedFunc.callR  s    yy$)&)2--r   c                     gr   r!   r   s      r   check_call_in_cache$NotMemorizedFunc.check_call_in_cacheU  s    r   r   NT)r"   r#   r$   r%   r&   rS   r   r   rv   rs   r   r   r'   r!   r   r   r   r   5  s+    	*>J.r   r   c                       \ rS rSrS rSrg)AsyncNotMemorizedFunci\  c                 T   #    [        U R                  " U0 UD6I S h  vN 5      $  N7fr_   r   r   s      r   r   %AsyncNotMemorizedFunc.call_and_shelve]  s$     !		4(B6(B"BCC"Bs   (&	(r!   N)r"   r#   r$   r%   r   r'   r!   r   r   r   r   \  s    Dr   r   c                       \ rS rSrSr       SS jrS rS r\S 5       r	S r
S	 rS
 rS rS rS rS rSS jrSS jrS rSS jrS rS rSS jrS S jrS S jrS!S jrS rSrg)"MemorizedFuncid  a  Callable 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.
Nc
           
         [         R                  " U 5        XPl        X`l        Xl        Xl        [        U5      U l        Ub  UO/ U l        Xpl	        [        UUU[        XeS9S9U l        U R                  b&  U R                  R                  U R                  /5        Ub  UO[        R                  " 5       U l         [         R"                  " X5        [&        R(                  " U5      (       aP  [*        R,                  " 5       R/                  U5      n
U
R1                  SSS5      n
[2        R4                  " SSU
5      n
OUR6                  n
SU
-  U l        S U l        S U l        g ! [$         a     Nf = f)	NcompressrV   r4   r   z

r   z. zMemoized version of %s)r   rS   rV   r   rI   cache_validation_callbackrL   r`   ignore_verboserG   dictrU   store_cached_func_codetimerZ   	functoolsupdate_wrapper	Exceptioninspect
isfunctionpydocTextDocdocumentreplaceresubr&   _func_code_info_func_code_id)r[   rI   rC   r1   r   rV   r   r5   rZ   r   docs              r   rS   MemorizedFunc.__init__  s;    	" 	)B&-d3 & 2f 4 (H	
 )55t||nE&/&;	$$T0 d##--/**40C++dFA.C&&"c*C ,,C/#5#!  		s   <E" "
E/.E/c                 $   U R                  SS9(       d  gU R                  R                  U5      (       d  gU R                  R                  U5      nU R                  b2  U R	                  U5      (       d  U R                  R                  U5        gg)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.
   
stacklevelFT)_check_previous_func_coderU   contains_itemrX   r   rr   r[   r\   rW   s      r   _is_in_cache_and_valid$MemorizedFunc._is_in_cache_and_valid  s     ---; !!//88 %%227;**6228<<))'2r   c                    U R                   " U0 UD6nU R                  U4n[        U R                  5      u  pgU R                  R                  U R                  /5      nUS   n	U R                  S:  ao  [        R                  " [        R                  S9  [        U R                  /UQ70 UD6u  pjU R                  [        R                  " SU SU
 SU SU	 S3	5      5        U R                  U5      (       a{  U(       a  U R                  U5      0 4$  [         R                   " 5       nU R#                  U5      nU R                  S	:  a&  U R%                  [         R                   " 5       U-
  S
S9  U0 4$ U R                  S:  a  U R)                  SU SU SU	 35        U R1                  XQX#5      $ ! [&         aR    [        U R                  /UQ70 UD6u  pjU R)                  SR+                  U
[,        R.                  " 5       5      5         Nf = f)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.
rC      )levelz"
                        Querying z( with signature
                        z*.

                        (argument hash z1)

                        The store location is z.
                        r   zcache loaded )contextz*Exception while loading results for {}
 {}
   zComputing func z, argument hash z in location )_get_args_idr`   r   rI   rU   get_cached_func_infor   loggingbasicConfigINFOr
   infotextwrapdedentr   _get_memorized_resultr   
_load_item_print_durationr   r@   r-   	traceback
format_exc_call)r[   r   r   shelvingri   r\   _	func_name	func_inforC   	signature
start_timeoutputs                r   _cached_callMemorizedFunc._cached_call  s   , ##T4V4<<)$TYY/&&;;T\\NK	Z(==Bgll3+DIIGGGLAII""+ -" $((/y 1//7j 9	  &&w//11':B>>!YY[
1==1$((		j0/ )  rz! ==2II!),<WI F'j* zz'::!  /		KDKFK		AHH!9#7#7#9s   AF/ /AH
Hc                 j   [        U R                  S5      (       af  U R                  c%  [        U R                  R                  5      U l        O4[        U R                  R                  5      U R                  :w  a  S U l        U R
                  c  [        U R                  5      U l        U R
                  $ )N__code__)hasattrrI   r   idr   r   r   ra   s    r   func_code_infoMemorizedFunc.func_code_info4  s     499j))!!)%'		(:(:%;"DII&&'4+=+=='+$' $1#;D ###r   c                 (    U R                  XSS9S   $ )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 picklable, 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      r   r   MemorizedFunc.call_and_shelveK  s         =a@@r   c                 (    U R                  XSS9S   $ NFr   r   r   r   s      r   r   MemorizedFunc.__call__]  s       >qAAr   c                 f    U R                   nU R                  R                  5       nS US'   S US'   U$ )NrZ   r   )r   rz   r{   )r[   r   r}   s      r   r~   MemorizedFunc.__getstate__a  s>      ""$!k "&or   c                 `    U R                   U R                  " U0 UD64nU R                  U5      $ )a  Check if the function call is cached and valid for given arguments.

Does not call the function or do any work besides function inspection
and argument hashing.

- 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
-------
is_call_in_cache: bool
    Whether or not the function call is in cache and can be used.
)r`   r   r   r[   r   r   r\   s       r   r   !MemorizedFunc.check_call_in_cacheq  s3      <<!2!2D!CF!CD**733r   c                     [         R                  " [        U R                  U R                  X5      U R
                  SLS9$ )z,Return the input parameter hash of a result.N)coerce_mmap)r   hashr   rI   r   rV   r   s      r   r   MemorizedFunc._get_args_id  s3    ||		4;;=d2
 	
r   c                     [        [        U R                  SS5      5      n[        U R                  5      [        U R                  5      U4$ )z'Hash a function to key the online cacher   N)r
  getattrrI   r   )r[   func_code_hs     r   
_hash_funcMemorizedFunc._hash_func  s6    7499j$?@$))}d499o{::r   c                 L   S[         X!4-  nU R                  R                  U R                  /U5        [	        U R
                  S5      =(       a    U R
                  R                  S:g  nU(       a%  U R                  5       n U[        U R
                  '   gg! [         a     gf = f)z3Write the function code and the filename to a file.z%s %i
%sr"   <lambda>N)
r   rU   r   r`   r   rI   r"   r  _FUNCTION_HASHESr=   )r[   r   r   is_named_callable	func_hashs        r   _write_func_codeMemorizedFunc._write_func_code  s      ?J"JJ	114<<.)L DIIz*Otyy/A/AZ/O 	  )I.7 +   s   B 
B#"B#c                 `    U R                   [        ;   a(  U R                  5       nU[        U R                      :X  a  gU R                  u  p4n [        U R                  R                  U R                  /5      5      u  pgXc:X  a  g[        U R                   SSS9u  pXus=:X  a  S:X  d  O  U	S:X  aH  US:X  d  SR                  XU5      n
OU	n
[        R                  " [!        SR                  U
5      5      US9  Xu:X  Gd  UGb  ["        R$                  R'                  U5      (       a  [        U R                   SS
9u  p[)        UR+                  S5      5      n[,        R.                  " U5       nUR1                  5       US-
  US-
  U-   S-
   nS	S	S	5        SR3                  W5      nUR5                  5       UR5                  5       :H  nOUR7                  S5      nU(       a'  [        R                  " [!        SU	UUU	UU4-  5      US9  U R8                  S:  a@  [        U R                   SS
9u  pU R                  SR                  XR                  5      5        U R;                  SS9  g! [         a     GN5f = f! [        [        4 a    U R                  X55         gf = f! , (       d  f       GN= f)z`
stacklevel is the depth a which this function is called, to
issue useful warnings to the user.
TF)resolv_aliaswin_charactersr   r  z{0} ({1}:{2})z0Cannot detect name collisions for function '{0}'r   N)r  r   r   r   z	<doctest zHPossible name collisions between functions '%s' (%s:%i) and '%s' (%s:%i)r   z-Function {0} (identified by {1}) has changed.)r@   )rI   r  r  r=   r   r   rU   get_cached_func_coder`   IOErrorOSErrorr  r   r-   r?   r@   r   r9   r:   existsr   r   tokenizeopen	readlinesr   rstripr   r   rs   )r[   r   r  r   source_filer   old_func_codeold_first_liner   r   func_description	num_linesfon_disk_func_codepossible_collisions                  r   r   'MemorizedFunc._check_previous_func_code  s   
	yy,, !OO-	 0 ;; .2-@-@*	
	,>""77G-)M % %IIE%
 -2-j1H##2#9#9J$  $- MM&FMM(
 & +0Gww~~k**,TYYUK	 56	]];/1()&*^a-?)-Ka-O)% 0 %'GG,=$>!%,,.-2F2F2HH # &1%;%;K%H"!*8 &'*%'&	  *$ ==2(GLAII?FF||
 	


m  		 ! 	!!)8	J 0/s/   ;I& 1I7 , J&
I43I47!JJ
J-c                     U R                   nU R                  S:  a  U(       a  U R                  SU-  5        U R                  R	                  U/5        U R
                  u  p4nU R                  X55        g)zEmpty the function's cache.r   z(Clearing function cache identified by %sN)r`   r   r@   rU   
clear_pathr   r  )r[   r@   r`   r   r   r   s         r   rs   MemorizedFunc.clear  sg    ,,==1II@7JK%%	
 $(#6#6 	ji4r   c                 b    U R                   U R                  " U0 UD64nU R                  X1U5      $ )a  Force 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       r   r   MemorizedFunc.call#  s5    ( <<!2!2D!CF!CD zz'00r   c                     U R                  X#5        [        R                  " 5       nU R                  " U0 UD6nU R                  XX4Xe5      $ r_   _before_callr   rI   _after_callr[   r\   r   r   r   r   r   s          r   r   MemorizedFunc._call<  sC    $'YY[
D+F+vTTr   c                 d    U R                   S:  a   [        [        U R                  X5      5        g g rd   )r   printr	   rI   r   s      r   r3  MemorizedFunc._before_callC  s&    ==1+dii67 r   c                 V   U R                   R                  XU R                  S9  [        R                  " 5       U-
  nU R                  S:  a  U R	                  U5        U R                  XqX#5      nU(       a  U R                  X5      U4$ U R                  b  U R                  X5      nXX4$ )NrQ   r   )	rU   	dump_itemr   r   r   _persist_inputr   rV   r   )	r[   r\   r   r   r   r   r   rR   rW   s	            r   r4  MemorizedFunc._after_callG  s    $$Wdmm$L99;+==1  *&&x$G--g@(JJ>>% __W7Fr   c                 ^   [         R                   " 5       n[        U R                  U R                  X45      n[	        S UR                  5        5       5      nUUUS.n	U R                  R                  X)5        [         R                   " 5       U-
  n
X:  a  [        R                  " SU
-  SS9  U	$ )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.
c              3   @   #    U  H  u  pU[        U5      4v   M     g 7fr_   )repr).0kvs      r   	<genexpr>/MemorizedFunc._persist_input.<locals>.<genexpr>j  s     I3H411d1g,3Hs   )rR   
input_argsr   zPersisting 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.   r   )
r   r   rI   r   r   r<   rU   store_metadatar?   r@   )r[   rR   r\   r   r   this_duration_limitr   argument_dict
input_reprrW   this_durations              r   r<  MemorizedFunc._persist_inputV  s    " YY[
#DIIt{{DII=3F3F3HII
 !$
 	))'<		j0. MM4
 7DD  r   c                 ^    [        U R                  UUU R                  U R                  S-
  S9$ )Nr   rW   rZ   r5   )rN   rU   rZ   r   r   s      r   r   #MemorizedFunc._get_memorized_result  s1    nnMMA%
 	
r   c                 `    U R                   R                  XU R                  U R                  S9$ )NrO  )rU   rl   rZ   r   r   s      r   r   MemorizedFunc._load_item  s/    !!++$..$-- , 
 	
r   c           	          [        U R                  5      u  p4U SU S[        U5       3n[        [	        SS[        U5      -
  5      S-  U-   5        g )N z- r   P   r   )r   rI   r   r8  maxr   )r[   rR   r   r   namemsgs         r   r   MemorizedFunc._print_duration  sO    		*ay;x#8"9:c!b3s8m%+c12r   c                     SR                  U R                  R                  U R                  U R                  R
                  S9$ )Nz.{class_name}(func={func}, location={location}))r   rI   rC   )r-   rA   r"   rI   rU   rC   ra   s    r   rv   MemorizedFunc.__repr__  s>    ?FF~~..''00 G 
 	
r   )r&   r   r   r   r   r   rI   r`   r   rV   rU   rZ   )r(   NNFr   NN)   r   F)g      ?r_   )r   )r"   r#   r$   r%   r&   rS   r   r   r   r   r   r   r~   r   r   r  r  r   rs   r   r   r3  r4  r<  r   r   r   rv   r'   r!   r   r   r   r   d  s    +j "&1"f<K;Z $ $,A$B 4.
;
0gR512U8 0d


3
r   r   c                   >   ^  \ rS rSrS rS rU 4S jrSS jrSrU =r	$ )AsyncMemorizedFunci  c                    #    U R                  XSS9n[        R                  " U5      (       a
  UI S h  vN OUnUS   $  N7fr  r   asyncioiscoroutiner[   r   r   outs       r   r   AsyncMemorizedFunc.__call__  sC     u="..s33Cii1v    1A?Ac                    #    U R                  XSS9n[        R                  " U5      (       a
  UI S h  vN OUnUS   $  N7f)NTr   r   ra  rd  s       r   r   "AsyncMemorizedFunc.call_and_shelve  sC     t<"..s33Cii1v rg  c                 ~   >#    [         TU ]  " U0 UD6n[        R                  " U5      (       a
  UI S h  vN $ U$  N7fr_   )superr   rb  rc  )r[   r   r   re  rA   s       r   r   AsyncMemorizedFunc.call  s8     glD+F+#//44Sy=#=ys   1=;=c                    #    U R                  X#5        [        R                  " 5       nU R                  " U0 UD6I S h  vN nU R                  XX4Xe5      $  N7fr_   r2  r5  s          r   r   AsyncMemorizedFunc._call  sN     $'YY[
yy$1&11vTT 2s   <AAAr!   r]  )
r"   r#   r$   r%   r   r   r   r   r'   __classcell__)rA   s   @r   r_  r_    s    

>U Ur   r_  c                   h    \ rS rSrSr      SS jr     SS jrSS jrSS jrS r	S	 r
S
 rSrg)Memoryi  ad  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, default='local'
    Type of store backend for reading/writing cache files.
    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.

backend_options: dict, optional
    Contains a dictionary of named parameters used to configure
    the store backend.
Nc                    [         R                  " U 5        XPl        X0l        [        R                  " 5       U l        X l        X@l        Uc  0 nX`l        U(       a  Ub  [        R                  " SSS9  Xl        [        U[        5      (       a   [        R                  R!                  US5      n[#        UUU R                  [%        SXCS.UD6S9U l        g )Nz&Compressed results cannot be memmappedr\  r   joblibr   r4   r!   )r   rS   r   rV   r   rZ   r1   r   r6   r?   r@   rC   r*   r+   r9   r:   r   rG   r   rU   )r[   rC   r1   rV   r   r5   r6   s          r   rS   Memory.__init__  s     	" " O.	-MMBqQ h$$ww||Hh7H3MM  !:I	
r   c                 D   Ub  [        U5      (       d  [        SU S35      eUc"  [        R                  " U R                  UUUUS9$ U R
                  c/  [        R                  " U5      (       a  [        O[        nU" U5      $ Uc  U R                  nUSL a  U R                  n[        U[        5      (       a  UR                  n[        R                  " U5      (       a  [        O[        nU" UU R
                  U R                   UUU R"                  UU R$                  US9	$ )a  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`.
z4cache_validation_callback needs to be callable. Got .)r   rV   r5   r   F)rC   r1   r   rV   r   r5   rZ   r   )callabler,   r   partialcacherU   rb  iscoroutinefunctionr   r   r   rV   r*   r   rI   r_  r1   r   rZ   )r[   rI   r   r5   rV   r   clss          r   ry  Memory.cache  s+   P %0%:
 :
 014  < $$

#*C  % ..t44 &% 
 t9?mmGIdM**99D$+$?$?$E$E =''LL]]nn&?

 
	
r   c                     U(       a  U R                  S5        U R                  b/  U R                  R                  5         [        R                  5         gg)z#Erase the complete cache directory.zFlushing completely the cacheN)r@   rU   rs   r  r   s     r   rs   Memory.clearg  sC    II56)$$& ""$ *r   c                 l    U R                   c  gUc  Uc  Uc  gU R                   R                  XU5        g)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. Example: to remove files older than 5 days,
    use datetime.timedelta(days=5). Negative timedelta are not
    accepted.
N)rU   enforce_store_limits)r[   bytes_limititems_limit	age_limits       r   reduce_sizeMemory.reduce_sizet  s>    8 %;#69;L 	//)Tr   c                 Z    U R                   c  U" U0 UD6$ U R                  U5      " U0 UD6$ )zEval 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.

)rU   ry  )r[   rI   r   r   s       r   evalMemory.eval  s9     %(((zz$000r   c                     SR                  U R                  R                  U R                  c  S S9$ U R                  R                  S9$ )Nz!{class_name}(location={location}))r   rC   )r-   rA   r"   rU   rC   ra   s    r   rv   Memory.__repr__  sU    299~~..**2 : 
 	
 9=8J8J8S8S : 
 	
r   c                 D    U R                   R                  5       nSUS'   U$ )zQWe don't store the timestamp when pickling, to avoid the hash
depending from it.
NrZ   ry   r|   s     r   r~   Memory.__getstate__  s%     ""$!kr   )r   r1   r6   r   rC   rV   rU   rZ   )Nr(   NFr   N)NNNFNr   )NNN)r"   r#   r$   r%   r&   rS   ry  rs   r  r  rv   r~   r'   r!   r   r   rq  rq    sU    '^ !
J "&Q
f%%UN1"
r   rq  c           
      H   ^ [         R                  " U UUUUUUS9mU4S jnU$ )zHelper 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                 `   > [         R                   " 5       U S   -
  nUTR                  5       :  $ )Nr   )r   total_seconds)rW   computation_agedeltas     r   r   0expires_after.<locals>.cache_validation_callback  s,    ))+(88!4!4!666r   )datetime	timedelta)	r  r  r  r  r  r  r  r   r  s	           @r   expires_afterr    s7     !!E7 %$r   )r   N)r   r   r   r   r   r   r   )3r&   rb  r  r   r   r   r9   r7   r   r   r   r   r  r   r?   weakrefr   r   _store_backendsr   r   r   func_inspectr   r	   r
   r   r   loggerr   r   r   r   r   rB   r   r/   r2   rG   rL   WeakKeyDictionaryr  rN   objectr   r   r   r   r_  rq  r  r!   r   r   <module>r     s        	   	        
  1 0!
!K[ K 23,@(V, ,,. af aH$$ $$T!v !ND, D@	
F @	
LU U2wV w@ RS%r   