AlkantarClanX12

Your IP : 3.136.236.178


Current Path : /proc/self/root/opt/alt/python35/lib64/python3.5/unittest/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python35/lib64/python3.5/unittest/__pycache__/mock.cpython-35.opt-2.pyc



���]y2�@s�dddddddddd	d
ddf
Zd
ZddlZddlZddlZddlZddlmZddlm	Z	m
Z
dd�ee�D�Ze
fZdejkr�ddlZe
ejjfZdZeZdd�Zdd�ZGdd�de�Zeej�efZdd�Zddd �Zd!d"�Z d#d$�Z!d%d&�Z"d'd(�Z#dd)d*�Z$d+d,�Z%d-d.�Z&Gd/d0�d0e�Z'Gd1d2�d2e�Z(e(�Z)e)j*Z*e)j+Z,e)j-Z.d3d4�Z/d5d6d7d8d9d:d;d<hZ0d=d>�Z1Gd?d@�d@e2�Z3dAdB�Z4GdCdD�dDe�Z5GdEdF�dFe�Z6GdGd	�d	e6�Z7dHdI�Z8GdJdK�dKe6�Z9GdLd�de9e7�Z:dMdN�Z;dOdP�Z<dQdR�Z=GdSdT�dTe�Z>dUdV�Z?e*ddddddWdX�Z@ddddddYdZ�ZAe*dddddd[d�ZBGd\d]�d]e�ZCd^d_�ZDd`da�ZEe@eB_eCeB_FeAeB_GeEeB_HdbeB_IdcZJddZKdejLdfdg�eKjM�D��ZNdejLdhdg�eKjM�D��ZOdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzhZPd{d|�ZQd}d�dejLeJeKeNeOg�jM�D�ZReRePBZSd~dd�d�d�d�d�hZTd�d�d��d�d�d��d�d�d��iZUd�eVd�eVd�eVd�eVd�d�d�dd�dd�dd�d�d�d�d�dd�d�iZWd�d��ZXd�d��ZYd�d��ZZd�eXd�eYd�eZiZ[d�d��Z\Gd�d��d�e�Z]Gd�d
�d
e]e7�Z^Gd�d�de]e:�Z_Gd�d��d�e�Z`Gd�d��d�e�Zaea�Zbd�d��ZcGd�d��d�ed�Zeeed�d�Zfddddd�d�Zgd�d��Zhd�d��ZiGd�d��d�e�Zjeeg�eebjk�fZleebjkjm�fZndaod�d��Zpdd�d�d�ZqGd�d�de:�ZrdS)��Mock�	MagicMock�patch�sentinel�DEFAULT�ANY�call�create_autospec�
FILTER_DIR�NonCallableMock�NonCallableMagicMock�	mock_open�PropertyMockz1.0�N)�
ModuleType)�wraps�partialcCs%h|]}|jd�s|�qS)�_)�
startswith)�.0�name�r�)/opt/alt/python35/lib64/python3.5/mock.py�	<setcomp>#s	r�javaTcCstt|�t�S)N)�
issubclass�typer
)�objrrr�_is_instance_mock2srcCs+t|t�p*t|t�o*t|t�S)N)�
isinstance�BaseExceptionsrr)rrrr�
_is_exception8sr c@seZdZdgZdS)�_slotted�aN)�__name__�
__module__�__qualname__�	__slots__rrrrr!?sr!cCs�t|t�rE|rEy
|j}Wntk
r;dSYnXd}n5t|t�szy
|j}Wntk
rydSYnX|r�t|d�}n|}y|tj|�fSWnt	k
r�dSYnXdS)NT)
rr�__init__�AttributeError�
FunctionTypes�__call__r�inspectZ	signature�
ValueError)�funcZas_instanceZeat_selfZsig_funcrrr�_get_signature_objectKs$

		

	
r.Fcs`t|||���dkr"dS�\}��fdd�}t||�|t|�_dS)Ncs�j||�dS)N)�bind)�
_mock_self�args�kwargs)�sigrr�checksigpsz"_check_signature.<locals>.checksig)r.�_copy_func_detailsr�_mock_check_sig)r-�mock�	skipfirst�instancer4r)r3r�_check_signatureks
r:c#Cs�|j|_|j|_y|j|_Wntk
r<YnXy|j|_Wntk
raYnXy|j|_Wntk
r�YnXy|j|_Wntk
r�YnXdS)N)r#�__doc__�__text_signature__r(r$�__defaults__�__kwdefaults__)r-�funcopyrrrr5vs$



r5cCs3t|t�rdSt|dd�dk	r/dSdS)NTr*F)rr�getattr)rrrr�	_callable�s
rAcCst|�ttfkS)N)r�list�tuple)rrrr�_is_list�srDcCs`t|t�s%t|dd�dk	Sx4|f|jD]"}|jjd�dk	r6dSq6WdS)Nr*TF)rrr@�__mro__�__dict__�get)r�baserrr�_instance_callable�srIcs�t|�sdSt|t�}t|||�}|dkrA|S|\}��fdd�}t||�|j}|j�s�d}d|d|i}d|}	t|	|�||}
t|
|�|
S)Ncs�j||�dS)N)r/)r1r2)r3rrr4�sz _set_signature.<locals>.checksigr?Z
_checksig_r7zYdef %s(*args, **kwargs):
    _checksig_(*args, **kwargs)
    return mock(*args, **kwargs))	rArrr.r5r#�isidentifier�exec�_setup_func)r7�originalr9r8�resultr-r4r�context�srcr?r)r3r�_set_signature�s$
	



