Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/joblib/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/joblib/__pycache__/func_inspect.cpython-35.opt-1.pyc



ש�W&3�@sdZddlmZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZddlm
Z
d	d
�Zdd�Zd
d
dd�Zdd�Zdd�Zdd�Zfe�dd�Zdd�Zddd�ZdS)z>
My own variation on function-specific inspect-like features.
�)�isliceN�)�_basestring)�pformat)�open_py_source)�PY3_OR_LATERcCsGd}y�|j}|j}tjj|�s�djtj|�d�}d}|jd�r�t	j
d|�j�\}}t|�}d|}|||fSt
|��,}|j}tt||dd��}WdQRXdjtj|��||fSWnFt|d�r+t|jj��|d	fSt|�|d
fSYnXdS)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�rrz	<doctest z\<doctest (.*\.rst)\[(.*)\]\>z<doctest %s>�__code__���r
)r	�co_filename�os�path�exists�join�inspectZgetsourcelines�
startswith�re�match�groups�intr�co_firstlineno�listrZgetblock�hasattr�str�__hash__�repr)�funcZsource_file�codeZsource_codeZline_noZsource_file_objZ
first_lineZsource_lines�r�D/opt/alt/python35/lib/python3.5/site-packages/joblib/func_inspect.py�
get_func_codes*		

	##r cCslddl}t|d�r'|j}nddl}|jj}x&d	D]}|j|||��}qFW|S)
z2Windows cannot encode some characters in filename.rN�quote�<�>�!�:�\)r"r#r$r%r&)�urllibrr!Zurllib.parse�parse�replace)�stringr'r!�charrrr�_clean_win_charsMs
r,TcCs-t|d�r|j}nLytj|�}Wn6tk
rft|d�r\|jj}nd}YnX|dkryd}|dkr,ytjjtj	|��}Wnd}YnX|dk	r,|j
tj�}|djd�r�d	|d<d
j
|�}|jd�r|dd�}|d
|}|j
d
�}t|d�rV|j}n!t|d�rq|j}nd}|r�t|d�r�||jkr�|j||k	r�d|}tj|�r�t|d�r�|j}|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__rz<ipython-inputz__ipython-input__�-z.py��.�	func_name�__name__�func_globalsz%s-alias�im_class�ntcSsg|]}t|��qSr)r,)�.0�srrr�
<listcomp>�s	z!get_func_name.<locals>.<listcomp>r
r
���)rr-rZ	getmodule�	TypeErrorr.rr
�abspathZ
getsourcefile�split�seprr�endswithr4r5r6�ismethodr7�append�namer,)r�resolv_aliasZwin_characters�module�filename�partsrD�klassrrr�
get_func_name[sR


	rJcCs�ytj|�SWn�tk
r�tj|�}ddl}d}|jd|�}|d|jd|jd|jd|j	d	gd
ddi�SYnXdS)a>Compatibility function to provide inspect.getfullargspec in Python 2

    This should be rewritten using a backport of Python 3 signature
    once we drop support for Python 2.6. We went for a simpler
    approach at the time of writing because signature uses OrderedDict
    which is not available in Python 2.6.
    rNzAargs varargs varkw defaults kwonlyargs kwonlydefaults annotationsZFullArgSpec�args�varargs�varkw�defaults�
kwonlyargs�kwonlydefaultsZannotations)
r�getfullargspec�AttributeErrorZ
getargspec�collections�
namedtuplerKrL�keywordsrN)r�arg_specrSZtuple_fieldsZ
tuple_typerrrrQ�s
			rQcCs;|dtrdnd�}tj|�}dj||�S)z.Helper function to output a function signatureN��z{0}{1})rrZ
formatargspec�format)�
function_namerVZarg_spec_for_formatZarg_spec_strrrr�_signature_str�sr[cCsQd}t|�dd�}djdd�|j�D��}|j|||�S)z)Helper function to output a function callz
{0}({1}, {2})rz, css%|]\}}d||fVqdS)z%s=%sNr)r9�k�vrrr�	<genexpr>�sz'_function_called_str.<locals>.<genexpr>r
)rr�itemsrY)rZrK�kwargsZtemplate_strZargs_strZ
kwargs_strrrr�_function_called_str�sracs;t|�}t|t�r7td|t|�f��tj|�r�tj|�r�|rttj	d|dd�d|d|iSt
|���j�j}�j
p�f}|t�fdd��jD��}�j}�j}tj|�r|jg|}t|d	d
�\}}	t�}
d}xt|�D]�\}}|t|�kr�|�jkrx|||
|<q3td|t|	��t|	||�f��q:|t|�}
||kr�|j|�|
|<q:y||
|
|<Wq:ttfk
r2td
t|	��t|	||�f��Yq:Xq:Wt�}xht|j��D]T\}}||
krx||
|<qS|dk	r�|||<qStd|	|f��qSW|dk	r�||
d<|dk	r�||dd�}||
d<xI|D]A}||
kr|
j|�q�td|t|	��f��q�W|
S)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.
    zHignore_lst must be a list of parameters to ignore %s (type %s) was givenz4Cannot inspect object %s, ignore list will not work.�
stacklevel��*z**c3s|]}�j|VqdS)N)rP)r9r\)rVrrr^�szfilter_args.<locals>.<genexpr>rEFrzZKeyword-only parameter '%s' was passed as positional parameter for %s:
     %s was called.z5Wrong number of arguments for %s:
     %s was called.NzAIgnore list for %s() contains an unexpected keyword argument '%s'z9Ignore list: argument '%s' is not defined for function %sr
)r�
isinstancer�
ValueError�typerrBZ
isfunction�warnings�warnrQrKrOrN�tuplerLrM�__self__rJ�dict�	enumerate�lenr[ra�pop�
IndexError�KeyError�sortedr_r=)rZ
ignore_lstrKr`Z	arg_namesZarg_defaultsZarg_varargsZ	arg_varkw�_rDZarg_dictZarg_positionZarg_nameZpositionZ	varkwargsZ	arg_valuerL�itemr)rVr�filter_args�sz 				"	




ruc
Os t|�\}}dd�|D�}|rJ|j|�dj|�}n|}t�}d}xu|D]m}t|dd�}t|�dkr�d|dd	�}|d
kr�d|}t|�}|j|�qfW|jdd�|j�D��d
j|�}d||f}	||	fS)NcSsg|]}|r|�qSrr)r9�mrrrr;Bs	z$format_signature.<locals>.<listcomp>r3r�indentrci�z%s...i��Pz
%scSs,g|]"\}}d|t|�f�qS)z%s=%s)r)r9r]�irrrr;Rs	z, z%s(%s))rJrCrrrrn�extendr_)
rrKr`rFrDZmodule_pathZarg_strZprevious_length�arg�	signaturerrr�format_signature?s(
	

 r}ZMemorycCs6t|||�\}}ddd|||f}|S)zi Returns a nicely formatted statement displaying the function
        call with the given arguments.
    z%s
[%s] Calling %s...
%srxrs)r})rrKr`Zobject_namer
r|�msgrrr�format_callYs

r)�__doc__�	itertoolsrrrhrrZ_compatrZloggerrZ_memory_helpersrrr r,rJrQr[rarlrur}rrrrr�<module>s$8E
p