AlkantarClanX12

Your IP : 18.225.95.229


Current Path : /proc/self/root/usr/lib64/python3.6/unittest/__pycache__/
Upload File :
Current File : //proc/self/root/usr/lib64/python3.6/unittest/__pycache__/mock.cpython-36.opt-2.pyc

3


 \�7�@sFd�Zd
ZddlZddlZddlZddlZddlmZddlm	Z	m
Z
dd�ee�D�Ze
fZdejkrzddlZe
ejjfZdZeZdd�Zdd�Zdd�Zd�dd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd�d'd(�Zd)d*�Zd+d,�Z Gd-d.�d.e!�Z"Gd/d0�d0e!�Z#e#�Z$e$j%Z%e$j&Z'e$j(Z)d1d2�Z*d3d4d5d6d7d8d9d:hZ+d;d<�Z,Gd=d>�d>e-�Z.d?d@�Z/GdAdB�dBe!�Z0GdCdD�dDe!�Z1GdEd	�d	e1�Z2dFdG�Z3GdHdI�dIe1�Z4GdJd�de4e2�Z5dKdL�Z6dMdN�Z7dOdP�Z8GdQdR�dRe!�Z9dSdT�Z:e%dddddfdUdV�Z;d�dWdX�Z<e%dddddfdYd�Z=GdZd[�d[e!�Z>d\d]�Z?d^d_�Z@e;e=_!e>e=_Ae<e=_Be@e=_Cd`e=_DdaZEdbZFdcjGddde�eFjH�D��ZIdcjGdfde�eFjH�D��ZJdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxhZKdydz�ZLd{d�dcjGeEeFeIeJg�jH�D�ZMeMeKBZNd|d}d~dd�d�d�d�hZOd�d��d�d��d�d��d��ZPeQeQeQeQd�dddd�d�dd�d��ZRd�d��ZSd�d��ZTd�d��ZUeSeTeUd��ZVd�d��ZWGd�d��d�e!�ZXGd�d
�d
eXe2�ZYGd�d�deXe5�ZZGd�d��d�e!�Z[Gd�d��d�e!�Z\e\�Z]d�d��Z^Gd�d��d�e_�Z`e`dd��Zad�d�d�Zbd�d��Zcd�d��ZdGd�d��d�e!�Zeefeb�efe]jg�fZhefe]jgji�fZjdakd�d��Zld�d�d�ZmGd�d�de5�ZndS)��Mock�	MagicMock�patch�sentinel�DEFAULT�ANY�call�create_autospec�
FILTER_DIR�NonCallableMock�NonCallableMagicMock�	mock_open�PropertyMockz1.0�N)�
ModuleType)�wraps�partialcCsh|]}|jd�s|�qS)�_)�
startswith)�.0�name�r�%/usr/lib64/python3.6/unittest/mock.py�	<setcomp>#sr�javaTcCstt|�t�S)N)�
issubclass�typer
)�objrrr�_is_instance_mock2srcCst|t�pt|t�ot|t�S)N)�
isinstance�BaseExceptionsrr)rrrr�
_is_exception8s
r cCs�t|t�r6|r6y
|j}Wntk
r.dSXd}n*t|t�s`y
|j}Wntk
r^dSX|rpt|d�}n|}y|tj|�fSt	k
r�dSXdS)NT)
rr�__init__�AttributeError�
FunctionTypes�__call__r�inspectZ	signature�
ValueError)�funcZas_instanceZeat_selfZsig_funcrrr�_get_signature_object?s$


r(FcsDt|||���dkrdS�\}��fdd�}t||�|t|�_dS)Ncs�j||�dS)N)�bind)�
_mock_self�args�kwargs)�sigrr�checksigdsz"_check_signature.<locals>.checksig)r(�_copy_func_detailsr�_mock_check_sig)r'�mock�	skipfirst�instancer.r)r-r�_check_signature_s
r4c#Cs�|j|_|j|_y|j|_Wntk
r0YnXy|j|_Wntk
rRYnXy|j|_Wntk
rtYnXy|j|_Wntk
r�YnXdS)N)�__name__�__doc__�__text_signature__r"�
__module__�__defaults__�__kwdefaults__)r'�funcopyrrrr/js$r/cCs&t|t�rdSt|dd�dk	r"dSdS)NTr$F)rr�getattr)rrrr�	_callable�s

r=cCst|�ttfkS)N)r�list�tuple)rrrr�_is_list�sr@cCsHt|t�st|dd�dk	Sx(|f|jD]}|jjd�dk	r(dSq(WdS)Nr$TF)rrr<�__mro__�__dict__�get)r�baserrr�_instance_callable�s
rEcs�t|�sdSt|t�}t|||�}|dkr.|S|\}��fdd�}t||�|j}|j�s^d}||d�}d|}	t|	|�||}
t|
|�|
S)Ncs�j||�dS)N)r))r+r,)r-rrr.�sz _set_signature.<locals>.checksigr;)Z
_checksig_r1zYdef %s(*args, **kwargs):
    _checksig_(*args, **kwargs)
    return mock(*args, **kwargs))	r=rrr(r/r5�isidentifier�exec�_setup_func)r1�originalr3r2�resultr'r.r�context�srcr;r)r-r�_set_signature�s$