rQcs��_t��sdS�fdd�}�fdd�}�fdd�}�fdd�}��fd	d
�}d�_d�_d�_t��_t��_t��_�j	�_	�j
�_
�j�_|�_|�_
|�_|�_|�_��_dS)
Ncs�j||�S)N)�assert_called_with)r1r2)r7rrrR�sz'_setup_func.<locals>.assert_called_withcs�j||�S)N)�assert_called_once_with)r1r2)r7rrrS�sz,_setup_func.<locals>.assert_called_once_withcs�j||�S)N)�assert_has_calls)r1r2)r7rrrT�sz%_setup_func.<locals>.assert_has_callscs�j||�S)N)�assert_any_call)r1r2)r7rrrU�sz$_setup_func.<locals>.assert_any_callcsQt��_t��_�j��j}t|�rM|�k	rM|j�dS)N)�	_CallList�method_calls�
mock_calls�
reset_mock�return_valuer)�ret)r?r7rrrY�s
	z_setup_func.<locals>.reset_mockFr)r7r�called�
call_count�	call_argsrV�call_args_listrWrXrZ�side_effect�_mock_childrenrRrSrTrUrY�_mock_delegate)r?r7rRrSrTrUrYr)r?r7rrL�s.									rLcCsd|dd�|kS)Nz__%s__����r)rrrr�	_is_magic�srec@s(eZdZdd�Zdd�ZdS)�_SentinelObjectcCs
||_dS)N)r)�selfrrrrr'�sz_SentinelObject.__init__cCsd|jS)Nzsentinel.%s)r)rgrrr�__repr__�sz_SentinelObject.__repr__N)r#r$r%r'rhrrrrrf�srfc@s(eZdZdd�Zdd�ZdS)�	_SentinelcCs
i|_dS)N)�
_sentinels)rgrrrr'sz_Sentinel.__init__cCs+|dkrt�|jj|t|��S)N�	__bases__)r(rj�
setdefaultrf)rgrrrr�__getattr__sz_Sentinel.__getattr__N)r#r$r%r'rmrrrrri�sricCs2t|�ttttfkr.t|�|�S|S)N)r�dictrBrC�set)�valuerrr�_copysrqrZ�_mock_return_valuer`�_mock_side_effect�_mock_parent�_mock_new_parent�
_mock_name�_mock_new_namecCsHtj|�d|}||dd�}||dd�}t||�S)NZ_mock_cSs/|j}|dkr"t||�St||�S)N)rbr@)rgr�	_the_namer3rrr�_get"s	
z"_delegating_property.<locals>._getcSs9|j}|dkr%||j|<nt|||�dS)N)rbrF�setattr)rgrprrxr3rrr�_set's	z"_delegating_property.<locals>._set)�_allowed_names�add�property)rrxryr{rrr�_delegating_propertys


rc@s(eZdZdd�Zdd�ZdS)rVcCs�t|t�stj||�St|�}t|�}||krGdSxCtd||d�D]*}||||�}||kr_dSq_WdS)NFr�T)rrB�__contains__�len�range)rgrpZ	len_valueZlen_self�iZsub_listrrrr�4sz_CallList.__contains__cCstjt|��S)N)�pprintZpformatrB)rgrrrrhBsz_CallList.__repr__N)r#r$r%r�rhrrrrrV2srVcCs�t|�sdS|js@|js@|jdk	s@|jdk	rDdS|}x)|dk	ru||kridS|j}qMW|r�||_||_|r�||_||_dS)NFT)rrvrwrtru)�parentrpr�new_name�_parentrrr�_check_and_set_parentFs$
				r�c@s4eZdZdd�Zdd�Zdd�ZdS)�	_MockItercCst|�|_dS)N)�iterr)rgrrrrr'`sz_MockIter.__init__cCs|S)Nr)rgrrr�__iter__bsz_MockIter.__iter__cCs
t|j�S)N)�nextr)rgrrr�__next__dsz_MockIter.__next__N)r#r$r%r'r�r�rrrrr�_sr�c@s(eZdZeZdZdd�ZdS)�BaseNcOsdS)Nr)rgr1r2rrrr'jsz
Base.__init__)r#r$r%rrrrsr'rrrrr�gsr�c
@s�eZdZdd�Zddddddddddddd�Zdd	�Zdd
d�Zdddd
�Zdd�Zdd�Z	dZ
eee	e
�Zedd��Z
ed�Zed�Zed�Zed�Zed�Zdd�Zdd�Zeee�Zddd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Z d2d3�Z!d4d5�Z"d6d7�Z#dd8d9�Z$d:d;�Z%d<d=�Z&dS)>r
cOs4t|j|fd|ji�}tj|�}|S)Nr;)rr#r;�object�__new__)�clsr1�kw�newr9rrrr�rs!zNonCallableMock.__new__N�FcKs2|dkr|}|j}
||
d<||
d<||
d<||
d<|dk	r[|}d}|
dkrs|dk	}
|j|||	|
�i|
d<||
d<d|
d<d	|
d
<d|
d<d|
d
<t�|
d<t�|
d<t�|
d<||
d<|r	|j|�tt|�j||||||�dS)NrtrvrwruTra�_mock_wrapsrbFZ_mock_calledZ_mock_call_argsrZ_mock_call_countZ_mock_call_args_listZ_mock_mock_callsrW�_mock_unsafe)rF�_mock_add_specrV�configure_mock�_safe_superr
r')rg�specrr�spec_setr��_spec_state�	_new_name�_new_parent�_spec_as_instance�	_eat_selfZunsafer2rFrrrr'{s8	














zNonCallableMock.__init__cCs8d|_d|_d|_d|_t|||�dS)Nr�)rtrurvrwrz)rgr7�	attributerrr�attach_mock�s
				zNonCallableMock.attach_mockcCs|j||�dS)N)r�)rgr�r�rrr�
mock_add_spec�szNonCallableMock.mock_add_specc	Cs�d}d}|dk	rwt|�rwt|t�r=|}nt|�}t|||�}|oh|d}t|�}|j}||d<||d<||d<||d<dS)Nr��_spec_class�	_spec_set�_spec_signature�
_mock_methods)rDrr�
_get_classr.�dirrF)	rgr�r�r�r�r�r��resrFrrrr��s		


zNonCallableMock._mock_add_speccCsU|j}|jdk	r$|jj}|tkrQ|jd|dd�}||_|S)Nr�r�z())rrrbrZr�_get_child_mock)rgr[rrrZ__get_return_value�s			z"NonCallableMock.__get_return_valuecCs>|jdk	r||j_n||_t||dd�dS)Nz())rbrZrrr�)rgrprrrZ__set_return_value�s	z"NonCallableMock.__set_return_valuez1The value to be returned when the mock is called.cCs |jdkrt|�S|jS)N)r�r)rgrrr�	__class__�s
zNonCallableMock.__class__r\r]r^r_rXcCst|j}|dkr|jS|j}|dk	rpt|�rpt|t�rpt|�rpt|�}||_|S)N)rbrsr`�callablerr�r )rg�	delegatedZsfrrrZ__get_side_effect�s			z!NonCallableMock.__get_side_effectcCs:t|�}|j}|dkr-||_n	||_dS)N)�	_try_iterrbrsr`)rgrpr�rrrZ__set_side_effects
	z!NonCallableMock.__set_side_effectcCs�|dkrg}t|�|kr(dS|jt|��d|_d|_d|_t�|_t�|_t�|_x6|j	j
�D]%}t|t�r�q�|j
|�q�W|j}t|�r�||k	r�|j
|�dS)NFr)�id�appendr\r^r]rVrXr_rWra�valuesr�
_SpecStaterYrrr)rgZvisitedZchildr[rrrrYs$				zNonCallableMock.reset_mockcKs�x}t|j�ddd��D]]\}}|jd�}|j�}|}x|D]}t||�}qSWt|||�qWdS)N�keycSs|djd�S)Nr�.)�count)�entryrrr�<lambda>6sz0NonCallableMock.configure_mock.<locals>.<lambda>r�)�sorted�items�split�popr@rz)rgr2�arg�valr1�finalrr�rrrr�)s	
zNonCallableMock.configure_mockcCsu|dkrt|��nU|jdk	rX||jksE|tkrptd|��nt|�rpt|��|js�|jd�r�t|��|jj|�}|tkr�t|��n�|dkr.d}|j	dk	r�t
|j	|�}|jd|d|d|d	|d
|�}||j|<nCt|t
�rqt|j|j|j|j|j�}||j|<|S)
Nr�r�zMock object has no attribute %r�assert�assretr�rrr�r�>r�r�)r�r�)r(r��_all_magicsrer�rrarG�_deletedr�r@r�rr�rr�r�r9r�r)rgrrNrrrrrm?s6			
zNonCallableMock.__getattr__c
Cs�|jg}|j}|}d}|dgkr6d}t�}xt|dk	r�|}|j|j|�d}|jdkr�d}|j}t|�|kr�P|jt|��qBWtt|��}|jp�d}t	|�dkr|dd
kr|d7}||d<dj
|�}d}|dkr8d	|}d}	|jdk	rrd
}	|jrbd}	|	|jj
}	dt|�j
||	t|�fS)Nr��()r�r7r��().r�mock.z name=%rz spec=%rz spec_set=%rz<%s%s%s id='%s'>)r�r�)r7r�)rwruror�r�r}rB�reversedrvr��joinr�r�r#r)
rgZ
_name_listr�Zlast�dot�seenZ_firstrZname_stringZspec_stringrrrrhesL			


	zNonCallableMock.__repr__cCs�tstj|�S|jpg}tt|��}t|j�}dd�|D�}dd�|D�}tt	|||t|j
���S)NcSs%g|]}|jd�s|�qS)r)r)r�errr�
<listcomp>�s	z+NonCallableMock.__dir__.<locals>.<listcomp>cSs2g|](}|jd�s(t|�r|�qS)r)rre)rr�rrrr��s	)r	r��__dir__r�r�rrBrFr�rora)rg�extrasZ	from_typeZ	from_dictrrrr��s
zNonCallableMock.__dir__cs�|tkrtj�||�S�jrh�jdk	rh|�jkrh|�jkrhtd|��n|tkr�d|}t|��n�|tkrI�jdk	r�|�jkr�td|��t	|�st
t��|t||��|���fdd�}q�t
�|d|�t
t��||�|�j|<n;|dkrb|�_dSt
�|||�r�|�j|<tj�||�S)Nz!Mock object has no attribute '%s'z.Attempting to set unsupported magic method %r.cs��||�S)Nr)r1r�)rMrgrrr��sz-NonCallableMock.__setattr__.<locals>.<lambda>r�)r|r��__setattr__r�r�rFr(�_unsupported_magicsr�rrzr�_get_methodr�rar�)rgrrp�msgr)rMrgrr��s2
	
