
    .Ph6                         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mZ ddlm	Z
 ddlmZ dZ ej        de          Zd	 Zd
 ZddZd Zd Zd e            fdZd Zd ZddZdS )z>
My own variation on function-specific inspect-like features.
    N)islice)open   )pformatzAargs varargs varkw defaults kwonlyargs kwonlydefaults annotationsFullArgSpecc                 
   d}	 | j         }|j        }t          j                            |          sd                    t          j        |           d                   }d}|                    d          r>t          j
        d|                                          \  }}t          |          }d|z  }|||fS t          |          5 }|j        }t          t!          ||dz
  d                    }ddd           n# 1 swxY w Y   d                    t          j        |                    ||fS #  t%          | d          r+t'          | j                                                   |d	fcY S t+          |           |d	fcY S xY w)
a/  Attempts to retrieve a reliable function code hash.

    The reason we don't use inspect.getsource is that it caches the
    source, whereas we want this to be modified on the fly when the
    function is modified.

    Returns
    -------
    func_code: string
        The function code
    source_file: string
        The path to the file in which the function is defined.
    first_line: int
        The first line of the code in the source file.

    Notes
    ------
    This function does a bit more magic than inspect, and is thus
    more robust.
    N r   r   z	<doctest z\<doctest (.*\.rst)\[(.*)\]\>z<doctest %s>__code__)r
   co_filenameospathexistsjoininspectgetsourcelines