rMc
s���_t��sdS�fdd�}�fdd�}�fdd�}�fdd�}�fd	d
�}�fdd�}�fd
d�}��fdd�}	d�_d�_d�_t��_t��_t��_�j	�_	�j
�_
�j�_|�_|�_
|�_|�_|	�_|�_|�_|�_��_dS)Ncs�j||�S)N)�assert_called_with)r+r,)r1rrrN�sz'_setup_func.<locals>.assert_called_withcs�j||�S)N)�
assert_called)r+r,)r1rrrO�sz"_setup_func.<locals>.assert_calledcs�j||�S)N)�assert_not_called)r+r,)r1rrrP�sz&_setup_func.<locals>.assert_not_calledcs�j||�S)N)�assert_called_once)r+r,)r1rrrQ�sz'_setup_func.<locals>.assert_called_oncecs�j||�S)N)�assert_called_once_with)r+r,)r1rrrR�sz,_setup_func.<locals>.assert_called_once_withcs�j||�S)N)�assert_has_calls)r+r,)r1rrrS�sz%_setup_func.<locals>.assert_has_callscs�j||�S)N)�assert_any_call)r+r,)r1rrrT�sz$_setup_func.<locals>.assert_any_callcs:t��_t��_�j��j}t|�r6|�k	r6|j�dS)N)�	_CallList�method_calls�
mock_calls�
reset_mock�return_valuer)�ret)r;r1rrrX�sz_setup_func.<locals>.reset_mockFr)r1r�called�
call_count�	call_argsrU�call_args_listrVrWrY�side_effect�_mock_childrenrNrRrSrTrXrOrPrQ�_mock_delegate)
r;r1rNrOrPrQrRrSrTrXr)r;r1rrH�s:rHcCsd|dd�|kS)Nz__%s__����r)rrrr�	_is_magic�srdc@seZdZdd�Zdd�ZdS)�_SentinelObjectcCs
||_dS)N)r)�selfrrrrr!�sz_SentinelObject.__init__cCs
d|jS)Nzsentinel.%s)r)rfrrr�__repr__�sz_SentinelObject.__repr__N)r5r8�__qualname__r!rgrrrrre�srec@seZdZdd�Zdd�ZdS)�	_SentinelcCs
i|_dS)N)�
_sentinels)rfrrrr!�sz_Sentinel.__init__cCs|dkrt�|jj|t|��S)N�	__bases__)r"rj�
setdefaultre)rfrrrr�__getattr__sz_Sentinel.__getattr__N)r5r8rhr!rmrrrrri�sricCs$t|�ttttfkr t|�|�S|S)N)r�dictr>r?�set)�valuerrr�_copysrqrY�_mock_return_valuer_�_mock_side_effect�_mock_parent�_mock_new_parent�
_mock_name�_mock_new_namecCs8tj|�d|}||fdd�}||fdd�}t||�S)NZ_mock_cSs"|j}|dkrt||�St||�S)N)rar<)rfr�	_the_namer-rrr�_gets
z"_delegating_property.<locals>._getcSs*|j}|dkr||j|<nt|||�dS)N)rarB�setattr)rfrprrxr-rrr�_set$sz"_delegating_property.<locals>._set)�_allowed_names�add�property)rrxryr{rrr�_delegating_propertys

rc@seZdZdd�Zdd�ZdS)rUcCsnt|t�stj||�St|�}t|�}||kr2dSx6td||d�D] }||||�}||krFdSqFWdS)NFr�T)rr>�__contains__�len�range)rfrpZ	len_valueZlen_self�iZsub_listrrrr�1s
z_CallList.__contains__cCstjt|��S)N)�pprintZpformatr>)rfrrrrg?sz_CallList.__repr__N)r5r8rhr�rgrrrrrU/srUcCsxt|�sdS|js,|js,|jdk	s,|jdk	r0dS|}x|dk	rR||krJdS|j}q6W|rd||_||_|rt||_||_dS)NFT)rrvrwrtru)�parentrpr�new_name�_parentrrr�_check_and_set_parentCs$