zNonCallableMock.__setattr__cCs�|tkrG|t|�jkrGtt|�|�||jkrGdS||jkrftj||�|jj|t�}|t	kr�t
|��|tk	r�|j|=t	|j|<dS)N)r�rrF�delattrr��__delattr__rarG�_missingr�r()rgrrrrrr��s!
zNonCallableMock.__delattr__cCs|jpd}t|||�S)Nr7)rv�_format_call_signature)rgr1r2rrrr�_format_mock_call_signature�sz+NonCallableMock._format_mock_call_signaturecCs`d}|j||�}|j}t|�dkrC|dd�}|j|�}|||fS)Nz!Expected call: %s
Actual call: %s�r�)r�r^r�)rgr1r2�message�expected_stringr^Z
actual_stringrrr�_format_mock_failure_message�s	z,NonCallableMock._format_mock_failure_messagecCs�|j}|dk	r�t|�dkr<d}|\}}n|\}}}y||j||�fSWq�tk
r�}z|jd�SWYdd}~Xq�Xn|SdS)Nrcr�)r�r�r/�	TypeError�with_traceback)rg�_callr3rr1r2r�rrr�
_call_matcher�s	#zNonCallableMock._call_matchercCsA|}|jdkr=d|jp$d|jf}t|��dS)Nrz7Expected '%s' to not have been called. Called %s times.r7)r]rv�AssertionError)r0rgr�rrr�assert_not_calleds
z!NonCallableMock.assert_not_calledcs�|��jdkr:�j���}td|f�����fdd�}�j��f�}�j�j�}||kr�t|t�r�|nd}t|��|�dS)NzExpected call: %s
Not calledcs�j���}|S)N)r�)r�)r1r2rgrr�_error_messagesz:NonCallableMock.assert_called_with.<locals>._error_message)r^r�r�r�r�	Exception)r0r1r2�expectedr��actual�causer)r1r2rgrrR	sz"NonCallableMock.assert_called_withcOsM|}|jdks=d|jp$d|jf}t|��|j||�S)Nr�z1Expected '%s' to be called once. Called %s times.r7)r]rvr�rR)r0r1r2rgr�rrrrSsz'NonCallableMock.assert_called_once_withcs�fdd�|D�}t|t�r.|nd}t�fdd��jD��}|s�||kr�td|�jf�|�dSt|�}g}xA|D]9}y|j|�Wq�tk
r�|j|�Yq�Xq�W|rtdt	|�f�|�dS)Ncsg|]}�j|��qSr)r�)r�c)rgrrr�2s	z4NonCallableMock.assert_has_calls.<locals>.<listcomp>c3s|]}�j|�VqdS)N)r�)rr�)rgrr�	<genexpr>4sz3NonCallableMock.assert_has_calls.<locals>.<genexpr>z(Calls not found.
Expected: %r
Actual: %rz%r not all found in call list)
rr�rVrXr�rB�remover,r�rC)rgZcallsZ	any_orderr�r�Z	all_callsZ	not_foundZkallr)rgrrT(s*
"

z NonCallableMock.assert_has_callscs��j||f�}�fdd��jD�}||kr}t|t�rR|nd}�j||�}td|�|�dS)Ncsg|]}�j|��qSr)r�)rr�)rgrrr�Rs	z3NonCallableMock.assert_any_call.<locals>.<listcomp>z%s call not found)r�r_rr�r�r�)rgr1r2r�r�r�r�r)rgrrUKs
zNonCallableMock.assert_any_callcKsbt|�}t|t�sKt|t�r3t}qXt|t�rXt}n
|jd}||�S)Nr�)rr�
CallableMixinrrr
rrE)rgr��_type�klassrrrr�[s		
zNonCallableMock._get_child_mock)'r#r$r%r�r'r�r�r�Z"_NonCallableMock__get_return_valueZ"_NonCallableMock__set_return_valueZ"_NonCallableMock__return_value_docr~rZr�rr\r]r^r_rXZ!_NonCallableMock__get_side_effectZ!_NonCallableMock__set_side_effectr`rYr�rmrhr�r�r�r�r�r�r�rRrSrTrUr�rrrrr
osL
)
	
		&2"
	#cCs[|dkr|St|�r |St|�r0|Syt|�SWntk
rV|SYnXdS)N)r rAr�r�)rrrrr�os
r�c@s^eZdZddeddddddddd�
Zdd�Zdd�Zd	d
�ZdS)r�Nr�c
KsH||jd<tt|�j|||||||	|
|�||_dS)Nrr)rFr�r�r'r`)rgr�r`rZrrr�r�r�r�r�r2rrrr'�s