startswithrematchgroupsintopen_py_sourceco_firstlinenolistr   getblockhasattrstr__hash__repr)funcsource_filecodesource_codeline_nosource_file_obj
first_linesource_liness           S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/joblib/func_inspect.pyget_func_coder)      s   * K /}&w~~k** 	5 '''"8">">q"ABBKG%%k22 ;')x4k( (&(( %W g,,,{:W44K(( 	OO,J
Q M MNNL	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O www'5566ZOO/ 4$$ 	/t}--//00+rAAAA ::{B....s<   B3D1 8D1 )C<0D1 <D  D1 D ,D1 1;F.Fc                     ddl }t          |d          r|j        }nddl}|j        j        }dD ]!}|                     | ||                    } "| S )z2Windows cannot encode some characters in filename.r   Nquote)<>!:\)urllibr   r+   urllib.parseparsereplace)stringr1   r+   chars       r(   _clean_win_charsr7   R   so    MMMvw # 	"* 3 3eeDkk22M    Tc                    t          | d          r| j        }nE	 t          j        |           }n/# t          $ r" t          | d          r| j        j        }nd}Y nw xY w|d}|dk    r.	 t          j                            t          j	        |                     }n	#  d}Y nxY w||
                    t          j                  }|d                             d          rG|d         
                    d	          }d	                    |dd
         |dd         z             |d<   n3t          |          d
k    r |d                             d          rd|d<   d	                    |          }|                    d          r
|dd         }|d	z   |z   }|
                    d          }t          | d          r| j        }nt          | d          r| j        }nd}|r-t          | d          r|| j        v r| j        |         | urd|z  }t          | d          r@| j        |k    r5|                    | j        
                    d          dd                    t          j        |           r1t          | d          r!| j        }|                    |j                   t          j        dk    r|rt3          |          }d |D             }||fS )a  Return the function import path (as a list of module names), and
    a name for the function.

    Parameters
    ----------
    func: callable
        The func to inspect
    resolv_alias: boolean, optional
        If true, possible local aliases are indicated.
    win_characters: boolean, optional
        If true, substitute special characters using urllib.quote
        This is useful in Windows, as it cannot encode some filenames
    
__module__	__class__unknownNr	   __main__r   z<ipython-input-      
ipykernel_	ipykernelz.py.	func_name__name__func_globalsz%s-alias__qualname__im_classntc                 ,    g | ]}t          |          S  )r7   ).0ss     r(   
<listcomp>z!get_func_name.<locals>.<listcomp>   s!    666!"1%%666r8   )r   r:   r   	getmodule	TypeErrorr;   r   r   abspathgetsourcefilesplitsepr   r   lenendswithrF   rG   rH   rI   extendismethodrJ   appendnamer7   )	r    resolv_aliaswin_charactersmodulefilenamepartsrU   r\   klasss	            r(   get_func_namerc   b   s    t\"" 	#	#&t,,FF 	# 	# 	#t[)) #2"		#
 ~	ww'<T'B'BCCHH	HHHNN26**ERy##$455 ( b	,,HHU2A2Yqrr%:;;b		UaE"I$8$8$F$F (b	xxH  '' )#CRC=c\H,F\\#Ft[!! ~	z	"	" } )4(( 	)TT5F-F-F &d22!D(t^$$ 9):d)B)B 	d'--c223B37888 *4$$ 	*MEMM%.)))	w$>%%66v6664<s   / )AA*1B B"c                 .    d                     | |          S )z.Helper function to output a function signaturez{}{})format)function_namearg_sigs     r(   _signature_strrh      s    ==000r8   c                     d}t          |          dd         }d                    d |                                D                       }|                    | ||          S )z)Helper function to output a function callz{0}({1}, {2})r   r   , c              3   *   K   | ]\  }}|d |V  dS )=NrM   )rN   kvs      r(   	<genexpr>z'_function_called_str.<locals>.<genexpr>   s1      GG1aaa+GGGGGGr8   )r   r   itemsre   )rf   argskwargstemplate_strargs_str
kwargs_strs         r(   _function_called_strrv      s[    "LDzz!B$HGGGGGGGJ}h
CCCr8   rM   c                 ^   t          |          }t          |t                    r#t          d|dt	          |          d          t          j        |           s4t          j        |           s |rt          j	        d| z  d           ||dS t          j
        |           }g }g }g }d}d}	|j                                        D ]}
|
j        |
j        u r|                    |
j                   nn|
j        |
j        u r5|                    |
j                   |                    |
j                   n+|
j        |
j        u r|
j        }n|
j        |
j        u r|
j        }	|
j        |
j        ur|                    |
j                   t          j        |           rK| j        g|z   }t          j
        | j                  }t1          t3          |j                            }|g|z   }t5          | d	
          \  }}t7                      }d}t9          |          D ]\  }}|t;          |          k     rF||vr||         ||<   (t          d|dt=          ||          dt?          |||          d          |t;          |          z
  }||v r||         ||<   	 ||         ||<   # t@          tB          f$ r9}t          dt=          ||          dt?          |||          d          |d}~ww xY wt7                      }tE          |#                                          D ],\  }}||v r|||<   |	|||<   tI          d|d|d          |	||d<   |||dz   d         }||d<   |D ]>}||v r|%                    |           t          d|dt=          ||                    |S )aX  Filters the given args and kwargs using a list of arguments to
    ignore, and a function specification.

    Parameters
    ----------
    func: callable
        Function giving the argument specification
    ignore_lst: list of strings
        List of arguments to ignore (either a name of an argument
        in the function spec, or '*', or '**')
    *args: list
        Positional arguments passed to the function.
    **kwargs: dict
        Keyword arguments passed to the function

    Returns
    -------
    filtered_args: list
        List of filtered positional and keyword arguments.
    z2ignore_lst must be a list of parameters to ignore z (type z) was givenz4Cannot inspect object %s, ignore list will not work.r?   )
stacklevel)***NF)r]   r   zKeyword-only parameter 'z)' was passed as positional parameter for z:
     z was called.zWrong number of arguments for zIgnore list for z,() contains an unexpected keyword argument ''rz   r   ry   zIgnore list: argument 'z' is not defined for function )&r   
isinstancer   
ValueErrortyper   rZ   
isfunctionwarningswarn	signature
parametersvalueskindPOSITIONAL_OR_KEYWORDr[   r\   KEYWORD_ONLYVAR_POSITIONALVAR_KEYWORDdefaultempty__self____func__nextiterrc   dict	enumeraterW   rh   rv   
IndexErrorKeyErrorsortedrp   rR   pop)r    
ignore_lstrq   rr   rg   	arg_namesarg_defaultsarg_kwonlyargsarg_varargs	arg_varkwparamclass_method_sig	self_name_r\   arg_dictarg_positionarg_namepositione	varkwargs	arg_valuevarargsitems                           r(   filter_argsr      s   * ::D*c"" 
j(2

D4D4D4D4DF
 
 	

 D!! )'*<T*B*B ) 	MFM    (((%%GILNKI#**,, / /:444UZ((((Z5---UZ(((!!%*----Z5///*KKZ5,,,
I=++... , M
 #,T];;.9::;;	K)+	 Du555GAtvvHL"+I"6"6 ! !h#d))##~--%),%7"" j
 !&tW5555,T4@@@@	 	 	 $c)nn4H6!!%+H%5"")5h)?HX&&"H- 	 	 	$* +499990tVDDDD	  	 I%fllnn55 	 	)x!*HX""+Ih)+/44;  
 "|a'))*   8LL*!%~dG'D'D'DF  
 Os   J((K294K--K2c                 h    t          | d          }t          |          dk    rd|d d         z  }|S )Nr?   )indenti  z%s...i  )r   rW   )argformatted_args     r(   _format_argr   T  s@    C***M
=D  -"55r8   c                    t          |           \  }}d |D             }|r+|                    |           d                    |          }n|}t                      }d}|D ]@}t	          |          }	|dk    rd|	z  }	t          |	          }|                    |	           A|                    d |                                D                        d                    |          }|d|d	}
||
fS )
Nc                     g | ]}||S rM   rM   )rN   ms     r(   rP   z$format_signature.<locals>.<listcomp>^  s    %%%A1%a%%%r8   rE   r   P   z
%sc                 <    g | ]\  }}|d t          |          S )rl   )r   )rN   rn   is      r(   rP   z$format_signature.<locals>.<listcomp>l  s-    MMMdaqqq+a...1MMMr8   rj   ())rc   r[   r   r   r   rW   rY   rp   )r    rq   rr   r_   r\   module_patharg_strprevious_lengthr   r   r   s              r(   format_signaturer   [  s    &&LFD%%%%%F dhhv&&ffGO & &#C((R"]2Mm,,}%%%%NNMMfllnnMMMNNNii  G DD'''*I	!!r8   Memoryc                 F    t          | g|R i |\  }}dd|d|d|}|S )zdReturns a nicely formatted statement displaying the function
    call with the given arguments.
    P________________________________________________________________________________z
[z
] Calling z...
)r   )r    rq   rr   object_namer   r   msgs          r(   format_callr   s  sF     't=d===f==OD)*2((KKKyy
QCJr8   )TT)r   )__doc__collectionsr   r   r   r   	itertoolsr   tokenizer   r   loggerr   full_argspec_fields
namedtuplefull_argspec_typer)   r7   rc   rh   rv   r   r   r   r   r   rM   r8   r(   <module>r      sU         				 				        + + + + + +       H  +K*=:MNN 6/ 6/ 6/r   W W W Wt1 1 1
D D D (*$$&& G G G GT  " " "0     r8   