r�c@s$eZdZdd�Zdd�Zdd�ZdS)�	_MockItercCst|�|_dS)N)�iterr)rfrrrrr!]sz_MockIter.__init__cCs|S)Nr)rfrrr�__iter___sz_MockIter.__iter__cCs
t|j�S)N)�nextr)rfrrr�__next__asz_MockIter.__next__N)r5r8rhr!r�r�rrrrr�\sr�c@seZdZeZdZdd�ZdS)�BaseNcOsdS)Nr)rfr+r,rrrr!gsz
Base.__init__)r5r8rhrrrrsr!rrrrr�dsr�c@sDeZdZdd�ZdCdd�Zdd	�ZdDd
d�ZdEdd
�Zdd�Zdd�Z	dZ
eee	e
�Zedd��Z
ed�Zed�Zed�Zed�Zed�Zdd�Zdd�Zeee�ZdFddd�dd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Z d3d4�Z!d5d6�Z"d7d8�Z#d9d:�Z$d;d<�Z%dGd=d>�Z&d?d@�Z'dAdB�Z(dS)Hr
cOs$t|j|fd|ji�}tj|�}|S)Nr6)rr5r6�object�__new__)�clsr+�kw�newr3rrrr�os
zNonCallableMock.__new__N�FcKs�|dkr|}|j}
||
d<||
d<||
d<||
d<|dk	rB|}d}|
dkrR|dk	}
|j|||	|
�i|
d<||
d<d|
d<d	|
d
<d|
d<d|
d
<t�|
d<t�|
d<t�|
d<||
d<|r�|jf|�tt|�j||||||�dS)NrtrvrwruTr`�_mock_wrapsraFZ_mock_calledZ_mock_call_argsrZ_mock_call_countZ_mock_call_args_listZ_mock_mock_callsrV�_mock_unsafe)rB�_mock_add_specrU�configure_mock�_safe_superr
r!)rf�specrr�spec_setr��_spec_state�	_new_name�_new_parent�_spec_as_instance�	_eat_selfZunsafer,rBrrrr!xs8




zNonCallableMock.__init__cCs(d|_d|_d|_d|_t|||�dS)Nr�)rtrurvrwrz)rfr1�	attributerrr�attach_mock�s
zNonCallableMock.attach_mockcCs|j||�dS)N)r�)rfr�r�rrr�
mock_add_spec�szNonCallableMock.mock_add_specc	Cs|d}d}|dk	rRt|�rRt|t�r*|}nt|�}t|||�}|oH|d}t|�}|j}||d<||d<||d<||d<dS)Nr��_spec_class�	_spec_set�_spec_signature�
_mock_methods)r@rr�
_get_classr(�dirrB)	rfr�r�r�r�r�r��resrBrrrr��s
zNonCallableMock._mock_add_speccCs8|j}|jdk	r|jj}|tkr4|j|dd�}||_|S)Nz())r�r�)rrrarYr�_get_child_mock)rfrZrrrZ__get_return_value�s

z"NonCallableMock.__get_return_valuecCs,|jdk	r||j_n||_t||dd�dS)Nz())rarYrrr�)rfrprrrZ__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)rfrrr�	__class__�s
zNonCallableMock.__class__r[r\r]r^rWcCsT|j}|dkr|jS|j}|dk	rPt|�rPt|t�rPt|�rPt|�}||_|S)N)rarsr_�callablerr�r )rf�	delegatedZsfrrrZ__get_side_effect�sz!NonCallableMock.__get_side_effectcCs(t|�}|j}|dkr||_n||_dS)N)�	_try_iterrarsr_)rfrpr�rrrZ__set_side_effects
z!NonCallableMock.__set_side_effect)rYr_cCs�|dkrg}t|�|krdS|jt|��d|_d|_d|_t�|_t�|_t�|_|r^t	|_
|rhd|_x0|jj
�D]"}t|t�st|tkr�qt|j|�qtW|j
}t|�r�||k	r�|j|�dS)NFr)�id�appendr[r]r\rUrWr^rVrrrrsr`�valuesr�
_SpecState�_deletedrXr)rfZvisitedrYr_ZchildrZrrrrX
s,zNonCallableMock.reset_mockcKs`xZt|j�dd�d�D]B\}}|jd�}|j�}|}x|D]}t||�}q:Wt|||�qWdS)NcSs|djd�S)Nr�.)�count)�entryrrr�<lambda>8sz0NonCallableMock.configure_mock.<locals>.<lambda>)�keyr�)�sorted�items�split�popr<rz)rfr,�arg�valr+�finalrr�rrrr�+s	


zNonCallableMock.configure_mockcCs�|dkrt|��n:|jdk	r<||jks.|tkrLtd|��nt|�rLt|��|jsd|jd�rdt|��|jj|�}|tkr�t|��np|dkr�d}|j	dk	r�t
|j	|�}|j|||||d�}||j|<n.t|t
�r�t|j|j|j|j|j�}||j|<|S)	Nr�r�zMock object has no attribute %r�assert�assret)r�rrr�r�>r�r�)r�r�)r"r��_all_magicsrdr�rr`rCr�r�r<r�rr�rr�r�r3r�r)rfrrJrrrrrmAs6






zNonCallableMock.__getattr__c
Cs"|jg}|j}|}d}|dgkr$d}t�}xT|dk	r~|}|j|j|�d}|jdkrZd}|j}t|�|krnP|jt|��q,Wtt|��}|jp�d}t	|�dkr�|dd
kr�|d7}||d<dj
|�}d}|dkr�d	|}d}	|jdk	�rd
}	|j�r�d}	|	|jj
}	dt|�j
||	t|�fS)Nr��()r�r1r��().r�mock.z name=%rz spec=%rz spec_set=%rz<%s%s%s id='%s'>)r�r�)r1r�)rwruror�r�r}r>�reversedrvr��joinr�r�r5r)
rfZ
_name_listr�Zlast�dot�seenZ_firstrZname_stringZspec_stringrrrrggsL




zNonCallableMock.__repr__cCshtstj|�S|jpg}tt|��}t|j�}dd�|D�}dd�|D�}tt	|||t|j
���S)NcSsg|]}|jd�s|�qS)r)r)r�errr�
<listcomp>�sz+NonCallableMock.__dir__.<locals>.<listcomp>cSs$g|]}|jd�st|�r|�qS)r)rrd)rr�rrrr��s)r	r��__dir__r�r�rr>rBr�ror`)rfZextrasZ	from_typeZ	from_dictrrrr��s


zNonCallableMock.__dir__cs"|tkrtj�||�S�jrH�jdk	rH|�jkrH|�jkrHtd|��n�|tkrbd|}t|��n�|tkr�jdk	r�|�jkr�td|��t	|�s�t
t��|t||��|���fdd�}n(t
�|d|�t
t��||�|�j|<n.|dk�r�|�_dSt
�|||��r|�j|<tj�||�S)Nz!Mock object has no attribute '%s'z.Attempting to set unsupported magic method %r.cs��f|�|�S)Nr)r+r�)rIrfrrr��sz-NonCallableMock.__setattr__.<locals>.<lambda>r�)r|r��__setattr__r�r�rBr"�_unsupported_magicsr�rrzr�_get_methodr�r`r�)rfrrp�msgr)rIrfrr��s2