zCallableMixin.__init__cOsdS)Nr)rgr1r2rrrr6�szCallableMixin._mock_check_sigcOs |j||�|j||�S)N)r6�
_mock_call)r0r1r2rrrr*�szCallableMixin.__call__cOs�|}d|_|jd7_|j}|j}t||fdd�}||_|jj|�|jjtd||f��t	�}|dk}|j
dk	}	|j}
x|dk	r�t|||f�}|jrd}|r�d}d}|jdkrd}|j||}|	r~||
kr3|}
nt|
||f�}
|jj|
�|j
dk	}	|	r~|jd|
}
|jj|�|j}t
|�}||kr�P|j|�q�Wt}|j}|dk	r@t|�r�|�t|�s1t|�}t|�r|�|tkr-|j}|S|||�}|jdk	rn|jtkrn|j||�S|tkr�|j}|S)NTr��twor�z()r�F)r\r]rwru�_Callr^r_r�rXrortrvrWr�r}rr`r rAr�rZr�rr)r0r1r2rgr�r�r�r�Z
skip_next_dotZdo_method_callsrZthis_mock_callr�Zthis_method_callZ_new_parent_id�ret_valZeffectrNrrrr��sp												zCallableMixin._mock_call)r#r$r%rr'r6r*r�rrrrr�s	r�c@seZdZdS)rN)r#r$r%rrrrr�s1cCsAyt||�SWn)tk
r<t|�t||�SYnXdS)N)r@r(�
__import__)�thing�comp�import_pathrrr�_dot_lookups


r�cCs_|jd�}|jd�}t|�}x.|D]&}|d|7}t|||�}q1W|S)Nr�rz.%s)r�r�r�r�)�targetZ
componentsr�r�r�rrr�	_importer!s
r�cCs
t|d�S)N�is_local)�hasattr)�patcherrrr�_is_started,sr�c@s�eZdZdZgZdd�Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�ZdS)�_patchNc

Cs�|dk	r<|tk	r$td��|dk	r<td��||_||_||_||_||_||_d|_||_	||_
|	|_g|_dS)Nz,Cannot use 'new' and 'new_callable' togetherz1Cannot use 'autospec' and 'new_callable' togetherF)
rr,�getterr�r��new_callabler��createZ	has_localr��autospecr2�additional_patchers)
rgr�r�r�r�rr�rr�r2rrrr'6s$												z_patch.__init__c
Csht|j|j|j|j|j|j|j|j|j	�	}|j
|_
dd�|jD�|_|S)NcSsg|]}|j��qSr)�copy)r�prrrr�Ys	z_patch.copy.<locals>.<listcomp>)r�r�r�r�r�rr�rr�r2�attribute_namer)rgr�rrrrQsz_patch.copycCs)t|t�r|j|�S|j|�S)N)rr�decorate_class�decorate_callable)rgr-rrrr*^s
z_patch.__call__cCssxlt|�D]^}|jtj�s(q
t||�}t|d�sIq
|j�}t||||��q
W|S)Nr*)r�rr�TEST_PREFIXr@r�rrz)rgr��attr�
attr_valuer�rrrrdsz_patch.decorate_classcsTt�d�r#�jj|��St����fdd���|g�_�S)N�	patchingscs
g}g}t�}z�y�xe�jD]Z}|j�}|j|�|jdk	rc|j|�q%|jtkr%|j|�q%W|t|�7}�||�SWn<||kr�t|�r�|j|�t	j
�}�YnXWdx!t|�D]}|j|�q�WXdS)N)
rCr�	__enter__r�r�updater�rr��sys�exc_infor��__exit__)r1Zkeywargs�
extra_argsZentered_patchersr�patchingr�)r-�patchedrrrws*	

z)_patch.decorate_callable.<locals>.patched)r�rr�r)rgr-r)r-rrrrs!z_patch.decorate_callablecCs�|j�}|j}t}d}y|j|}Wn*ttfk
r^t||t�}YnXd}|tkr�t|t	�r�d|_
|j
r�|tkr�td||f��||fS)NFTz!%s does not have the attribute %r)r�r�rrFr(�KeyErrorr@�	_builtinsrrr)rgr�rrM�localrrr�get_original�s		z_patch.get_originalcCsP|j|j|j}}}|j|j}}|j}|j�|_|dkrZd}|dkrld}|dkr~d}|dk	r�|dk	r�td��|dk	s�|dk	r�|dkr�td��|j	�\}}|t
kr |dkr d}	|dkr/|}|dkrh|}d}n9|dk	rV|dkrh|}d}n|dkrh|}|dk	s�|dk	r�|t
kr�td��t|t�r�d}	t
}
i}|dk	r�|}
nd|dk	s�|dk	r2|}|dk	r�|}t|�rd|k}
n
t|�}
|
r2t}
|dk	rH||d<|dk	r^||d<t|
t�r�t|
t�r�|jr�|j|d	<|j|�|
|�}|	r�t|�r�|}|dk	r�|}t|�r�t|�r�t}
|jd	�|
d
|dd|�|_n�|dk	r�|t
k	rDtd
��|t
kr\td��t|�}|dkrz|}t|d|d|j|�}n|r�td��|}||_||_t|j|j|�|jdk	rLi}|jt
kr|||j<x9|jD].}|j �}|jt
kr|j|�qW|S|S)NFzCan't specify spec and autospecTz6Can't provide explicit spec_set *and* spec or autospecz!Can't use 'spec' with create=Truer*r�r�rr�r�z()zBautospec creates the mock for you. Can't specify autospec and new.z%Can't use 'autospec' with create=True�_namez.Can't pass kwargs to a mock we aren't creating)TN)!r�r�r�rr2r�r�r�r�rrrrrrDr�rrr
r�r
rrIr�rZ�boolr�
temp_originalr�rzrrr)rgr�r�r�rr2r�rMrZinherit�Klass�_kwargsZ	this_specZnot_callableZnew_attrrrr�rrrr�s�				







			
z_patch.__enter__cGs�t|�std��|jrL|jtk	rLt|j|j|j�n[t|j|j�|j	r�t
|j|j�s�|jdkr�t|j|j|j�|`|`|`x0t|j�D]}t|�r�|j
|�q�WdS)Nz stop called on unstarted patcherr;r$r=�__annotations__r>)r;r$r=rr>)r��RuntimeErrorr�rrrzr�r�r�rr�r�rr)rgrr�rrrr0s  	z_patch.__exit__cCs |j�}|jj|�|S)N)r�_active_patchesr�)rgrNrrr�startHsz_patch.startcCs3y|jj|�Wntk
r(YnX|j�S)N)rr�r,r)rgrrr�stopOs

