B
    &d                 @   s   d Z ddlZejd dkZyddlmZmZ W n$ ek
rR   ddlmZmZ Y nX erfddl	m
Z
 nddl	m
Z dd Z
d	d
 ZdS )z9
Created on Mon Jan 13 18:17:15 2014

@author: takluyver
    N   )	signature	Parameter   )wrapsc                s    fdd}|S )Nc                s   t  |   | _| S )N)_wraps__wrapped__)func)f ^/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/backcall/backcall.pydec   s    zwraps.<locals>.decr   )r
   r   r   )r
   r   r      s    r   c                s   t | }g g  }x^|j D ]P\}}|jtjtjfkr@td|jtj	k	sX|jtj
krd|| q| qW t|  fdd}|| _| S )aJ  Decorator to process a callback prototype.
    
    A callback prototype is a function whose signature includes all the values
    that will be passed by the callback API in question.
    
    The original function will be returned, with a ``prototype.adapt`` attribute
    which can be used to prepare third party callbacks.
    z**args/**kwargs not supported in prototypesc                sf  t  }y|j  S  tk
r,   Y nX dd } g }x|j D ]\}}|jtjkrt	|dkr~|
d n
|| qR|jtjkr|jtjk	r|kr
| n"t	|dkr|
d n
|| qR|jtjkrg }qR|jtjkr|kr
| n
|| qRi qRW |r:td |t	t	| t  fdd}|S )z.Introspect and prepare a third party callback.Nr   z)Function {!r} had unmatched arguments: {}c                 s.   | d } xD ]}| | qW  | |S )z@Wrapper for third party callbacks that discards excess argumentsN)pop)argskwargsname)callbackn_positionalunmatched_kwr   r   adapted_   s    
z2callback_prototype.<locals>.adapt.<locals>.adapted)r   bind	TypeErrorcopy
parametersitemskindr   POSITIONAL_ONLYlenr   appendPOSITIONAL_OR_KEYWORDdefaultemptyVAR_POSITIONALKEYWORD_ONLYformatr   )r   sigZunmatched_posZunrecognisedr   paramr   )r   
positional)r   r   r   r   adapt1   s@    
z!callback_prototype.<locals>.adapt)r   r   r   r   r   r"   VAR_KEYWORDr   r    r!   r#   r   dictfromkeysr(   )Z	prototypeZprotosigkeywordr   r&   r(   r   )r   r'   r   callback_prototype   s    	

;r-   )__doc__sysversion_infoPY3inspectr   r   ImportErrorZ_signatures	functoolsr   r   r-   r   r   r   r   <module>   s   