zNonCallableMock.__setattr__cCs�|tkr2|t|�jkr2tt|�|�||jkr2dS||jkrHtj||�|jj|t�}|t	krft
|��|tk	rv|j|=t	|j|<dS)N)r�rrB�delattrr��__delattr__r`rC�_missingr�r")rfrrrrrr��s

zNonCallableMock.__delattr__cCs|jpd}t|||�S)Nr1)rv�_format_call_signature)rfr+r,rrrr�_format_mock_call_signature�s
z+NonCallableMock._format_mock_call_signaturecCsDd}|j||�}|j}t|�dkr.|dd�}|j|�}|||fS)Nz!Expected call: %s
Actual call: %s�r�)r�r]r�)rfr+r,�message�expected_stringr]Z
actual_stringrrr�_format_mock_failure_message�s
z,NonCallableMock._format_mock_failure_messagecCst|j}|dk	rlt|�dkr(d}|\}}n
|\}}}y||j||�fStk
rh}z
|jd�Sd}~XqpXn|SdS)Nrbr�)r�r�r)�	TypeError�with_traceback)rf�_callr-rr+r,r�rrr�
_call_matcher�s

zNonCallableMock._call_matchercCs.|}|jdkr*d|jpd|jf}t|��dS)Nrz7Expected '%s' to not have been called. Called %s times.r1)r\rv�AssertionError)r*rfr�rrrrPs

z!NonCallableMock.assert_not_calledcCs(|}|jdkr$d|jpd}t|��dS)Nrz"Expected '%s' to have been called.r1)r\rvr�)r*rfr�rrrrOs

zNonCallableMock.assert_calledcCs.|}|jdks*d|jpd|jf}t|��dS)Nr�z8Expected '%s' to have been called once. Called %s times.r1)r\rvr�)r*rfr�rrrrQs

z"NonCallableMock.assert_called_oncecs||��jdkr(�j���}td|f�����fdd�}�j��f�}�j�j�}||krxt|t�rh|nd}t|��|�dS)NzExpected call: %s
Not calledcs�j���}|S)N)r�)r�)r+r,rfrr�_error_message'sz:NonCallableMock.assert_called_with.<locals>._error_message)r]r�r�r�r�	Exception)r*r+r,�expectedr��actual�causer)r+r,rfrrNs
z"NonCallableMock.assert_called_withcOs6|}|jdks*d|jpd|jf}t|��|j||�S)Nr�z1Expected '%s' to be called once. Called %s times.r1)r\rvr�rN)r*r+r,rfr�rrrrR1s
z'NonCallableMock.assert_called_once_withcs��fdd�|D�}t|t�r |nd}t�fdd��jD��}|sd||kr`tdt|��jf�|�dSt|�}g}x:|D]2}y|j|�Wqvtk
r�|j|�YqvXqvW|r�tdt	|�f�|�dS)Ncsg|]}�j|��qSr)r�)r�c)rfrrr�Fsz4NonCallableMock.assert_has_calls.<locals>.<listcomp>c3s|]}�j|�VqdS)N)r�)rr�)rfrr�	<genexpr>Hsz3NonCallableMock.assert_has_calls.<locals>.<genexpr>z(Calls not found.
Expected: %r
Actual: %rz%r not all found in call list)
rr�rUrWr�r>�remover&r�r?)rfZcallsZ	any_orderr�r�Z	all_callsZ	not_foundZkallr)rfrrS<s*

z NonCallableMock.assert_has_callscsZ�j||f�}�fdd��jD�}||krVt|t�r8|nd}�j||�}td|�|�dS)Ncsg|]}�j|��qSr)r�)rr�)rfrrr�fsz3NonCallableMock.assert_any_call.<locals>.<listcomp>z%s call not found)r�r^rr�r�r�)rfr+r,r�r�r�r�r)rfrrT_szNonCallableMock.assert_any_callcKsFt|�}t|t�s2t|t�r"t}q<t|t�r<t}n
|jd}|f|�S)Nr�)rr�
CallableMixinrrr
rrA)rfr��_type�klassrrrr�os



zNonCallableMock._get_child_mock)NNNNNNr�NFNF)F)FF)N)F))r5r8rhr�r!r�r�r�Z"_NonCallableMock__get_return_valueZ"_NonCallableMock__set_return_valueZ"_NonCallableMock__return_value_docr~rYr�rr[r\r]r^rWZ!_NonCallableMock__get_side_effectZ!_NonCallableMock__set_side_effectr_rXr�rmrgr�r�r�r�r�r�rPrOrQrNrRrSrTr�rrrrr
lsP

)
	


&2"
			
#cCsF|dkr|St|�r|St|�r$|Syt|�Stk
r@|SXdS)N)r r=r�r�)rrrrr��sr�c
@sBeZdZddedddddddf
dd�Zdd�Zdd�Zd	d
�ZdS)r�Nr�c	Ks6||jd<tt|�j|||||||	|
f|�||_dS)Nrr)rBr�r�r!r_)rfr�r_rYrrr�r�r�r�r�r,rrrr!�s