z_patch.stop)r#r$r%rrr'rr*rrrrrr r!rrrrr�1s
(~r�csfy�jdd�\�}Wn+ttfk
rItd�f��YnX�fdd�}||fS)Nr�r�z.Need a valid target to patch. You supplied: %rcs
t��S)N)r�r)r�rrr�asz_get_target.<locals>.<lambda>)�rsplitr�r,)r�r�r�r)r�r�_get_target[sr#c

s4�fdd�}	t|	||||||||�	S)Ncs�S)Nrr)r�rrr�wsz_patch_object.<locals>.<lambda>)r�)
r�r�r�r�rr�rr�r2r�r)r�r�
_patch_objectesr$c
s�t��tkr'�fdd�}n�fdd�}|sKtd��t|j��}|d\}	}
t||	|
|||||i�	}|	|_x[|dd�D]I\}	}
t||	|
|||||i�	}|	|_|jj|�q�W|S)Ncs
t��S)N)r�r)r�rrr��sz!_patch_multiple.<locals>.<lambda>cs�S)Nrr)r�rrr��sz=Must supply at least one keyword argument with patch.multiplerr�)	r�strr,rBr�r�rrr�)
r�r�rr�rr�r2r�r�r�r�r�Zthis_patcherr)r�r�_patch_multiple~s&			r&c

Ks4t|�\}}	t||	|||||||�	S)N)r#r�)
r�r�r�rr�rr�r2r�r�rrrr�sEc@sveZdZfddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	eZ
e	ZdS)�_patch_dictFcKsYt|t�rt|�}||_t|�|_|jj|�||_d|_dS)N)	rr%r��in_dictrnr�r
�clear�	_original)rgr(r�r)r2rrrr's		z_patch_dict.__init__csAt�t�r�j��St����fdd��}|S)Nc
s-�j�z�||�SWd�j�XdS)N)r'�
_unpatch_dict)r1r�)�frgrr�_inner&s
z$_patch_dict.__call__.<locals>._inner)rrrr)rgr,r-r)r,rgrr*#s
!z_patch_dict.__call__cCs�x{t|�D]m}t||�}|jtj�r
t|d�r
t|j|j|j	�}||�}t
|||�q
W|S)Nr*)r�r@rrrr�r'r(r�r)rz)rgr�r	r
Z	decoratorZ	decoratedrrrr1sz_patch_dict.decorate_classcCs|j�dS)N)r')rgrrrr<sz_patch_dict.__enter__cCs�|j}|j}|j}y|j�}Wn7tk
rdi}x|D]}||||<qHWYnX||_|r~t|�y|j|�Wn1tk
r�x|D]}||||<q�WYnXdS)N)r�r(r)rr(r*�_clear_dictr
)rgr�r(r)rMr�rrrr'As"			

	


z_patch_dict._patch_dictcCse|j}|j}t|�y|j|�Wn1tk
r`x|D]}||||<qDWYnXdS)N)r(r*r.r
r()rgr(rMr�rrrr+[s		


z_patch_dict._unpatch_dictcGs|j�dS)NF)r+)rgr1rrrrhs
z_patch_dict.__exit__N)r#r$r%r'r*rrr'r+rr r!rrrrr'�s
r'cCsKy|j�Wn6tk
rFt|�}x|D]
}||=q1WYnXdS)N)r)r(rB)r(�keysr�rrrr.qs

r.cCs(x!ttj�D]}|j�qWdS)N)r�r�rr!)rrrr�_patch_stopallzsr0Ztestz�lt le gt ge eq ne getitem setitem delitem len contains iter hash str sizeof enter exit divmod rdivmod neg pos abs invert complex int float index trunc floor ceil bool next zHadd sub mul matmul div floordiv mod lshift rshift and xor or pow truediv� ccs|]}d|VqdS)zi%sNr)r�nrrrr��sr�ccs|]}d|VqdS)zr%sNr)rr2rrrr��s�__get__�__set__�
__delete__�__reversed__�__missing__�
__reduce__�
__reduce_ex__�__getinitargs__�__getnewargs__�__getstate__�__setstate__�
__getformat__�
__setformat__rhr��__subclasses__�
__format__�__getnewargs_ex__cs�fdd�}||_|S)Ncs�|||�S)Nr)rgr1r�)r-rr�method�sz_get_method.<locals>.method)r#)rr-rCr)r-rr��s	r�cCsh|]}d|�qS)z__%s__r)rrCrrrr�s	rmr�r'r�Z__prepare____instancecheck__�__subclasscheck__�__del__�__hash__cCs
tj|�S)N)r�rF)rgrrrr��sr��__str__cCs
tj|�S)N)r�rG)rgrrrr��s�
__sizeof__cCs
tj|�S)N)r�rH)rgrrrr��s�__lt__�__gt__�__le__�__ge__�__int__r�r��__len__r�__complex__y�?�	__float__g�?�__bool__�	__index__cs�fdd�}|S)Ncs0�jj}|tk	r|S�|kr,dStS)NT)�__eq__rrr�NotImplemented)�otherr�)rgrrrS�sz_get_eq.<locals>.__eq__r)rgrSr)rgr�_get_eq�srVcs�fdd�}|S)Ncs*�jjtk	rtS�|kr&dStS)NF)�__ne__rrrrT)rU)rgrrrW�s
z_get_ne.<locals>.__ne__r)rgrWr)rgr�_get_ne�srXcs�fdd�}|S)Ncs,�jj}|tkr"tg�St|�S)N)r�rrrr�)r�)rgrrr��s
z_get_iter.<locals>.__iter__r)rgr�r)rgr�	_get_iter�srYrSrWr�cCs�tj|t�}|tk	r+||_dStj|�}|dk	r�y||�}Wntk
rvt|�}YnX||_dStj|�}|dk	r�||�|_dS)N)�_return_valuesrGrrZ�_calculate_return_valuer(�_side_effect_methodsr`)r7rCrZfixedZreturn_calulatorrZZ
side_effectorrrr�_set_return_value�s	
	r]c@s(eZdZdd�Zdd�ZdS)�
MagicMixincOs1|j�tt|�j||�|j�dS)N)�_mock_set_magicsr�r^r')rgr1r�rrrr's
zMagicMixin.__init__cCs�t}t|dd�dk	rvtj|j�}t�}t|}x0|D](}|t|�jkrJt||�qJW|tt|�j�}t|�}x'|D]}t||t	||��q�WdS)Nr�)
�_magicsr@�intersectionr�rorrFr�rz�
MagicProxy)rgZthese_magicsZ
remove_magicsr�r�rrrr_s	


zMagicMixin._mock_set_magicsN)r#r$r%r'r_rrrrr^sr^c@seZdZddd�ZdS)rFcCs|j||�|j�dS)N)r�r_)rgr�r�rrrr�/sz"NonCallableMagicMock.mock_add_specN)r#r$r%r�rrrrr-sc@seZdZddd�ZdS)rFcCs|j||�|j�dS)N)r�r_)rgr�r�rrrr�EszMagicMock.mock_add_specN)r#r$r%r�rrrrr:sc@sCeZdZdd�Zdd�Zdd�Zddd	�ZdS)
rbcCs||_||_dS)N)rr�)rgrr�rrrr'Qs	zMagicProxy.__init__cOs|j�}|||�S)N)�create_mock)rgr1r2�mrrrr*UszMagicProxy.__call__cCsT|j}|j}|jd|d|d|�}t|||�t|||�|S)Nrr�r�)rr�r�rzr])rgr�r�rdrrrrcYs			zMagicProxy.create_mockNcCs
|j�S)N)rc)rgrr�rrrr3bszMagicProxy.__get__)r#r$r%r'r*rcr3rrrrrbPs	rbc@s4eZdZdd�Zdd�Zdd�ZdS)�_ANYcCsdS)NTr)rgrUrrrrSjsz_ANY.__eq__cCsdS)NFr)rgrUrrrrWmsz_ANY.__ne__cCsdS)Nz<ANY>r)rgrrrrhpsz
_ANY.__repr__N)r#r$r%rSrWrhrrrrregsrecCs�d|}d}djdd�|D��}djdd�t|j��D��}|r`|}|r�|rv|d7}||7}||S)Nz%s(%%s)r�z, cSsg|]}t|��qSr)�repr)rr�rrrr�zs	z*_format_call_signature.<locals>.<listcomp>cSs&g|]\}}d||f�qS)z%s=%rr)rr�rprrrr�|s	)r�r�r�)rr1r2r�Zformatted_args�args_stringZ
kwargs_stringrrrr�ws
"

