
    sKg|7                         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y)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                  j	                  |      svdj                  t        j                  |       d         }d}|j                  d      r7t        j                  d|      j                         \  }}t        |      }d|z  }|||fS t        |      5 }|j                  }t        t!        ||dz
  d            }ddd       dj                  t        j"                              |fS # 1 sw Y   0xY w#  t%        | d      r(t'        | j                   j)                               |d	fcY S t+        |       |d	fcY S xY w)
al   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           W/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/joblib/func_inspect.pyget_func_coder)      sH   * K/}}&&ww~~k* '''"8"8">q"ABKG%%k2')xx4k(CCI68 %Wg,,{:W44K(O,,J
Q MNL ) www''56ZOO	 )(
/ 4$t}}--/0+rAA :{B..s0   B,D 1D <&D".D DD 4E#E#c                     ddl }t        |d      r|j                  }nddl}|j                  j                  }dD ]  }| j                  | ||            }  | S )z2Windows cannot encode some characters in filename.r   Nquote)<>!:\)urllibr   r+   urllib.parseparsereplace)stringr1   r+   chars       r(   _clean_win_charsr7   Q   sO    vw 	""*eDk2 +M    c                 `   t        | d      r| j                  }n	 t        j                  |       }|d}|dk(  r	 t        j                  j                  t        j                  |             }||j                  t        j                        }|d   j                  d      r2|d   j                  d	      }d	j                  |dd
 |dd z         |d<   n't        |      d
kD  r|d   j                  d      rd|d<   d	j                  |      }|j                  d      r|dd }|d	z   |z   }|j                  d      }t        | d      r| j                   }nt        | d      r| j"                  }nd}|r0t        | d      r$|| j$                  v r| j$                  |   | urd|z  }t        | d      r<| j&                  |k7  r-|j)                  | j&                  j                  d      dd        t        j*                  |       r3t        | d      r'| j,                  }|j/                  |j"                         t        j0                  dk(  r%|r#t3        |      }|D 	cg c]  }	t3        |	       }}	||fS # t        $ r) t        | d      r| j
                  j                  }nd}Y mw xY w#  d}Y <xY wc c}	w )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partssplittedrW   klassss
             r(   get_func_namer`   _   s{    t\"	#&&t,F ~	www'<'<T'BCH NN266*ERy##$45 !9??3/HHXbq\HQRL%@Ab	UaE"I$8$8$F (b	xxH  '#CR=c\H,F\\#Ft[!~~	z	"}}4(TT5F5F-F$$T*d2!D(t^$):):d)B 	d''--c23B784$MMEMM%..)	ww$>%/56v!"1%v64<I  	#t[)22"		#	Hn 7s"   I, 2J! J+,.JJ!J(c                 &    dj                  | |      S )z.Helper function to output a function signaturez{}{})format)function_namearg_sigs     r(   _signature_strre      s    ==00r8   c                     d}t        |      dd }dj                  d |j                         D              }|j                  | ||      S )z)Helper function to output a function callz{0}({1}, {2})r   r   , c              3   0   K   | ]  \  }}|d |  yw)=N ).0kvs      r(   	<genexpr>z'_function_called_str.<locals>.<genexpr>   s!      7'5tq! '(+'5s   )r   r   itemsrb   )rc   argskwargstemplate_strargs_str
kwargs_strs         r(   _function_called_strru      sR    "LDz!BH 7'-||~7 7J}h)+ +r8   rj   c                 <   t        |      }t        |t              rt        d|dt	        |      d      t        j                  |       s6t        j                  |       s!|rt        j                  d| z  d       ||dS t        j                  |       }g }g }g }d}d}	|j                  j                         D ]  }
|
j                  |
j                  u r|j                  |
j                          n|
j                  |
j"                  u r7|j                  |
j                          |j                  |
j                          nI|
j                  |
j$                  u r|
j                   }n$|
j                  |
j&                  u r|
j                   }	|
j(                  |
j*                  us|j                  |
j(                          t        j                  |       rS| j,                  g|z   }t        j                  | j.                        }t1        t3        |j                              }|g|z   }t5        | d	
      \  }}t7               }d}t9        |      D ]n  \  }}|t;        |      k  r7||vr	||   ||<   !t        d|dt=        ||      dt?        |||      d      |t;        |      z
  }||v r	||   ||<   f	 ||   ||<   p t7               }tE        |jG                               D ](  \  }}||v r|||<   |	|||<   tI        d|d|d       |	||d<   |||dz   d }||d<   |D ]2  }||v r|jK                  |       t        d|dt=        ||             |S # t@        tB        f$ r-}t        dt=        ||      dt?        |||      d      |d}~ww xY w)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   re   ru   
IndexErrorKeyErrorsortedro   rM   pop)r    
ignore_lstrp   rq   rd   	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G 	G T"7+=+=d+CMM &(,-9:<((%GILNKI##**,::444UZZ(ZZ5---UZZ(!!%**-ZZ5///**KZZ5,,,

I==+. -   4' #,,T]];.99:;	K)+	 Du5GAtvHL"+I"6h#d)#~-%),%7"   %dG4+D$?A  $c)n4H6!%+H%5"	)5h)?HX&+ #7> I%flln5)x!*HX""+Ih7;XG H H  6 "|a'() 8LL $ .tW =?  	  OI #H- $ *$8/dFCE
 s   8MN.(NNc                 L    t        | d      }t        |      dkD  rd|d d z  }|S )Nr?   )indenti  z%s...i  )r   rR   )argformatted_args     r(   _format_argr   I  s2    C*M
=D -"55r8   c                    t        |       \  }}|D cg c]  }|s|	 }}|r#|j                  |       dj                  |      }n|}t               }d}|D ]3  }	t	        |	      }
|dkD  rd|
z  }
t        |
      }|j                  |
       5 |j                  |j                         D cg c]  \  }}|dt	        |       c}}       dj                  |      }|d|d}||fS c c}w c c}}w )	NrE   r   P   z
%sri   rg   ())r`   rV   r   r   r   rR   rT   ro   )r    rp   rq   rZ   rW   mmodule_patharg_strprevious_lengthr   r   rm   ir   s                 r(   format_signaturer   P  s     &LFD%A1aF%dhhv&fGO#C(R"]2Mm,}%  NNfllnMndaq+a.1nMNii G '*I	!!% & Ns   C)C)*C.
c                 D    t        | g|i |\  }}dd|d|d|}|S )zi 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   h  s2     't=d=f=OD)*2K*.	;CJr8   )TT)Memory)__doc__r   r   r   r   collections	itertoolsr   tokenizer   r   loggerr   full_argspec_fields
namedtuplefull_argspec_typer)   r7   r`   re   ru   r   r   r   r   r   rj   r8   r(   <module>r      s}      	 	   + 4 *K**=:MN 5/pWt1
+ (*$& }@"0r8   