
    7Th6                         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Jr  SSKJ	r
  SSKJr  Sr\R                  " S\5      rS	 rS
 rSS jrS rS rS\" 5       4S jrS rS rSS jrg)z>
My own variation on function-specific inspect-like features.
    N)islice)open   )pformatzAargs varargs varkw defaults kwonlyargs kwonlydefaults annotationsFullArgSpecc                    Sn U R                   nUR                  n[        R                  R	                  U5      (       d{  SR                  [        R                  " U 5      S   5      nSnUR                  S5      (       a7  [        R                  " SU5      R                  5       u  p[        U5      nSU-  nX1U4$ [        U5       nUR                  n[        [!        XVS-
  S5      5      nSSS5        SR                  [        R"                  " W5      5      UW4$ ! , (       d  f       N6= f!   [%        U S5      (       a(  ['        U R                   R)                  5       5      US	4s $ [+        U 5      US	4s $ = f)
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           K/var/www/auris/envauris/lib/python3.13/site-packages/joblib/func_inspect.pyget_func_coder)      sL   * K /}}&&ww~~k** '''"8"8">q"ABKG%%k22')xx4k(&( % g,,{:W44K(O,,JQ MNL ) www''56ZOO	 )(
/ 4$$t}}--/0+rAA :{B..s0   B6D, ;D, %D+/D, 
D)%D, ,9E7'E7c                     SSK n[        US5      (       a  UR                  nOSSKnUR                  R                  nS H  nU R                  X2" U5      5      n M     U $ )z2Windows cannot encode some characters in filename.r   Nquote)<>!:\)urllibr   r+   urllib.parseparsereplace)stringr1   r+   chars       r(   _clean_win_charsr7   R   sR    vw 	""*eDk2 +M    c                    [        U S5      (       a  U R                  nO [        R                  " U 5      nUc  SnUS:X  Ga   [        R                  R                  [        R                  " U 5      5      nUb  UR                  [        R                  5      nUS   R                  S5      (       a2  US   R                  S	5      nS	R                  USS
 USS -   5      US'   O-[        U5      S
:  a  US   R                  S5      (       a  SUS'   S	R                  U5      nUR                  S5      (       a  USS nUS	-   U-   nUR                  S5      n[        U S5      (       a  U R                   nO [        U S5      (       a  U R"                  nOSnU(       a7  [        U S5      (       a&  XpR$                  ;   a  U R$                  U   U La  SU-  n[        U S5      (       a=  U R&                  U:w  a-  UR)                  U R&                  R                  S5      SS 5        [        R*                  " U 5      (       a8  [        U S5      (       a'  U R,                  nUR/                  UR"                  5        [        R0                  S:X  a-  U(       a&  [3        U5      nU V	s/ s H  n	[3        U	5      PM     nn	X74$ ! [         a0    [        U S5      (       a  U R
                  R                  n GNSn GNf = f!   Sn GN= fs  sn	f )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nt)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partsrP   rW   klassss
             r(   get_func_namer_   b   s    t\""	#&&t,F ~	www'<'<T'BCH NN266*ERy##$455 b	,HHU2AYqr%:;b	UaE"I$8$8$F$F (b	xxH  ''#CR=c\H,F\\#Ft[!!~~	z	"	"}}4((T5F5F-F  &d2!D(t^$$):):d)B 	d''--c23B784$$MMEMM%..)	ww$>%/56v!"1%v6<I  	#t[))22"		#	Hn 7s)   J6 3K3 K=61K0*K0/K03K:c                 $    SR                  X5      $ )z.Helper function to output a function signaturez{}{})format)function_namearg_sigs     r(   _signature_strrd      s    ==00r8   c                     Sn[        U5      SS nSR                  S UR                  5        5       5      nUR                  XU5      $ )z)Helper function to output a function callz{0}({1}, {2})r   r   , c              3   8   #    U  H  u  pU< S U< 3v   M     g7f)=N ).0kvs      r(   	<genexpr>'_function_called_str.<locals>.<genexpr>   s     Ga+s   )r   r   itemsra   )rb   argskwargstemplate_strargs_str
kwargs_strs         r(   _function_called_strru      sD    "LDz!BHGGGJ}
CCr8   ri   c                    [        U5      n[        U[        5      (       a  [        SU< S[	        U5      < S35      e[
        R                  " U 5      (       d>  [
        R                  " U 5      (       d#  U(       a  [        R                  " SU -  SS9  X#S.$ [
        R                  " U 5      n/ n/ n/ nSnSn	UR                  R                  5        GH
  n
U
R                  U
R                  L a  UR                  U
R                   5        OU
R                  U
R"                  L a7  UR                  U
R                   5        UR                  U
R                   5        OKU
R                  U
R$                  L a  U
R                   nO%U
R                  U
R&                  L a  U
R                   n	U
R(                  U
R*                  Ld  M  UR                  U
R(                  5        GM     [
        R                  " U 5      (       aT  U R,                  /U-   n[
        R                  " U R.                  5      n[1        [3        UR                  5      5      nU/U-   n[5        U S	S
9u  p[7        5       nSn[9        U5       Hw  u  nnU[;        U5      :  a;  UU;  a
  UU   UU'   M%  [        SU< S[=        X5      < S[?        XU5      < S35      eU[;        U5      -
  nUU;   a
  UU   UU'   Mn   UU   UU'   My     [7        5       n[E        URG                  5       5       H/  u  nnUU;   a  UUU'   M  U	b  UUU'   M  [I        SU< SU< S35      e   U	b  UUS'   Ub  UUS-   S nUUS'   U H6  nUU;   a  URK                  U5        M  [        SU< S[=        X5      < 35      e   U$ ! [@        [B        4 a-  n[        S[=        X5      < S[?        XU5      < S35      UeSnAff = f)a  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)rX   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 ''ry   r   rx   zIgnore list: argument 'z' is not defined for function )&r   
isinstancer   
ValueErrortyper   rU   
isfunctionwarningswarn	signature
parametersvalueskindPOSITIONAL_OR_KEYWORDrV   rW   KEYWORD_ONLYVAR_POSITIONALVAR_KEYWORDdefaultempty__self____func__nextiterr_   dict	enumeraterR   rd   ru   
IndexErrorKeyErrorsortedro   rM   pop)r    
ignore_lstrp   rq   rc   	arg_namesarg_defaultsarg_kwonlyargsarg_varargs	arg_varkwparamclass_method_sig	self_name_rW   arg_dictarg_positionarg_namepositione	varkwargs	arg_valuevarargsitems                           r(   filter_argsr      s   * :D*c""(2D4DF
 	

 D!!'*<*<T*B*BMMFM ((%GILNKI##**,::444UZZ(ZZ5---UZZ(!!%**-ZZ5///**KZZ5,,,

I==+. -  MM
 #,,T]];.99:;	K)+	 Du5GAvHL"+I"6h#d)#~-%),%7" 
 !&t5,T@	 	 $c)n4H6!%+H%5")5h)?HX&/ #7F I%flln5)x!*HX""+Ih+/;   6 "|a')* 8LL!%~d'DF 	  OO #H- 	$ +490VD	 	s   !NO)(OOc                 H    [        U SS9n[        U5      S:  a  SUS S -  nU$ )Nr?   )indenti  z%s...i  )r   rR   )argformatted_args     r(   _format_argr   T  s2    C*M
=D -"55r8   c                    [        U 5      u  p4U Vs/ s H  oU(       d  M  UPM     nnU(       a#  UR                  U5        SR                  U5      nOUn[        5       nSnU H5  n	[	        U	5      n
US:  a  SU
-  n
[        U
5      nUR                  U
5        M7     UR                  UR                  5        VVs/ s H  u  pU< S[	        U5      < 3PM     snn5        SR                  U5      nU< SU< S3nXm4$ s  snf s  snnf )	NrE   r   P   z
%srh   rf   ())r_   rV   r   r   r   rR   rT   ro   )r    rp   rq   rZ   rW   mmodule_patharg_strprevious_lengthr   r   rl   ir   s                 r(   format_signaturer   [  s     &LF%A1aF%dhhv&fGO#C(R"]2Mm,}%  NNfllnMndaq+a.1nMNii G '*I!!% & Ns   
C=C=9D
c                 J    [        U /UQ70 UD6u  pES< SU< SU< SU< 3nU$ )z\Returns a nicely formatted statement displaying the function
call with the given arguments.
P________________________________________________________________________________z
[z
] Calling z...
)r   )r    rp   rq   object_namer   r   msgs          r(   format_callr   s  s-     't=d=f=OD*2Ky
QCJr8   )TT)Memory)__doc__collectionsr   r   r   r   	itertoolsr   tokenizer   r   loggerr   full_argspec_fields
namedtuplefull_argspec_typer)   r7   r_   rd   ru   r   r   r   r   r   ri   r8   r(   <module>r      s      	 	   +  H   **=:MN 6/r Wt1
D (*$& GT"0r8   