r�c@s�eZdZfdddddd�Zfdddddd�Zd	d
�ZejZdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)r�r�NFTcCsf}i}t|�}|dkr6|\}}}n�|dkr�|\}	}
t|	t�r�|	}t|
t�r{|
}q�|
}q�|	|
}}nK|dkr�|\}t|t�r�|}nt|t�r�|}n|}|r�tj|||f�Stj||||f�S)Nr�rcr�)r�rr%rCr�)r�rprr�r��	from_kallr1r2�_len�first�secondrrrr��s.					z
_Call.__new__cCs||_||_||_dS)N)rr�rh)rgrprr�r�rhrrrr'�s		z_Call.__init__cCs�|tkrdSyt|�}Wntk
r8dSYnXd}t|�dkr`|\}}n|\}}}d}|dkr�fi}}n�|dkr�|\}}}n�|dkr|\}	t|	t�r�|	}i}q�t|	t�r|	}fi}}q�f}|	}np|dkr�|\}
}t|
t�rr|
}t|t�rb|i}}qf|}}q�|
|}}ndS|r�||kr�dS||f||fkS)NTFr�rcrr�r�)rr�r�rrCr%)rgrUZ	len_otherZ	self_nameZ	self_argsZself_kwargsZ
other_nameZ
other_argsZother_kwargsrprjrkrrrrS�sJ
				z_Call.__eq__cOsW|jdkr(td||fdd�S|jd}t|j||fd|d|�S)Nr�rz()r�)rr�)rgr1r2rrrrr*�s
z_Call.__call__cCsN|jdkr"td|dd�Sd|j|f}td|d|dd�S)NrrhFz%s.%sr�)rr�)rgr	rrrrrmsz_Call.__getattr__cOs|jd�||�S)Nr�)rm)rgr1r2rrrr�sz_Call.countcOs|jd�||�S)N�index)rm)rgr1r2rrrrlsz_Call.indexcCs�|js5|jpd}|jd�r1d|}|St|�dkr\d}|\}}nD|\}}}|szd}n&|jd�s�d|}n
d|}t|||�S)Nrz()zcall%srczcall.%s)rhrrr�r�)rgrr1r2rrrrhs	
	

z_Call.__repr__cCsNg}|}x/|dk	r=|jr1|j|�|j}qWtt|��S)N)rhr�r�rVr�)rg�valsr�rrr�	call_list#s	

z_Call.call_list)r#r$r%r�r'rSr�rWr*rmr�rlrhrnrrrrr��s3	r�rhcKs�t|�rt|�}t|t�}d|i}|rHd|i}n|dkrZi}|rp|rpd|d<|j|�t}tj|�r�i}n4t|�s�t}n|r�|r�t	|�r�t}|j
d|�}|}	|dkr�d}	|d|d|d	|	d||�}
t|t�r>t|
|�}
nt
||
||�|dk	rq|rq|
|j|<|r�|r�d
|kr�t||dddd
d|
�|
_x@t|�D]2}t|�r�q�yt||�}Wntk
r�w�YnXd|i}|rd|i}t|t�sPt|||
||�}
|
|
j|<n~|
}t|t�rn|
j}t|||�}||d<td|d|d	|d||�}
|
|
j|<t
||
d|�t|
t�r�t|
||
�q�W|
S)Nr�r�Tr�rr�r�r�r�rZr9rz()r�r�r8)rDrrr
rr+ZisdatadescriptorrArrIr�r)rQr:rarrZr�rer@r(r�r7�
_must_skiprz)r�r�r9r�rr2�is_typerrr�r7r�rMr�r�r8rrrr4st

		

	
	
cCs�t|t�s4|t|di�kr+dS|j}xq|jD]f}|jj|t�}|tkrhq>t|tt	f�r�dStt|dd�t
�r�|SdSq>W|S)NrFFr3)rrr@r�rErFrGr�staticmethod�classmethod�MethodWrapperTypes)r�r�rpr�rNrrrro�s	rocCs.y|jSWntk
r)t|�SYnXdS)N)r�r(r)rrrrr��s
r�c@s+eZdZddddddd�ZdS)r�FNcCs:||_||_||_||_||_||_dS)N)r��idsr�r�r9r)rgr�r�r�rrtr9rrrr'�s					z_SpecState.__init__)r#r$r%r'rrrrr��sr�c#s�t|t�rdnd��fdd�|j��D�}|d�kr`|dd�}n|ddd	�|d
<x|D]}|VqWdS)Ns
�
csg|]}|��qSrr)r�l)�seprrr��s	z&_iterate_read_data.<locals>.<listcomp>r����rxrxrxrx)r�bytesr�)�	read_dataZdata_as_list�liner)rwr�_iterate_read_data�s"
r|r�cst��fdd�}���fdd�}���fdd��tdkr�ddl}ttt|j��jtt|j����a|dkr�tdd	d
t	�}td
t����j
_t��dg�d�j
_d�j_d�j_d�j_|�j_���d<�d�j_|�j_����fdd
�}||_�|_|S)Ncs*�jjdk	r�jjSt�d�S)Nr)�	readlinesrZrB)r1r2)�_state�handlerr�_readlines_side_effect	s
z)mock_open.<locals>._readlines_side_effectcs6�jjdk	r�jjSt���j�d�S)Nr)�readrZrr�)r1r2)r~rrzrr�_read_side_effect	s
z$mock_open.<locals>._read_side_effectc3sW�jjdk	r$x�jjVqWx�dD]}|Vq/Wxt���VqAWdS)Nr)�readlinerZr)r{)r~rrzrr�_readline_side_effect	s	z(mock_open.<locals>._readline_side_effectrr�openr�r�csGt���d<�jj�dkrC���d<�d�j_tS)Nrr�)r|r�r`r)r1r2)r�r~rrzrr�
reset_data7	s

zmock_open.<locals>.reset_data)�	file_spec�_iorBror��
TextIOWrapper�union�BytesIOrr�rrZr|�writer�r�r}r`)r7rzr�r�r�r�r)r�r~rrzrr	s.3
		c@s4eZdZdd�Zdd�Zdd�ZdS)r
cKs
t|�S)N)r)rgr2rrrr�M	szPropertyMock._get_child_mockcCs|�S)Nr)rgrZobj_typerrrr3P	szPropertyMock.__get__cCs||�dS)Nr)rgrr�rrrr4R	szPropertyMock.__set__N)r#r$r%r�r3r4rrrrr
D	s	)s�__all__�__version__r+r�r�builtins�typesr�	functoolsrrr�r�
BaseExceptionr�platformr�langZ	Throwabler	�superr�rr r�r!rr"r~ZDescriptorTypesr.r:r5rArDrIrQrLrerfrirrZMISSINGr�ZDELETEDr�rqr|rrBrVr�r�r�r
r�r�rr�r�r�r�r#r$r&rr'r.r0rnZmultipleZstopallrZ
magic_methodsZnumericsr�r�Zinplace�rightZ
_non_defaultsr�r`r�r�r[rTrZrVrXrYr\r]r^rrrbrerr�rCr�rrror�r�rSr)r3rsr�r|rr
rrrr�<module>s			 +							��e5�+		1	Jv						""		%
		
	
	�	w	D