zCallableMixin.__init__cOsdS)Nr)rfr+r,rrrr0�szCallableMixin._mock_check_sigcOs|j||�|j||�S)N)r0�
_mock_call)r*r+r,rrrr$�szCallableMixin.__call__cOs�|}d|_|jd7_t||fdd�}||_|jj|�t�}|jdk	}|j}|j	}|dk}	|j
jtd||f��|j}
x�|
dk	�r*|r�|
jjt|||f��|
jdk	}|r�|
jd|}t|||f�}|
j
j|�|
j	�r|	r�d}nd}|
j	dk}	|
j	||}|
j}
t
|
�}
|
|k�rP|j|
�q|W|j}|dk	�r�t|��rL|�n,t|��snt|�}t|��rx|�n
|||�}|tk	�r�|S|jtk	�r�|jS|jdk	�r�|j||�S|jS)NTr�)�twoz()r�r�)r[r\�_Callr]r^r�rortrvrwrWrurVr�r}r_r r=r�rrrrYr�)r*r+r,rfr�r�Zdo_method_callsZmethod_call_nameZmock_call_nameZ	is_a_callr�Zthis_mock_callr�Z_new_parent_idZeffectrJrrrr��s`









zCallableMixin._mock_call)r5r8rhrr!r0r$r�rrrrr��sr�c@seZdZdS)rN)r5r8rhrrrrr�s1cCs2y
t||�Stk
r,t|�t||�SXdS)N)r<r"�
__import__)�thing�comp�import_pathrrr�_dot_lookup1s

r�cCsF|jd�}|jd�}t|�}x$|D]}|d|7}t|||�}q"W|S)Nr�rz.%s)r�r�r�r�)�targetZ
componentsr�r�r�rrr�	_importer9s


r�cCs
t|d�S)N�is_local)�hasattr)�patcherrrr�_is_startedDsr�c@sdeZdZdZgZdd�Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�ZdS)�_patchNc

Csn|dk	r(|tk	rtd��|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��autospecr,�additional_patchers)
rfr�r�r�r�r�r�r�r�r,rrrr!Ns$z_patch.__init__c
CsHt|j|j|j|j|j|j|j|j|j	�	}|j
|_
dd�|jD�|_|S)NcSsg|]}|j��qSr)�copy)r�prrrr�qsz_patch.copy.<locals>.<listcomp>)r�r�r�r�r�r�r�r�r�r,�attribute_namer�)rfr�rrrrisz_patch.copycCst|t�r|j|�S|j|�S)N)rr�decorate_class�decorate_callable)rfr'rrrr$vs

z_patch.__call__cCsRxLt|�D]@}|jtj�sq
t||�}t|d�s2q
|j�}t||||��q
W|S)Nr$)r�rr�TEST_PREFIXr<r�rrz)rfr��attr�
attr_valuer�rrrr|s

z_patch.decorate_classcs<t�d�r�jj|��St����fdd���|g�_�S)N�	patchingscs�g}g}t�}z�ybxJ�jD]@}|j�}|j|�|jdk	rF|j|�q|jtkr|j|�qW|t|�7}�||�S||kr�t|�r�|j|�t	j
�}�YnXWdxt|�D]}|j|�q�WXdS)N)
r?r�	__enter__r�r�updater�rr��sys�exc_infor��__exit__)r+Zkeywargs�
extra_argsZentered_patchersr�patchingr�)r'�patchedrrr�s*




z)_patch.decorate_callable.<locals>.patched)r�rr�r)rfr'r)r'rrr�s
z_patch.decorate_callablecCs�|j�}|j}t}d}y|j|}Wn$ttfk
rHt||t�}YnXd}|tkrft|t	�rfd|_
|j
r�|tkr�td||f��||fS)NFTz!%s does not have the attribute %r)r�r�rrBr"�KeyErrorr<�	_builtinsrrr�)rfr�rrI�localrrr�get_original�sz_patch.get_originalcCs>|j|j|j}}}|j|j}}|j}|j�|_|dkr@d}|dkrLd}|dkrXd}|dk	rp|dk	rptd��|dk	s�|dk	r�|dkr�td��|j	�\}}|t
ko�|dk�rTd}	|dkr�|}|dkr�|}d}n&|dk	r�|dkr�|}d}n|dkr�|}|dk	�s
|dk	�r,|t
k�rtd��t|t��r,d}	t
}
i}|dk	�rD|}
nN|dk	�sX|dk	�r�|}|dk	�rj|}t|��r~d|k}
n
t|�}
|
�r�t}
|dk	�r�||d<|dk	�r�||d<t|
t��r�t|
t��r�|j�r�|j|d	<|j|�|
f|�}|	�r�t|��r�|}|dk	�r|}t|��r2t|��r2t}
|jd	�|
f|d
d�|��|_nl|dk	�r�|t
k	�rptd��|t
k�r�td
��t|�}|dk�r�|}t|f||jd�|��}n|�r�td��|}||_||_t|j|j|�|jdk	�r:i}|jt
k�r|||j<x.|jD]$}|j �}|jt
k�r|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�rz())r�r�zBautospec creates the mock for you. Can't specify autospec and new.z%Can't use 'autospec' with create=True)r��_namez.Can't pass kwargs to a mock we aren't creating)TN)!r�r�r�r�r,r�r�r�r�rrrrrr@r�rrr
r�r
rrEr�rY�boolr�
temp_originalr�rzrr�r	)rfr�r�r�r�r,r�rIrZinherit�Klass�_kwargsZ	this_specZnot_callableZnew_attrrrr�rrrr	�s�


















z_patch.__enter__cGs�t|�std��|jr4|jtk	r4t|j|j|j�nBt|j|j�|j	rvt
|j|j�sd|jdkrvt|j|j|j�|`|`|`x$t|j�D]}t|�r�|j
|�q�WdS)Nz stop called on unstarted patcherr6r8r9�__annotations__r:)r6r8r9rr:)r��RuntimeErrorr�rrrzr�r�r�r�r�r�r�r
)rfrr�rrrr
Hs z_patch.__exit__cCs|j�}|jj|�|S)N)r	�_active_patchesr�)rfrJrrr�start`sz_patch.startcCs.y|jj|�Wntk
r$YnX|j�S)N)rr�r&r
)rfrrr�stopgs
z_patch.stop)r5r8rhrrr!rr$rrrr	r
rrrrrrr�Is
(~r�csPy�jdd�\�}Wn&ttfk
r:td�f��YnX�fdd�}||fS)Nr�r�z.Need a valid target to patch. You supplied: %rcst��S)N)r�r)r�rrr�ysz_get_target.<locals>.<lambda>)�rsplitr�r&)r�r�r�r)r�r�_get_targetssr c

s$�fdd�}	t|	||||||||�	S)Ncs�S)Nrr)r�rrr��sz_patch_object.<locals>.<lambda>)r�)
r�r�r�r�r�r�r�r�r,r�r)r�r�
_patch_object}s
r!c
s�t��tkr�fdd�}n�fdd�}|s2td��t|j��}|d\}	}
t||	|
|||||i�	}|	|_xB|dd�D]2\}	}
t||	|
|||||i�	}|	|_|jj|�qvW|S)Ncst��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&r>r�r�rr�r�)
r�r�r�r�r�r�r,r�r�r�r�r�Zthis_patcherr)r�r�_patch_multiple�s&

r#c

Ks$t|�\}}	t||	|||||||�	S)N)r r�)
r�r�r�r�r�r�r�r,r�r�rrrr�sE
c@sReZdZfdfdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	eZ
e	ZdS)�_patch_dictFcKs>t|t�rt|�}||_t|�|_|jj|�||_d|_dS)N)	rr"r��in_dictrnr�r
�clear�	_original)rfr%r�r&r,rrrr!0s

z_patch_dict.__init__cs.t�t�r�j��St����fdd��}|S)Nc
s"�j�z
�||�S�j�XdS)N)r$�
_unpatch_dict)r+r�)�frfrr�_inner>s
z$_patch_dict.__call__.<locals>._inner)rrrr)rfr)r*r)r)rfrr$;s

z_patch_dict.__call__cCs\xVt|�D]J}t||�}|jtj�r
t|d�r
t|j|j|j	�}||�}t
|||�q
W|S)Nr$)r�r<rrrr�r$r%r�r&rz)rfr�rrZ	decoratorZ	decoratedrrrrIs

z_patch_dict.decorate_classcCs|j�dS)N)r$)rfrrrr	Tsz_patch_dict.__enter__cCs�|j}|j}|j}y|j�}Wn2tk
rPi}x|D]}||||<q8WYnX||_|rdt|�y|j|�Wn.tk
r�x|D]}||||<q�WYnXdS)N)r�r%r&rr"r'�_clear_dictr
)rfr�r%r&rIr�rrrr$Ys"

z_patch_dict._patch_dictcCsV|j}|j}t|�y|j|�Wn.tk
rPx|D]}||||<q8WYnXdS)N)r%r'r+r
r")rfr%rIr�rrrr(ss
z_patch_dict._unpatch_dictcGs|j�dS)NF)r()rfr+rrrr
�sz_patch_dict.__exit__N)r5r8rhr!r$rr	r$r(r
rrrrrrr$s
r$cCsBy|j�Wn0tk
r<t|�}x|D]
}||=q*WYnXdS)N)r&r"r>)r%�keysr�rrrr+�s
r+cCs xttj�D]}|j�qWdS)N)r�r�rr)rrrr�_patch_stopall�sr-Ztestz�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)rr/rrrr��s�__get__�__set__�
__delete__�__reversed__�__missing__�
__reduce__�
__reduce_ex__Z__getinitargs__�__getnewargs__�__getstate__�__setstate__�
__getformat__�
__setformat__rgr��__subclasses__�
__format__�__getnewargs_ex__cs�fdd�}||_|S)Ncs�|f|�|�S)Nr)rfr+r�)r'rr�method�sz_get_method.<locals>.method)r5)rr'r?r)r'rr��sr�cCsh|]}d|�qS)z__%s__r)rr?rrrr�srmr�r!r��__prepare__�__instancecheck__�__subclasscheck__�__del__cCs
tj|�S)N)r��__hash__)rfrrrr��sr�cCs
tj|�S)N)r��__str__)rfrrrr��scCs
tj|�S)N)r��
__sizeof__)rfrrrr��s)rDrErFr�y�?g�?)�__lt__�__gt__�__le__�__ge__�__int__r��__len__r
�__complex__�	__float__�__bool__�	__index__cs�fdd�}|S)Ncs$�jj}|tk	r|S�|kr dStS)NT)�__eq__rrr�NotImplemented)�other�ret_val)rfrrrQ�sz_get_eq.<locals>.__eq__r)rfrQr)rfr�_get_eq�srUcs�fdd�}|S)Ncs �jjtk	rtS�|krdStS)NF)�__ne__rrrrR)rS)rfrrrV�s
z_get_ne.<locals>.__ne__r)rfrVr)rfr�_get_ne�srWcs�fdd�}|S)Ncs �jj}|tkrtg�St|�S)N)r�rrrr�)rT)rfrrr��sz_get_iter.<locals>.__iter__r)rfr�r)rfr�	_get_iter�srX)rQrVr�cCs�tj|t�}|tk	r||_dStj|�}|dk	rdy||�}Wntk
rXt|�}YnX||_dStj|�}|dk	r�||�|_dS)N)�_return_valuesrCrrY�_calculate_return_valuer"�_side_effect_methodsr_)r1r?rZfixedZreturn_calulatorrYZ
side_effectorrrr�_set_return_values

r\c@seZdZdd�Zdd�ZdS)�
MagicMixincOs&|j�tt|�j||�|j�dS)N)�_mock_set_magicsr�r]r!)rfr+r�rrrr!(szMagicMixin.__init__cCs�t}t|dd�dk	rTtj|j�}t�}t|}x$|D]}|t|�jkr4t||�q4W|tt|�j�}t|�}x|D]}t||t	||��qtWdS)Nr�)
�_magicsr<�intersectionr�rorrBr�rz�
MagicProxy)rfZthese_magicsZ
remove_magicsr�r�rrrr^.s

zMagicMixin._mock_set_magicsN)r5r8rhr!r^rrrrr]'sr]c@seZdZddd�ZdS)rFcCs|j||�|j�dS)N)r�r^)rfr�r�rrrr�Gsz"NonCallableMagicMock.mock_add_specN)F)r5r8rhr�rrrrrEsc@seZdZddd�ZdS)rFcCs|j||�|j�dS)N)r�r^)rfr�r�rrrr�]szMagicMock.mock_add_specN)F)r5r8rhr�rrrrrRsc@s.eZdZdd�Zdd�Zdd�Zd
dd	�ZdS)racCs||_||_dS)N)rr�)rfrr�rrrr!iszMagicProxy.__init__cOs|j�}|||�S)N)�create_mock)rfr+r,�mrrrr$mszMagicProxy.__call__cCs8|j}|j}|j|||d�}t|||�t|||�|S)N)rr�r�)rr�r�rzr\)rfr�r�rcrrrrbqszMagicProxy.create_mockNcCs|j�S)N)rb)rfrr�rrrr0zszMagicProxy.__get__)N)r5r8rhr!r$rbr0rrrrrahs	rac@s$eZdZdd�Zdd�Zdd�ZdS)�_ANYcCsdS)NTr)rfrSrrrrQ�sz_ANY.__eq__cCsdS)NFr)rfrSrrrrV�sz_ANY.__ne__cCsdS)Nz<ANY>r)rfrrrrg�sz
_ANY.__repr__N)r5r8rhrQrVrgrrrrrdsrdcCsdd|}d}djdd�|D��}djdd�t|j��D��}|rD|}|r\|rT|d7}||7}||S)Nz%s(%%s)r�z, cSsg|]}t|��qSr)�repr)rr�rrrr��sz*_format_call_signature.<locals>.<listcomp>cSsg|]\}}d||f�qS)z%s=%rr)rr�rprrrr��s)r�r�r�)rr+r,r�Zformatted_argsZargs_stringZ
kwargs_stringrrrr��sr�c@sreZdZfddddfdd�Zfddddfdd�Zd	d
�ZejZdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)r�r�NFTcCs�f}i}t|�}|dkr$|\}}}nr|dkrd|\}	}
t|	t�rX|	}t|
t�rR|
}qb|
}q�|	|
}}n2|dkr�|\}t|t�r�|}nt|t�r�|}n|}|r�tj|||f�Stj||||f�S)Nr�rbr�)r�rr"r?r�)r�rprr�r��	from_kallr+r,�_len�first�secondrrrr��s.



z
_Call.__new__cCs||_||_||_dS)N)rvrt�_mock_from_kall)rfrprr�r�rfrrrr!�sz_Call.__init__cCsf|tkrdSyt|�}Wntk
r,dSXd}t|�dkrH|\}}n
|\}}}t|dd�rzt|dd�rz|j|jkrzdSd}|dkr�fi}}n�|dkr�|\}}}n�|dkr�|\}	t|	t�r�|	}i}n"t|	t�r�|	}fi}}nf}|	}nV|dk�r>|\}
}t|
t��r2|
}t|t��r&|i}}n
f|}}n
|
|}}ndS|�rV||k�rVdS||f||fkS)	NTFr�rbrtrr�r�)rr�r�r<rtrr?r")rfrSZ	len_otherZ	self_nameZ	self_argsZself_kwargsZ
other_nameZ
other_argsZother_kwargsrprhrirrrrQ�sP




z_Call.__eq__cOs<|jdkrtd||fdd�S|jd}t|j||f||d�S)Nr�z())r)rr�)rvr�)rfr+r,rrrrr$s

z_Call.__call__cCs2|jdkrt|dd�Sd|j|f}t||dd�S)NF)rrfz%s.%s)rr�rf)rvr�)rfrrrrrrms
z_Call.__getattr__cOs|jd�||�S)Nr�)rm)rfr+r,rrrr�$sz_Call.countcOs|jd�||�S)N�index)rm)rfr+r,rrrrk'sz_Call.indexcCs||js&|jpd}|jd�r"d|}|St|�dkr@d}|\}}n0|\}}}|sTd}n|jd�shd|}nd|}t|||�S)Nrz()zcall%srbzcall.%s)rjrvrr�r�)rfrr+r,rrrrg*s





z_Call.__repr__cCs8g}|}x"|dk	r*|jr"|j|�|j}q
Wtt|��S)N)rjr�rtrUr�)rf�valsr�rrr�	call_list?s


z_Call.call_list)r5r8rhr�r!rQr�rVr$rmr�rkrgrmrrrrr��s7r�)rfcKs,t|�rt|�}t|t�}d|i}|r0d|i}n|dkr<i}|rL|rLd|d<|j|�t}tj|�rji}n$t|�sxt}n|r�|r�t	|�r�t}|j
d|�}|}	|dkr�d}	|f|||	|d�|��}
t|t�r�t|
|�}
nt
||
||�|dk	o�|�r|
|j|<|�r,|�r,d|k�r,t||dd	|
d
�|
_x�t|�D]�}t|��rH�q6yt||�}Wntk
�rp�w6YnXd|i}|�r�d|i}t|t��s�t|||
||�}
|
|
j|<nZ|
}t|t��r�|
j}t|||�}||d<tf||||d�|��}
|
|
j|<t
||
|d
�t|
t��r6t|
||
��q6W|
S)Nr�r�Tr�rr�)r�r�r�rrYz())r3rr�r�)r�rr�r�)r2)r@rrr
rr%Zisdatadescriptorr=rrEr�r#rMr4r`rrYr�rdr<r"r�r1�
_must_skiprz)r�r�r3r�rr,�is_typerrr�r1r�rIr�r�r2rrrrPst










