o �J�h�6�@s�dZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z dZ e�de �Zd d �Zd d �Zddd�Zdd�Zdd�Zde�fdd�Zdd�Zdd�Zddd�ZdS) z> My own variation on function-specific inspect-like features. �N)�islice)�open�)�pformatzAargs varargs varkw defaults kwonlyargs kwonlydefaults annotations� FullArgSpeccCsd}zb|j}|j}tj�|�s8d�t�|�d�}d}|�d�r2t � d|�� �\}}t |�}d|}|||fWSt |��}|j}tt||dd��}Wd�n1sTwYd�t�|��||fWSt|d�ryt|j���|d fYSt|�|d fYS) 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�rrz <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_noZsource_file_obj� first_line� source_lines�r%�QC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\joblib\func_inspect.py� get_func_codes2  ��  � r'cCsHddl}t|d�r |j}nddl}|jj}dD] }|�|||��}q|S)z2Windows cannot encode some characters in filename.rN�quote)�<�>�!�:�\)�urllibrr(� urllib.parse�parse�replace)�stringr.r(�charr%r%r&�_clean_win_charsRs r4Tc Cst|d�r |j}nzt�|�}Wnty%t|d�r!|jj}nd}Ynw|dur,d}|dkr�z tj�t� |��}Wnd}Y|dur�|� tj �}|d� d�rl|d� d �}d � |dd �|d d��|d<nt|�d kr}|d � d �r}d|d <d � |�}|�d�r�|dd�}|d |}|� d�}t|d�r�|j}n t|d�r�|j}nd}|r�t|d�r�||jvr�|j||ur�d|}t|d�r�|j|kr�|�|j� d�dd��t�|�r�t|d�r�|j}|�|j�tjdkr�|r�t|�}dd�|D�}||fS)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_Z ipykernelz.py������.� func_name�__name__� func_globalsz%s-alias� __qualname__�im_class�ntcSsg|]}t|��qSr%)r4)�.0�sr%r%r&� <listcomp>��z!get_func_name.<locals>.<listcomp>)rr5r� getmodule� TypeErrorr6r r �abspath� getsourcefile�split�seprr�len�endswithr@rArBrC�extend�ismethodrD�append�namer4) r� resolv_alias�win_characters�module�filename�partsrNrU�klassr%r%r&� get_func_namebs`    ��  $          r\cCs d�||�S)z.Helper function to output a function signaturez{}{})�format)� function_name�arg_sigr%r%r&�_signature_str�s r`cCs:d}t|�dd�}d�dd�|��D��}|�|||�S)z)Helper function to output a function callz {0}({1}, {2})rr �, css �|] \}}d||fVqdS)�%s=%sNr%)rF�k�vr%r%r&� <genexpr>�s�z'_function_called_str.<locals>.<genexpr>)rr�itemsr])r^�args�kwargs� template_str�args_strZ kwargs_strr%r%r&�_function_called_str�srkr%c Cs�t|�}t|t�rtd|t|�f��t�|�s-t�|�s-|r(tj d|dd�||d�St� |�}g}g}g}d}d} |j � �D]A} | j | jurP|�| j�n&| j | jurc|�| j�|�| j�n| j | jurm| j}n | j | jurv| j} | j| jur�|�| j�qAt�|�r�|jg|}t� |j�} tt| j ��} | g|}t|dd�\} }t�}d }t|�D]]\}}|t|�kr�||vr�||||<q�td |t||�t|||�f��|t|�}||vr�||||<q�z||||<Wq�t t!f�y}ztd t||�t|||�f�|�d}~wwt�}t"|�#��D]!\}}||v�r'|||<�q| du�r2|||<�qt$d ||f��| du�rC||d <|du�rT||dd�}||d<|D]}||v�rd|�%|��qVtd|t||�f��|S)aXFilters 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. zHignore_lst must be a list of parameters to ignore %s (type %s) was givenz4Cannot inspect object %s, ignore list will not work.r:)� stacklevel)�*�**NF)rVr zZKeyword-only parameter '%s' was passed as positional parameter for %s: %s was called.z5Wrong number of arguments for %s: %s was called.zAIgnore list for %s() contains an unexpected keyword argument '%s'rnrrmz9Ignore list: argument '%s' is not defined for function %s)&r� isinstancer� ValueError�typerrS� isfunction�warnings�warn� signature� parameters�values�kind�POSITIONAL_OR_KEYWORDrTrU� KEYWORD_ONLY�VAR_POSITIONAL� VAR_KEYWORD�default�empty�__self__�__func__�next�iterr\�dict� enumeraterPr`rk� IndexError�KeyError�sortedrfrK�pop)rZ ignore_lstrgrhr_� arg_names� arg_defaultsZarg_kwonlyargsZ arg_varargsZ arg_varkw�paramZclass_method_sig� self_name�_rUZarg_dictZ arg_position�arg_name�position�eZ varkwargs� arg_value�varargs�itemr%r%r&� filter_args�s�  ���         � ��    ���  ������     ��    ��r�cCs,t|dd�}t|�dkrd|dd�}|S)Nr:)�indenti�z%s...i�)rrP)�arg� formatted_argr%r%r&� _format_argTs  r�c Os�t|�\}}dd�|D�}|r|�|�d�|�}n|}t�}d}|D]}t|�} |dkr1d| } t| �}|�| �q#|�dd�|��D��d�|�}d ||f} || fS) NcSsg|]}|r|�qSr%r%)rF�mr%r%r&rH^rIz$format_signature.<locals>.<listcomp>r?r�Pz %scSs g|] \}}d|t|�f�qS)rb)r�)rFrd�ir%r%r&rHls raz%s(%s))r\rTrrr�rPrRrf) rrgrhrXrU� module_path�arg_strZprevious_lengthr�r�rur%r%r&�format_signature[s$      r��MemorycCs.t|g|�Ri|��\}}dd|||f}|S)zdReturns a nicely formatted statement displaying the function call with the given arguments. z%s [%s] Calling %s... %sZP________________________________________________________________________________)r�)rrgrh� object_namer ru�msgr%r%r&� format_callssr�)TT)r�)�__doc__� collectionsrr rrs� itertoolsr�tokenizerr�loggerrZfull_argspec_fields� namedtupleZfull_argspec_typer'r4r\r`rkr�r�r�r�r�r%r%r%r&�<module>s,   � 9 Z  
Memory