cCs|t|t�s$|t|di�krdS|j}xR|jD]H}|jj|t�}|tkrHq,t|tt	f�rZdStt|dd�t
�rp|SdSq,W|S)NrBFr0)rrr<r�rArBrCr�staticmethod�classmethod�MethodWrapperTypes)r�r�ror�rJrrrrn�s
rncCs$y|jStk
rt|�SXdS)N)r�r"r)rrrrr��sr�c@seZdZddd�ZdS)r�FNcCs(||_||_||_||_||_||_dS)N)r��idsr�r�r3r)rfr�r�r�rrsr3rrrr!�sz_SpecState.__init__)FNNNF)r5r8rhr!rrrrr��sr�c#spt|t�rdnd��fdd�|j��D�}|d�krD|dd�}n|ddd	�|d
<x|D]
}|Vq^WdS)N�
�
csg|]}|��qSrr)r�l)�seprrr�	sz&_iterate_read_data.<locals>.<listcomp>r����rxrxrxrx)r�bytesr�)�	read_dataZdata_as_list�liner)rwr�_iterate_read_data	s
r|r�cs���fdd�}���fdd�}���fdd��tdkr`ddl}ttt|j��jtt|j����a|dkrttdt	d	�}ttd
����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)�	readlinesrYr>)r+r,)�_state�handlerr�_readlines_side_effect(	sz)mock_open.<locals>._readlines_side_effectcs(�jjdk	r�jjSt���j�d�S)Nr)�readrYrr�)r+r,)r~rrzrr�_read_side_effect-	sz$mock_open.<locals>._read_side_effectc3sJ�jjdk	rx�jjVqWx�dD]
}|Vq&Wxt���Vq6WdS)Nr)�readlinerYr)r{)r~rrzrr�_readline_side_effect2	s
z(mock_open.<locals>._readline_side_effectr�open)rr�)r�r�cs6t���d<�jj�dkr2���d<�d�j_tS)Nrr�)r|r�r_r)r+r,)r�r~rrzrr�
reset_dataS	s

zmock_open.<locals>.reset_data)�	file_spec�_ior>ror��
TextIOWrapper�union�BytesIOrr�r	rYr|�writer�r�r}r_)r1rzr�r�r�r�r)r�r~rrzrr	s."

c@s$eZdZdd�Zdd�Zdd�ZdS)r
cKs
tf|�S)N)r)rfr,rrrr�i	szPropertyMock._get_child_mockcCs|�S)Nr)rfrZobj_typerrrr0l	szPropertyMock.__get__cCs||�dS)Nr)rfrr�rrrr1n	szPropertyMock.__set__N)r5r8rhr�r0r1rrrrr
`	s	)
rrrrrrrrr	r
rrr
)F)F)NFNNN)FFNN)Nr�)o�__all__�__version__r%r�r�builtins�typesr�	functoolsrrr�r�
BaseExceptionr�platformrZlangZ	Throwabler	�superr�rr r(r4r/r=r@rErMrHrdr�rerirrZMISSINGr�ZDELETEDr�rqr|rr>rUr�r�r�r
r�r�rr�r�r�r�r r!r#rr$r+r-rnZmultipleZstopallrZ
magic_methodsZnumericsr�r�Zinplace�rightZ
_non_defaultsr�r_r�r�rZrRrYrUrWrXr[r\r]rrrardrr�r?r�rrrnr�r�rrQr#r0rrr�r|rr
rrrr�<module>s
 

4	i5,
1Jv	

	
,

w
D