Your IP : 18.221.160.29


Current Path : /opt/alt/python310/lib64/python3.10/unittest/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/unittest/__pycache__/mock.cpython-310.opt-2.pyc

o

6��fs��@s�dZddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZmZddl
mZddlmZmZddlmZGdd	�d	e�Zd
d�ee�D�ZdZeZd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Z d�dd�Z!dd�Z"dd�Z#d d!�Z$d"d#�Z%d�d$d%�Z&d&d'�Z'd(d)�Z(d*d+�Z)Gd,d-�d-e*�Z+Gd.d/�d/e*�Z,e,�Z-e-j.Z.e-j/Z0e-j1Z2hd0�Z3d1d2�Z4Gd3d4�d4e5�Z6d5d6�Z7Gd7d8�d8e*�Z8Gd9d:�d:e*�Z9Gd;d<�d<e9�Z:e�;e:j<�Z=Gd=d>�d>e5�Z>d?d@�Z?GdAdB�dBe9�Z@GdCdD�dDe@e:�ZAdEdF�ZBdGdH�ZCdIdJ�ZDGdKdL�dLe*�ZEdMdN�ZFe.dddddfddO�dPdQ�ZG		d�dRdS�ZHe.dddddfddO�dTdU�ZIGdVdW�dWe*�ZJdXdY�ZKdZd[�ZLeGeI_*eJeI_MeHeI_NeLeI_Od\eI_Pd]ZQd^ZRd_�Sd`da�eR�T�D��ZUd_�Sdbda�eR�T�D��ZVhdc�ZWddde�ZXdfd�d_�SeQeReUeVg��T�D�ZYhdg�ZZdhhZ[eZe[BZ\eYeWBZ]e]e\BZ^hdi�Z_djdk�dldk�dmdk�dndk�do�Z`eaeaeaeadpddddqdrddpdds�
Zbdtdu�Zcdvdw�Zddxdy�Zedzd{�Zfecedeeefd|�Zgd}d~�ZhGdd��d�e9�ZiGd�d��d�eie:�ZjGd�d��d�ei�ZkGd�d��d�eieA�ZlGd�d��d�e9�ZmGd�d��d�e9�ZnGd�d��d�enekeA�ZoGd�d��d�e*�Zpep�Zqd�d��ZrGd�d��d�es�Ztetdd��Zu		d�ddO�d�d��Zvd�d��ZwGd�d��d�e*�Zxeyev�eyeqjz�fZ{da|d�d��Z}d�d�d��Z~Gd�d��d�eA�Zd�d��Z�Gd�d��d��Z�dS)�)�Mock�	MagicMock�patch�sentinel�DEFAULT�ANY�call�create_autospec�	AsyncMock�
FILTER_DIR�NonCallableMock�NonCallableMagicMock�	mock_open�PropertyMock�seal�N)�iscoroutinefunction)�CodeType�
ModuleType�
MethodType)�	safe_repr)�wraps�partial)�RLockc@�eZdZdS)�InvalidSpecErrorN��__name__�
__module__�__qualname__�rr�4/opt/alt/python310/lib64/python3.10/unittest/mock.pyr(�rcCsh|]	}|�d�s|�qS��_��
startswith)�.0�namerrr �	<setcomp>,�r(TcCs<t|�rt|t�sdSt|d�rt|d�}t|�pt�|�S)NF�__func__)�_is_instance_mock�
isinstancer	�hasattr�getattrr�inspectZisawaitable��objrrr �
_is_async_obj4s


r2cCst|dd�r
t|�SdS)N�__code__F)r.r��funcrrr �_is_async_func<sr6cCstt|�t�S�N)�
issubclass�typerr0rrr r+Csr+cCst|t�pt|t�ot|t�Sr7)r,�
BaseExceptionr9r8r0rrr �
_is_exceptionIs
�r;cCst|t�r
t|d�r
|jS|S�N�mock)r,�
FunctionTypesr-r=r0rrr �
_extract_mockPsr?cCs�	t|t�r|s|j}d}nt|t�s#z|j}Wn
ty"YdSw|r+t|d�}n|}z|t�|�fWSt	y?YdSw�NT)
r,r9�__init__r>�__call__�AttributeErrorrr/�	signature�
ValueError)r5Zas_instanceZeat_selfZsig_funcrrr �_get_signature_objectYs$

��rFFcsNt|||���durdS�\}��fdd�}t||�|t|�_�t|�_dS)Ncs�j|i|��dSr7��bind��self�args�kwargs��sigrr �checksig{�z"_check_signature.<locals>.checksig)rF�_copy_func_detailsr9�_mock_check_sig�
__signature__)r5r=�	skipfirst�instancerOrrMr �_check_signaturevs

rVc	Cs6dD]}zt||t||��WqtyYqwdS)N)r�__doc__�__text_signature__r�__defaults__�__kwdefaults__)�setattrr.rC)r5�funcopy�	attributerrr rQ�s��rQcCs@t|t�rdSt|tttf�rt|j�St|dd�durdSdS)NTrBF)r,r9�staticmethod�classmethodr�	_callabler*r.r0rrr r`�s

r`cCst|�ttfvSr7)r9�list�tupler0rrr �_is_list�srccCsH	t|t�st|dd�duS|f|jD]
}|j�d�dur!dSqdS)NrBTF)r,r9r.�__mro__�__dict__�get)r1�baserrr �_instance_callable�s
�rhcs�t|t�}t|||�}|dur|S|\}��fdd�}t||�|j}|��s)d}||d�}d|}	t|	|�||}
t|
|��|
S)Ncs�j|i|��dSr7rG�rKrLrMrr rO�rPz _set_signature.<locals>.checksigr\)Z
_checksig_r=zYdef %s(*args, **kwargs):
    _checksig_(*args, **kwargs)
    return mock(*args, **kwargs))r,r9rFrQr�isidentifier�exec�_setup_func)r=�originalrUrT�resultr5rOr'�context�srcr\rrMr �_set_signature�s$


�
rqcs���_�fdd�}�fdd�}�fdd�}�fdd�}�fd	d
�}�fdd�}�fd
d�}	��fdd�}
d�_d�_d�_t��_t��_t��_�j�_�j	�_	�j
�_
|�_|�_|�_
|	�_|
�_|�_|�_|�_|�_��_dS)Nc��j|i|��Sr7)�assert_called_withri�r=rr rs��z'_setup_func.<locals>.assert_called_withcrrr7)�
assert_calledrirtrr rv�ruz"_setup_func.<locals>.assert_calledcrrr7)�assert_not_calledrirtrr rw�ruz&_setup_func.<locals>.assert_not_calledcrrr7)�assert_called_oncerirtrr rx�ruz'_setup_func.<locals>.assert_called_oncecrrr7)�assert_called_once_withrirtrr ry�ruz,_setup_func.<locals>.assert_called_once_withcrrr7)�assert_has_callsrirtrr rz�ruz%_setup_func.<locals>.assert_has_callscrrr7)�assert_any_callrirtrr r{�ruz$_setup_func.<locals>.assert_any_callcsBt��_t��_����j}t|�r|�ur|��dSdSdSr7)�	_CallList�method_calls�
mock_calls�
reset_mock�return_valuer+)�ret�r\r=rr r�s�z_setup_func.<locals>.reset_mockFr)r=�called�
call_count�	call_argsr|�call_args_listr}r~r��side_effect�_mock_childrenrsryrzr{rrvrwrxrS�_mock_delegate)r\r=rNrsrvrwrxryrzr{rrr�r rl�s8
rlcsJtjj�_d�_d�_t��_�fdd�}dD]}t�|t||��qdS)Nrcst�j|�|i|��Sr7)r.r=)�attrrKrLrtrr �wrapper�z"_setup_async_mock.<locals>.wrapper)�assert_awaited�assert_awaited_once�assert_awaited_with�assert_awaited_once_with�assert_any_await�assert_has_awaits�assert_not_awaited)	�asyncio�
coroutines�
_is_coroutine�await_count�
await_argsr|�await_args_listr[r)r=r�r]rrtr �_setup_async_mock�s
�r�cCsd|dd�|kS)N�__%s__����r�r'rrr �	_is_magicrPr�c@�&eZdZ	dd�Zdd�Zdd�ZdS)�_SentinelObjectcCs
||_dSr7r��rJr'rrr rA�
z_SentinelObject.__init__cC�
d|jS�Nzsentinel.%sr��rJrrr �__repr__r�z_SentinelObject.__repr__cCr�r�r�r�rrr �
__reduce__!r�z_SentinelObject.__reduce__N)rrrrAr�r�rrrr r�s
r�c@r�)�	_SentinelcCs
i|_dSr7)�
_sentinelsr�rrr rA'r�z_Sentinel.__init__cCs|dkrt�|j�|t|��S)N�	__bases__)rCr��
setdefaultr�r�rrr �__getattr__*sz_Sentinel.__getattr__cC�dS)Nrrr�rrr r�0�z_Sentinel.__reduce__N)rrrrAr�r�rrrr r�%s
r�>�
_mock_name�_mock_new_parentr��_mock_return_valuer��_mock_new_name�_mock_parent�_mock_side_effectcCs8t�|�d|}||fdd�}||fdd�}t||�S)NZ_mock_cSs"|j}|durt||�St||�Sr7)r�r.)rJr'�	_the_namerNrrr �_getEs

z"_delegating_property.<locals>._getcSs,|j}|dur||j|<dSt|||�dSr7)r�rer[)rJ�valuer'r�rNrrr �_setJsz"_delegating_property.<locals>._set)�_allowed_names�add�property)r'r�r�r�rrr �_delegating_propertyBs


r�c@�eZdZdd�Zdd�ZdS)r|cCslt|t�st�||�St|�}t|�}||krdStd||d�D]}||||�}||kr3dSq"dS)NFr�T)r,ra�__contains__�len�range)rJr�Z	len_valueZlen_self�iZsub_listrrr r�Ws
�z_CallList.__contains__cCst�t|��Sr7)�pprintZpformatrar�rrr r�e�z_CallList.__repr__N)rrrr�r�rrrr r|Usr|cCs�t|�}t|�s
dS|js|js|jdus|jdurdS|}|dur/||ur(dS|j}|dus"|r7||_||_|r?||_||_dS)NFT)r?r+r�r�r�r�)�parentr�r'�new_name�_parentrrr �_check_and_set_parentis(

�r�c@r�)�	_MockItercCst|�|_dSr7)�iterr1)rJr1rrr rA�r�z_MockIter.__init__cCs
t|j�Sr7)�nextr1r�rrr �__next__�r�z_MockIter.__next__N)rrrrAr�rrrr r��sr�c@seZdZeZdZdd�ZdS)�BaseNcO�dSr7rrIrrr rA�r�z
Base.__init__)rrrrr�r�rArrrr r��sr�c@sreZdZ	e�Zdd�Z			dKdd�Zdd	�ZdLd
d�Z		dMdd
�Z	dd�Z
dd�ZdZe
e
ee�Ze
dd��Zed�Zed�Zed�Zed�Zed�Zdd�Zdd�Ze
ee�ZdNddd�dd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Z d/d0�Z!dOd2d3�Z"d4d5�Z#d6d7�Z$d8d9�Z%d:d;�Z&d<d=�Z'd>d?�Z(d@dA�Z)dLdBdC�Z*dDdE�Z+dFdG�Z,dPdIdJ�Z-dS)QrcOs||f}t|t�s*tj|g|�Ri|��j}|�d|�d��}|dur*t|�r*t|f}t|j|d|j	i�}t
t|��|�}|S)N�spec_set�specrW)
r8�AsyncMockMixin�	_MOCK_SIGZbind_partialZ	argumentsrfr2r9rrW�_safe_superr�__new__)�clsrK�kw�basesZ
bound_argsZspec_arg�newrUrrr r��s
zNonCallableMock.__new__N�FcKs�|dur|}|j}
||
d<||
d<||
d<||
d<d|
d<|dur%|}d}|
dur-|du}
|�|||	|
�i|
d<||
d	<d|
d
<d|
d<d|
d<d
|
d<t�|
d<t�|
d<t�|
d<||
d<|rj|jdi|��tt|��||||||�dS)Nr�r�r�r�F�_mock_sealedTr��_mock_wrapsr�Z_mock_calledZ_mock_call_argsrZ_mock_call_countZ_mock_call_args_listZ_mock_mock_callsr}�_mock_unsafer)re�_mock_add_specr|�configure_mockr�rrA)rJr�rr'r�r��_spec_state�	_new_name�_new_parent�_spec_as_instance�	_eat_self�unsaferLrerrr rA�s<




�zNonCallableMock.__init__cCs2	t|�}d|_d|_d|_d|_t|||�dS�Nr�)r?r�r�r�r�r[)rJr=r]Z
inner_mockrrr �attach_mock�szNonCallableMock.attach_mockcCs	|�||�dSr7)r��rJr�r�rrr �
mock_add_spec�szNonCallableMock.mock_add_speccCs�d}d}g}t|�D]}tt||d��r|�|�q
|dur>t|�s>t|t�r*|}nt|�}t|||�}	|	o9|	d}t|�}|j}
||
d<||
d<||
d<||
d<||
d<dS)Nr��_spec_class�	_spec_set�_spec_signature�
_mock_methods�_spec_asyncs)	�dirrr.�appendrcr,r9rFre)rJr�r�r�r�r�r�r�r��resrerrr r��s,
�
�zNonCallableMock._mock_add_speccCs8|j}|jdur|jj}|tur|j|dd�}||_|S)N�()�r�r�)r�r�r�r�_get_child_mock)rJr�rrr Z__get_return_values
�z"NonCallableMock.__get_return_valuecCs.|jdur||j_dS||_t||dd�dS)Nr�)r�r�r�r�)rJr�rrr Z__set_return_values
z"NonCallableMock.__set_return_valuez1The value to be returned when the mock is called.cCs|jdur	t|�S|jSr7)r�r9r�rrr �	__class__'s
zNonCallableMock.__class__r�r�r�r�r~cCsN|j}|dur
|jS|j}|dur%t|�s%t|t�s%t|�s%t|�}||_|Sr7)r�r�r��callabler,r�r;)rJ�	delegatedZsfrrr Z__get_side_effect4s��z!NonCallableMock.__get_side_effectcCs*t|�}|j}|dur||_dS||_dSr7)�	_try_iterr�r�r�)rJr�r�rrr Z__set_side_effect?s


z!NonCallableMock.__set_side_effect�r�r�cCs�	|durg}t|�|vrdS|�t|��d|_d|_d|_t�|_t�|_t�|_|r0t	|_
|r5d|_|j�
�D]}t|t�sE|turFq:|j|||d�q:|j
}t|�ra||urc|�|�dSdSdS)NFrr�)�idr�r�r�r�r|r~r�r}rr�r�r��valuesr,�
_SpecState�_deletedrr+)rJZvisitedr�r��childr�rrr rJs0�zNonCallableMock.reset_mockcKsZ	t|��dd�d�D]\}}|�d�}|��}|}|D]}t||�}qt|||�qdS)NcSs|d�d�S)Nr�.)�count)�entryrrr �<lambda>usz0NonCallableMock.configure_mock.<locals>.<lambda>)�keyr�)�sorted�items�split�popr.r[)rJrL�arg�valrK�finalr1rrrr r�hs�
�zNonCallableMock.configure_mockcCs�|dvrt|��|jdur||jvs|tvrtd|��nt|�r%t|��|js?|jr0||jvr?|�d�r?t|�d|�d���tj��|j�	|�}|t
urQt|��|durrd}|jdurbt|j|�}|j
|||||d�}||j|<nJt|t�r�zt|j|j|j|j|j�}Wn ty�|jdp�|}td|�d	|�d
|�d|j�d�	��w||j|<Wd�|SWd�|SWd�|S1s�wY|S)
N>r�r�zMock object has no attribute %r)�assertZassretZasertZaseertZassrtz6 is not a valid assertion. Use a spec for the mock if z is meant to be an attribute.)r�r'rr�r�r��Cannot autospec attr �
 from target �, as it has already been mocked out. [target=�, attr=�])rCr��_all_magicsr�r�r%r�_lockr�rfr�r�r.r�r,r�rr�r�rUr�r'rre)rJr'rnr�target_namerrr r�~sr
�
��
�
������
��
��
��zNonCallableMock.__getattr__cCs�|jg}|j}|}d}|dgkrd}|dur0|}|�|j|�d}|jdkr)d}|j}|dustt|��}|jp:d}t|�dkrK|ddvrK|d7}||d<d�|�S)Nr�r�r�r=r�)r�z().r)r�r�r�ra�reversedr�r��join)rJZ
_name_listr�Zlast�dotZ_firstrrr �_extract_mock_name�s*

�


z"NonCallableMock._extract_mock_namecCs^|��}d}|dvrd|}d}|jdur"d}|jrd}||jj}dt|�j||t|�fS)Nr�)r=zmock.z name=%rz spec=%rz spec_set=%rz<%s%s%s id='%s'>)rr�r�rr9r�)rJr'Zname_stringZspec_stringrrr r��s 
�zNonCallableMock.__repr__cCsx	tst�|�S|jpg}tt|��}t|j�}dd�|j�	�D�}dd�|D�}dd�|D�}t
t||||��S)NcSsg|]
\}}|tur|�qSr)r�)r&Zm_nameZm_valuerrr �
<listcomp>�s
�z+NonCallableMock.__dir__.<locals>.<listcomp>cSsg|]	}|�d�s|�qSr"r$�r&�errr r�r)cSs"g|]
}|�d�r
t|�r|�qSr")r%r�rrrr r�s
�)r
�object�__dir__r�r�r9rarer�rr�set)rJZextrasZ	from_typeZ	from_dictZfrom_child_mocksrrr r�s


�zNonCallableMock.__dir__csJ|tvrt��||�S�jr#�jdur#|�jvr#|�jvr#td|��|tvr/d|}t|��|tvrq�jdurC|�jvrCtd|��t	|�s\t
t��|t||��|���fdd�}n*t
�|d|�t
t��||�|�j|<n|dkrz|�_dSt
�|||�r�|�j|<�jr�t�|�s�����d|��}td|����t��||�S)Nz!Mock object has no attribute '%s'z.Attempting to set unsupported magic method %r.cs��g|�Ri|��Sr7r�rKr��rmrJrr r�z-NonCallableMock.__setattr__.<locals>.<lambda>r�r�zCannot set )r�r�__setattr__r�r�rerC�_unsupported_magicsrr+r[r9�_get_methodr�r�r�r�r-r)rJr'r��msg�	mock_namerrr r!�s8


zNonCallableMock.__setattr__cCs�|tvr|t|�jvrtt|�|�||jvrdS|j�|t�}||jvr.tt|��	|�n|t
ur6t|��|tur>|j|=t
|j|<dSr7)rr9re�delattrr�rf�_missingr�r�__delattr__r�rC)rJr'r1rrr r(s

zNonCallableMock.__delattr__cCs|jpd}t|||�Sr<)r��_format_call_signature�rJrKrLr'rrr �_format_mock_call_signature)s
z+NonCallableMock._format_mock_call_signaturercCs.d}|�||�}|j}|j|�}||||fS)Nz.expected %s not found.
Expected: %s
Actual: %s)r+r�)rJrKrL�action�message�expected_stringr�Z
actual_stringrrr �_format_mock_failure_message.s

z,NonCallableMock._format_mock_failure_messagecCsl	|s|jSd}|�dd��d�}|j}|D]}|�|�}|dus&t|t�r)|St|�}|j}|j}q|S)Nr�r�r�)r��replacerr�rfr,r�r?)rJr'rN�names�childrenr�rrr �_get_call_signature_from_name6s

	�z-NonCallableMock._get_call_signature_from_namec
Cs�	t|t�rt|�dkr|�|d�}n|j}|durVt|�dkr(d}|\}}n|\}}}z|j|i|��}t||j|j�WSt	yU}z|�
d�WYd}~Sd}~ww|S)Nr�rr�)r,rbr�r3r�rHrrKrL�	TypeError�with_traceback)rJ�_callrNr'rKrLZ
bound_callrrrr �
_call_matcherWs"

��zNonCallableMock._call_matchercCs2	|jdkrd|jpd|j|��f}t|��dS)Nrz9Expected '%s' to not have been called. Called %s times.%sr=�r�r��_calls_repr�AssertionError�rJr$rrr rwr�
���z!NonCallableMock.assert_not_calledcCs&	|jdkrd|jpd}t|��dS)Nrz"Expected '%s' to have been called.r=)r�r�r:r;rrr rv|s
��zNonCallableMock.assert_calledcCs2	|jdksd|jpd|j|��f}t|��dS)Nr�z:Expected '%s' to have been called once. Called %s times.%sr=r8r;rrr rx�r<z"NonCallableMock.assert_called_oncecs�	�jdur�����}d}d||f}t|�����fdd�}��t��fdd��}���j�}||krDt|t�r<|nd}t|��|�dS)Nznot called.z0expected call not found.
Expected: %s
Actual: %scs�����}|Sr7�r/�r$�rKrLrJrr �_error_message�sz:NonCallableMock.assert_called_with.<locals>._error_messageT��two)r�r+r:r7�_Callr,�	Exception)rJrKrL�expected�actualZ
error_messager@�causerr?r rs�s
��z"NonCallableMock.assert_called_withcOs>	|jdksd|jpd|j|��f}t|��|j|i|��S)Nr�z3Expected '%s' to be called once. Called %s times.%sr=)r�r�r9r:rs�rJrKrLr$rrr ry�s
��z'NonCallableMock.assert_called_once_withc		s	�fdd�|D�}tdd�|D�d�}t�fdd��jD��}|sN||vrL|dur-d}n
d�dd�|D��}t|�d	t|���jd
d��d����|�dSt|�}g}|D]}z|�|�WqVt	ym|�
|�YqVw|rtd
�jpvdt|�|f�|�dS)Nc�g|]}��|��qSr�r7�r&�cr�rr r�r z4NonCallableMock.assert_has_calls.<locals>.<listcomp>cs��|]
}t|t�r|VqdSr7�r,rDrrrr �	<genexpr>���z3NonCallableMock.assert_has_calls.<locals>.<genexpr>c3��|]}��|�VqdSr7rJrKr�rr rO���zCalls not found.z+Error processing expected calls.
Errors: {}cS�g|]}t|t�r|nd�qSr7rNrrrr r����
Expected: ZActual)�prefixr�z@%r does not contain all of %r in its call list, found %r insteadr=)
r�r|r~�formatr:r9�rstripra�removerEr�r�rb)	rJ�calls�	any_orderrErGZ	all_calls�problem�	not_found�kallrr�r rz�sX	�������������z NonCallableMock.assert_has_callsc�l	��t||fdd��}t|t�r|nd}�fdd��jD�}|s'|t|�vr4��||�}td|�|�dS)NTrAcrIrrJrKr�rr r�r z3NonCallableMock.assert_any_call.<locals>.<listcomp>z%s call not found)r7rCr,rDr��_AnyComparerr+r:�rJrKrLrErGrFr.rr�r r{�s���zNonCallableMock.assert_any_callcKs�	|jrd|vrd|d��nd}|��|}t|��|�d�}||jdvr.tdi|��St|�}t|t�r>|t	vr>t}n1t|t
�rU|tvsO|jrR||jvrRt}nt}nt|t
�sjt|t�rbt}n
t|t�rit}n|jd}|di|��S)Nr'r�r�r�r�r�r)r�rrCrfrer	r9r8r�_async_method_magicsr��_all_sync_magicsr��
CallableMixinrrrrd)rJr�r]r%r��_type�klassrrr r��s4

�



�
zNonCallableMock._get_child_mock�CallscCs$	|jsdSd|�dt|j��d�S)Nr��
z: r�)r~r)rJrVrrr r9szNonCallableMock._calls_repr)NNNNNNr�NFNF�F)FFr7)r)rg).rrrrrr�rAr�r�r�Z"_NonCallableMock__get_return_valueZ"_NonCallableMock__set_return_valueZ"_NonCallableMock__return_value_docr�r�r�r�r�r�r�r�r~Z!_NonCallableMock__get_side_effectZ!_NonCallableMock__set_side_effectr�rr�r�rr�rr!r(r+r/r3r7rwrvrxrsryrzr{r�r9rrrr r�sd
�-
	
�
�

0'
!


-&rc@seZdZ	dd�ZdS)r`cCs,|D]}tdd�t||�D��rdSqdS)NcSsg|]\}}||k�qSrr)r&rErFrrr r+s��z-_AnyComparer.__contains__.<locals>.<listcomp>TF)�all�zip)rJ�itemr6rrr r�(s��z_AnyComparer.__contains__N)rrrr�rrrr r`#sr`cCsF|dur|St|�r|St|�r|Szt|�WSty"|YSwr7)r;r`r�r4r0rrr r�3s
�r�c
@sReZdZddedddddddf
dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)rdNr�c	Ks:||jd<tt|�j|||||||	|
fi|��||_dS)Nr�)rer�rdrAr�)rJr�r�r�rr'r�r�r�r�r�rLrrr rADs


��
zCallableMixin.__init__cOr�r7rrIrrr rRPszCallableMixin._mock_check_sigcOs0|j|i|��|j|i|��|j|i|��Sr7)rR�_increment_mock_call�
_mock_callrIrrr rBUszCallableMixin.__call__cOs|j|i|��Sr7)�_execute_mock_callrIrrr rn]ruzCallableMixin._mock_callcOs
d|_|jd7_t||fdd�}||_|j�|�|jdu}|j}|j}|dk}|j	�td||f��|j
}|dur�|rW|j�t|||f��|jdu}|rW|jd|}t|||f�}	|j	�|	�|jrz|rld}
nd}
|jdk}|j|
|}|j
}|dus<dSdS)NTr�rAr�r�r�)r�r�rCr�r�r�r�r�r�r~r�r})rJrKrLr6Zdo_method_callsZmethod_call_nameZmock_call_nameZ	is_a_callr�Zthis_mock_callrrrr rm`s6


�z"CallableMixin._increment_mock_callcOs�|j}|dur)t|�r
|�t|�st|�}t|�r|�n||i|��}|tur)|S|jtur1|jS|jdur>|j|i|��S|jSr7)r�r;r`r�rr�r�r�)rJrKrL�effectrnrrr ro�s"�

z CallableMixin._execute_mock_call)
rrrrrArRrBrnrmrorrrr rdBs
�.rdc@r)rNrrrrr r�r!rcCs2zt||�WStyt|�t||�YSwr7)r.rC�
__import__)�thing�comp�import_pathrrr �_dot_lookup�s�rucCsB|�d�}|�d�}t|�}|D]}|d|7}t|||�}q|S)Nr�rz.%s)rrrqru)�targetZ
componentsrtrrrsrrr �	_importer�s

rwcCs(d}|D]
}||vrt|�d���qdS)N)Z	autospectZ	auto_specZset_specz5 might be a typo; use unsafe=True if this is intended)�RuntimeError)Zkwargs_to_checkZtyposZtyporrr �_check_spec_arg_typos�s���ryc@s�eZdZdZgZdd�dd�Zdd�Zdd	�Zd
d�Ze	j
dd
��Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)�_patchNF�r�c
Cs�|dur|turtd��|durtd��|
st|	�t|�r)td|�d|�d���t|�r8td|�d|�d���||_||_||_||_||_	||_
d|_||_||_
|	|_g|_dS)Nz,Cannot use 'new' and 'new_callable' togetherz1Cannot use 'autospec' and 'new_callable' togetherzCannot spec attr z0 as the spec has already been mocked out. [spec=rz? as the spec_set target has already been mocked out. [spec_set=F)rrEryr+r�getterr]r��new_callabler��createZ	has_localr��autospecrL�additional_patchers)rJr|r]r�r�r~r�rr}rLr�rrr rAsD������
z_patch.__init__c
CsHt|j|j|j|j|j|j|j|j|j	�	}|j
|_
dd�|jD�|_|S)NcSsg|]}|���qSr)�copy)r&�prrr r-��z_patch.copy.<locals>.<listcomp>)rzr|r]r�r�r~r�rr}rL�attribute_namer�)rJ�patcherrrr r�&s��z_patch.copycC�2t|t�r
|�|�St�|�r|�|�S|�|�Sr7�r,r9�decorate_classr/r�decorate_async_callable�decorate_callable�rJr5rrr rB3�





z_patch.__call__cCsNt|�D] }|�tj�s
qt||�}t|d�sq|��}t||||��q|S�NrB)r�r%r�TEST_PREFIXr.r-r�r[)rJrfr��
attr_valuer�rrr r�;s

z_patch.decorate_classccs��g}t���4}|jD]}|�|�}|jdur|�|�q|jtur'|�|�q|t	|�7}||fVWd�dS1s>wYdSr7)
�
contextlib�	ExitStack�	patchings�
enter_contextr��updater�rr�rb)rJ�patchedrK�keywargs�
extra_args�
exit_stack�patchingrrrr �decoration_helperIs�





�"�z_patch.decoration_helperc�>t�d�r
�j����St�����fdd����g�_�S)Nr�csD���||��\}}�|i|��Wd�S1swYdSr7�r��rKr�ZnewargsZnewkeywargs�r5r�rJrr r�^s�$�z)_patch.decorate_callable.<locals>.patched�r-r�r�rr�rr�r r�X�
z_patch.decorate_callablecr�)Nr�c�sL����||��\}}�|i|��IdHWd�S1swYdSr7r�r�r�rr r�os��$�z/_patch.decorate_async_callable.<locals>.patchedr�r�rr�r r�ir�z_patch.decorate_async_callablec	Cs�|��}|j}t}d}z|j|}Wnttfy#t||t�}Ynwd}|tvr2t|t	�r2d|_
|j
sA|turAtd||f��||fS)NFTz!%s does not have the attribute %r)r|r]rrerC�KeyErrorr.�	_builtinsr,rr~)rJrvr'rm�localrrr �get_originalzs"�
�z_patch.get_originalc
Cs�	|j|j|j}}}|j|j}}|j}|��|_|dur!d}|dur'd}|dur-d}|dur9|dur9td��|dusA|durI|dvrItd��|�	�\}}|t
u�r/|du�r/d}	|durj|}|duri|}d}n|durw|durv|}d}n|dur}|}|dus�|dur�|t
ur�td��t|t�r�d}	|dur�t
|�r�t}
nt}
i}|dur�|}
n)|dus�|dur�|}|dur�|}t|�r�d|v}
nt|�}
t
|�r�t}
n|
r�t}
|dur�||d<|dur�||d	<t|
t�r�t|
t�r�|jr�|j|d
<|�|�|
di|��}|	�r.t|��r.|}|du�r|}t|��st|��st}
|�d
�|
d|dd�|��|_nl|du�r�|t
u�r=td
��|t
u�rFtd��t|�}|du�rQ|}t|j��rgtd|j�d|j�d|�d���t|��r�t|jd|j�}td|j�d|�d|j�d|�d�	��t|f||jd�|��}n|�r�td��|}||_||_ t!�"�|_#z9t$|j|j|�|j%du�r�i}|jt
u�r�|||j%<|j&D]}|j#�'|�}|jt
u�r�|�|��q�|WS|WS|j(t)�*���s�YdS)NFzCan't specify spec and autospec)TNz6Can't provide explicit spec_set *and* spec or autospecTz!Can't use 'spec' with create=TruerBr�r�r'r�r�zBautospec creates the mock for you. Can't specify autospec and new.z%Can't use 'autospec' with create=Truerz: as the patch target has already been mocked out. [target=rrrr
r)r��_namez.Can't pass kwargs to a mock we aren't creatingr)+r�r�r�rrLr}r|rvr4r�rr,r9r2r	rrcr�rr8rr]r�r+rhrr��boolrr.r�
temp_original�is_localr�r��_exit_stackr[r�r�r��__exit__�sys�exc_info)rJr�r�r�rrLr}rmr�Zinherit�Klass�_kwargsZ	this_specZnot_callablerZnew_attrr�r�rrrr �	__enter__�s
��



��



�
��

�


���

������



��z_patch.__enter__cGs�	|jr|jturt|j|j|j�nt|j|j�|js2t|j|j�r)|jdvr2t|j|j|j�|`|`|`|j	}|`	|j
|�S)N)rWrrY�__annotations__rZ)r�r�rr[rvr]r&r~r-r�r�)rJr�r�rrr r�$s

z_patch.__exit__cCs	|��}|j�|�|Sr7)r��_active_patchesr��rJrnrrr �start9�z_patch.startcCs6	z|j�|�Wn
tyYdSw|�ddd�Sr7)r�rYrEr�r�rrr �stop@��z_patch.stop)rrrr�r�rAr�rBr�r��contextmanagerr�r�r�r�r�r�r�r�rrrr rz�s$�%

rzc
sLz
��dd�\�}Wntttfytd�����w�fdd�}||fS)Nr�r�z,Need a valid target to patch. You supplied: c�t��Sr7�rwr�rvrr rR�z_get_target.<locals>.<lambda>)�rsplitr4rErC)rvr]r|rr�r �_get_targetLs��r�r{csD	t��turt��d����fdd�}
t|
||||||||	|d�
S)Nz3 must be the actual object to be patched, not a strc��Sr7rrr�rr rl�z_patch_object.<locals>.<lambda>r{)r9�strr4rz)rvr]r�r�r~r�rr}r�rLr|rr�r �
_patch_objectVs
�

�r�c
s�	t��tur�fdd�}n�fdd�}|std��t|���}|d\}	}
t||	|
|||||i�	}|	|_|dd�D]\}	}
t||	|
|||||i�	}|	|_|j�|�q;|S)Ncr�r7r�rr�rr r�r�z!_patch_multiple.<locals>.<lambda>cr�r7rrr�rr r�r�z=Must supply at least one keyword argument with patch.multiplerr�)	r9r�rErarrzr�r�r�)
rvr�r~r�rr}rLr|rr]r�r�Zthis_patcherrr�r �_patch_multipless.���r�cKs*	t|�\}	}
t|	|
||||||||d�
S)Nr{)r�rz)rvr�r�r~r�rr}r�rLr|r]rrr r�sG

�rc@sheZdZ	ddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�_patch_dictrFcKs,||_t|�|_|j�|�||_d|_dSr7)�in_dict�dictr�r��clear�	_original)rJr�r�r�rLrrr rAs


z_patch_dict.__init__cCr�r7r�)rJ�frrr rBr�z_patch_dict.__call__c�t����fdd��}|S)Ncs,���z�|i|��W���S���wr7�r��
_unpatch_dictr�r�rJrr �_inner%sz-_patch_dict.decorate_callable.<locals>._inner�r�rJr�r�rr�r r�$�z_patch_dict.decorate_callablecr�)Nc�s4����z�|i|��IdHW���S���wr7r�rr�rr r�1s
�z3_patch_dict.decorate_async_callable.<locals>._innerr�r�rr�r r�0r�z#_patch_dict.decorate_async_callablecCsXt|�D]%}t||�}|�tj�r)t|d�r)t|j|j|j	�}||�}t
|||�q|Sr�)r�r.r%rr�r-r�r�r�r�r[)rJrfr�r�Z	decoratorZ	decoratedrrr r�<s
��z_patch_dict.decorate_classcCs	|��|jSr7)r�r�r�rrr r�Gsz_patch_dict.__enter__cCs�|j}t|jt�rt|j�|_|j}|j}z|��}Wnty1i}|D]}||||<q&Ynw||_|r;t	|�z|�
|�WdStyX|D]}||||<qLYdSwr7)r�r,r�r�rwr�r�rCr��_clear_dictr�)rJr�r�r�rmrrrr r�Ms.����z_patch_dict._patch_dictcCsP|j}|j}t|�z|�|�WdSty'|D]}||||<qYdSwr7)r�r�r�r�rC)rJr�rmrrrr r�is��z_patch_dict._unpatch_dictcGs	|jdur
|��dS�NF)r�r�)rJrKrrr r�vs
z_patch_dict.__exit__cCs	|��}tj�|�|Sr7)r�rzr�r�r�rrr r�}r�z_patch_dict.startcCs6	ztj�|�Wn
tyYdSw|�ddd�Sr7)rzr�rYrEr�r�rrr r��r�z_patch_dict.stopN)rF)rrrrArBr�r�r�r�r�r�r�r�r�rrrr r��s
	
r�cCs<z|��WdStyt|�}|D]}||=qYdSwr7)r�rCra)r��keysrrrr r��s��r�cCs	ttj�D]}|��qdSr7)rrzr�r�)rrrr �_patch_stopall�s
�r��testz�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 round trunc floor ceil bool next fspath aiter zHadd sub mul matmul div floordiv mod lshift rshift and xor or pow truediv� cc��|]}d|VqdS)zi%sNr�r&�nrrr rO���rOccr�)zr%sNrr�rrr rO�r�>�__reversed__r�Z__getinitargs__�
__format__�__getnewargs_ex__�__set__�
__delete__�__get__�__setstate__r��
__setformat__�__subclasses__�__getstate__r�
__getformat__�
__reduce_ex__�__missing__�__getnewargs__cs	�fdd�}||_|S)Ncs�|g|�Ri|��Sr7r�rJrKr�r4rr �method�r�z_get_method.<locals>.method)r)r'r5r�rr4r r#�sr#cCsh|]}d|�qS)r�r)r&r�rrr r(�r�>�	__aexit__�
__aenter__�	__anext__�	__aiter__>r�r!�__instancecheck__rA�__prepare__r��__del__�__subclasscheck__cC�
t�|�Sr7)r�__hash__r�rrr r��
rcCr�r7)r�__str__r�rrr r�r�cCr�r7)r�
__sizeof__r�rrr r�r�cCs"t|�j�d|���dt|���S)N�/)r9rrr�r�rrr r�s")r�r�r��
__fspath__r�y�?g�?)
�__lt__�__gt__�__le__�__ge__�__int__r��__len__r��__complex__�	__float__�__bool__�	__index__r�c��fdd�}|S)Ncs$�jj}|tur
|S�|urdStSr@)�__eq__r�r�NotImplemented)�other�ret_valr�rr r�sz_get_eq.<locals>.__eq__r)rJrrr�r �_get_eq��r	cr)Ncs �jjturtS�|urdStSr�)�__ne__r�rr)rr�rr rs
z_get_ne.<locals>.__ne__r)rJrrr�r �_get_nesrcr)Ncs �jj}|turtg�St|�Sr7)�__iter__r�rr��rr�rr r
sz_get_iter.<locals>.__iter__r)rJr
rr�r �	_get_iterr
rcr)Ncs(�jj}|turttg��Stt|��Sr7)r�r�r�_AsyncIteratorr�rr�rr r�sz"_get_async_iter.<locals>.__aiter__r)rJr�rr�r �_get_async_itersr)rrr
r�cCsft�|t�}|tur||_dSt�|�}|dur!||�}||_dSt�|�}|dur1||�|_dSdSr7)�_return_valuesrfrr��_calculate_return_value�_side_effect_methodsr�)r=r�r'ZfixedZreturn_calculatorr�Z
side_effectorrrr �_set_return_value*s

�rc@r�)�
MagicMixincO�*|��tt|�j|i|��|��dSr7)�_mock_set_magicsr�rrAr�rrr rA=�zMagicMixin.__init__cCs�ttB}|}t|dd�dur,|�|j�}t�}||}|D]}|t|�jvr+t||�q|tt|�j�}t|�}|D]}t	||t
||��q;dS)Nr�)�_magicsrbr.�intersectionr�rr9rer&r[�
MagicProxy)rJZorig_magicsZthese_magicsZ
remove_magicsrrerrr rCs
��zMagicMixin._mock_set_magicsN)rrrrArrrrr r<src@�eZdZ	ddd�ZdS)rFcC�	|�||�|��dSr7�r�rr�rrr r�]�z"NonCallableMagicMock.mock_add_specNri�rrrr�rrrr r[src@seZdZdd�ZdS)�AsyncMagicMixincOrr7)rr�r"rAr�rrr rAhrzAsyncMagicMixin.__init__N�rrrrArrrr r"gsr"c@r)rFcCrr7rr�rrr r�xr zMagicMock.mock_add_specNrir!rrrr rms
rc@s&eZdZdd�Zdd�Zddd�ZdS)	rcCs||_||_dSr7�r'r�)rJr'r�rrr rA�s
zMagicProxy.__init__cCs8|j}|j}|j|||d�}t|||�t|||�|S)N)r'r�r�)r'r�r�r[r)rJrr��mrrr �create_mock�s�zMagicProxy.create_mockNcCs|��Sr7)r&)rJr1rerrr r��szMagicProxy.__get__r7)rrrrAr&r�rrrr r�s	rcs�eZdZed�Zed�Zed�Z�fdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
ddd�Zdd�Z�fdd�Z�ZS)r�r�r�r�cs�t�j|i|��tjj|jd<d|jd<d|jd<t�|jd<ttd�}t	j
|_||jd<d|jd	<t�|jd
<i|jd<d|jd<dS)
Nr�rZ_mock_await_countZ_mock_await_argsZ_mock_await_args_list�r�r3r	rrYrZr�)
�superrAr�r�r�rer|rrr/ZCO_COROUTINE�co_flagsrb)rJrKrL�	code_mock�r�rr rA�s





zAsyncMockMixin.__init__c�s
�t||fdd�}|jd7_||_|j�|�|j}|dur]t|�r&|�t|�sAzt|�}Wn	t	y9t
�wt|�r@|�nt|�rP||i|��IdH}n||i|��}|tur]|S|j
ture|jS|jdur�t|j�rz|j|i|��IdHS|j|i|��S|jS)NTrAr�)rCr�r�r�r�r�r;r`r��
StopIteration�StopAsyncIterationrrr�r�r�)rJrKrLr6rprnrrr ro�s<���


z!AsyncMockMixin._execute_mock_callcCs*	|jdkrd|jpd�d�}t|��dS)Nr�	Expected r=z to have been awaited.�r�r�r:r;rrr r��s

�zAsyncMockMixin.assert_awaitedcCs2	|jdksd|jpd�d|j�d�}t|��dS�Nr�r.r=z$ to have been awaited once. Awaited � times.r/r;rrr r���
��z"AsyncMockMixin.assert_awaited_oncecs�	�jdur�����}td|�d������fdd�}��t��fdd��}���j�}||kr@t|t�r8|nd}t|��|�dS)NzExpected await: z
Not awaitedcs�j��dd�}|S)N�await)r,r=r>r?rr r@�sz:AsyncMockMixin.assert_awaited_with.<locals>._error_messageTrA)r�r+r:r7rCr,rD)rJrKrLrEr@rFrGrr?r r��s
�z"AsyncMockMixin.assert_awaited_withcOs>	|jdksd|jpd�d|j�d�}t|��|j|i|��Sr0)r�r�r:r�rHrrr r��s
�z'AsyncMockMixin.assert_awaited_once_withcr_)NTrAcrIrrJrKr�rr r
	r z3AsyncMockMixin.assert_any_await.<locals>.<listcomp>z%s await not found)r7rCr,rDr�r`r+r:rarr�r r�	s���zAsyncMockMixin.assert_any_awaitFc		s�	�fdd�|D�}tdd�|D�d�}t�fdd��jD��}|sI||vrG|dur-d}n
d�dd�|D��}t|�d	t|��d
�j���|�dSt|�}g}|D]}z|�|�WqQtyh|�|�YqQw|rutdt	|�f�|�dS)NcrIrrJrKr�rr r	r z4AsyncMockMixin.assert_has_awaits.<locals>.<listcomp>csrMr7rNrrrr rO	rPz3AsyncMockMixin.assert_has_awaits.<locals>.<genexpr>c3rQr7rJrKr�rr rO	rRzAwaits not found.z,Error processing expected awaits.
Errors: {}cSrSr7rNrrrr r'	rTrUz	
Actual: z%r not all found in await list)
r�r|r�rWr:rarYrEr�rb)	rJrZr[rErGZ
all_awaitsr\r]r^rr�r r�	sP�����������z AsyncMockMixin.assert_has_awaitscCs2	|jdkrd|jpd�d|j�d�}t|��dS)Nrr.r=z# to not have been awaited. Awaited r1r/r;rrr r�=	r2z!AsyncMockMixin.assert_not_awaitedcs,	t�j|i|��d|_d|_t�|_dS�Nr)r(rr�r�r|r�rIr+rr rF	s
zAsyncMockMixin.reset_mockri)rrrr�r�r�r�rAror�r�r�r�r�r�r�r�
__classcell__rrr+r r��s(	

,	r�c@r)r	Nrrrrr r	P	r!r	c@r�)�_ANYcCr�r@r�rJrrrr r~	r�z_ANY.__eq__cCr�r�rr7rrr r�	r�z_ANY.__ne__cCr�)Nz<ANY>rr�rrr r��	r�z
_ANY.__repr__N)rrrrrr�rrrr r6{	s
r6cCs`d|}d}d�dd�|D��}d�dd�|��D��}|r |}|r,|r(|d7}||7}||S)Nz%s(%%s)r�z, cSsg|]}t|��qSr)�repr)r&rrrr r�	sz*_format_call_signature.<locals>.<listcomp>cSsg|]
\}}d||f�qS)z%s=%rr)r&rr�rrr r�	s�)rr)r'rKrLr-Zformatted_argsZargs_stringZ
kwargs_stringrrr r)�	s
�r)c@s�eZdZ			ddd�Z		ddd	�Zd
d�ZejZdd
�Zdd�Z	dd�Z
dd�Zedd��Z
edd��Zdd�Zdd�ZdS)rCrr�NFTcCs�d}i}t|�}|dkr|\}}}n9|dkr2|\}	}
t|	t�r,|	}t|
t�r)|
}n"|
}n|	|
}}n|dkrK|\}t|t�rA|}n
t|t�rI|}n|}|rUt�|||f�St�||||f�S)Nr�r�r�)r�r,r�rbr�)r�r�r'r�rB�	from_kallrKrL�_len�first�secondrrr r��	s.



z
_Call.__new__cCs||_||_||_dSr7)r�r��_mock_from_kall)rJr�r'r�rBr:rrr rA�	s
z_Call.__init__cCsRzt|�}WntytYSwd}t|�dkr|\}}n|\}}}t|dd�r8t|dd�r8|j|jkr8dSd}|dkrDdi}}nU|dkrN|\}}}nK|dkrq|\}	t|	t�r_|	}i}n:t|	t�rl|	}di}}n-d}|	}n(|dkr�|\}
}t|
t�r�|
}t|t�r�|i}}nd|}}n|
|}}ndS|r�||kr�dS||f||fkS)	Nr�r�r�Frrr9r�)r�r4rr.r�r,rbr�)rJrZ	len_otherZ	self_nameZ	self_argsZself_kwargsZ
other_nameZ
other_argsZother_kwargsr�r<r=rrr r�	sN�





z_Call.__eq__cOs<|jdurtd||fdd�S|jd}t|j||f||d�S)Nr�r�r�r$�r�rCr*rrr rB
s

z_Call.__call__cCs2|jdurt|dd�Sd|j|f}t||dd�S)NF)r'r:z%s.%s)r'r�r:r?)rJr�r'rrr r�
s
z_Call.__getattr__cCs|tjvrt�t�||�Sr7)rbrerC�__getattribute__)rJr�rrr r@
s
z_Call.__getattribute__cCs.t|�dkr|\}}||fS|\}}}||fS)Nr�)r�r*rrr �_get_call_arguments$
s

�z_Call._get_call_argumentscC�|��dSr4�rAr�rrr rK,
�z
_Call.argscCrB)Nr�rCr�rrr rL0
rDz_Call.kwargscCs||js|jpd}|�d�rd|}|St|�dkr d}|\}}n|\}}}|s*d}n|�d�s4d|}nd|}t|||�S)Nrr�zcall%sr�zcall.%s)r>r�r%r�r))rJr'rKrLrrr r�4
s





z_Call.__repr__cCs<	g}|}|dur|jr|�|�|j}|dus	tt|��Sr7)r>r�r�r|r)rJZvalsrrrrr �	call_listI
s
�z_Call.call_list)rr�NFT)rNNFT)rrrr�rArrrrBr�r@rAr�rKrLr�rErrrr rC�	s(
� 
�5

rC)r:c	Ksj	t|�r	t|�}t|t�}t|�rtd|�d���t|�}d|i}	|r)d|i}	n|dur/i}	|	r7|r7d|	d<|s=t|�|	�|�t}
t	�
|�rLi}	n|rW|rTtd��t}
nt
|�s^t}
n
|rh|rht|�sht}
|	�d|�}|}|durvd	}|
d||||d
�|	��}t|t�r�t||�}|r�t|�nt||||�|dur�|s�||j|<|r�|s�d|vr�t||dd|d
�|_t|�D]w}
t|
�r�q�zt||
�}Wn	ty�Yq�wd|i}|r�d|i}t|t�s�t||||
|�}||j|
<n6|}t|t�r�|j}t||
|�}||d<t|��rt}nt}|d||
|
|d�|��}||j|
<t|||d�t|t��r2t ||
|�q�|S)Nz'Cannot autospec a Mock object. [object=rr�r�Tr�zJInstance can not be True when create_autospec is mocking an async functionr'r�)r�r�r�r'r�r�)rUr�r�r�)r�r'r�r�)rTr)!rcr9r,r+rr6ryr�rr/Zisdatadescriptorrxr	r`rrhrr>rqr�rVr�rr�r�r�r.rCr�r=�
_must_skiprr[)r�r�rUr�r�r�rL�is_typeZ
is_async_funcr�r�r�r=rrmr�r�rTZchild_klassrrr rY
s�

�



��

�
��



��
�rcCsx	t|t�s|t|di�vrdS|j}|jD]#}|j�|t�}|tur$qt|tt	f�r.dSt|t
�r7|SdS|S)NreF)r,r9r.r�rdrerfrr^r_r>)r�rrGrfrnrrr rF�
s


rFc@seZdZ		ddd�ZdS)r�FNcCs(||_||_||_||_||_||_dSr7)r��idsr�r�rUr')rJr�r�r�r'rHrUrrr rAs
z_SpecState.__init__)FNNNFr#rrrr r�s�r�cCst|t�r
t�|�St�|�Sr7)r,�bytes�io�BytesIO�StringIO)�	read_datarrr �
_to_streams


rNr�cs(	t��}|dg���fdd�}��fdd�}��fdd����fdd����fd	d
�}tdurEddl}ttt|j���tt|j����a|durOt	dt
d
�}t	td����j_d�j
_d�j_d�j_d�j_|�j_���d<�d�j_|�j_��j_|�j_����fdd�}||_�|_|S)Nc�(�jjdur
�jjS�dj|i|��Sr4)�	readlinesr�ri��_state�handlerr �_readlines_side_effect.�z)mock_open.<locals>._readlines_side_effectcrOr4)�readr�rirQrr �_read_side_effect3rUz$mock_open.<locals>._read_side_effectc?s(���EdH	�dj|i|��Vq�NTr)�readlineri)�_iter_side_effectrRrr �_readline_side_effect8s
��z(mock_open.<locals>._readline_side_effectc3s4��jjdur	�jjVq�dD]}|VqdSrX)rYr�)�linerQrr rZ=s�
��z$mock_open.<locals>._iter_side_effectcs �jjdur
�jjSt�d�Sr4)rYr�r�rrQrr �_next_side_effectDsz$mock_open.<locals>._next_side_effectr�open)r'r�)r�r�cs6t���d<�jj�dkr���d<�d�j_tS)Nrr�)rNrYr�rri)r[rRrSrMrr �
reset_data`s

zmock_open.<locals>.reset_data)rN�	file_spec�_iorarr��
TextIOWrapper�unionrKrr^r�r��writerVrYrPr�r
r�)r=rMZ
_read_datarTrWr]rar_r)rZr[rRrSrMr r
s:"

r
c@s(eZdZ	dd�Zddd�Zdd�ZdS)	rcKstdi|��S)Nr)r)rJrLrrr r�vr�zPropertyMock._get_child_mockNcCs|�Sr7r)rJr1Zobj_typerrr r�yszPropertyMock.__get__cCs||�dSr7r)rJr1r	rrr r�{szPropertyMock.__set__r7)rrrr�r�r�rrrr rms

rc	Csn	d|_t|�D],}zt||�}Wn	tyYqwt|t�s!qt|j�|�t�r+q|j	|ur4t
|�qdSr@)r�r�r.rCr,rr�rfr�r�r)r=r�r%rrr rs 	�

��rc@seZdZ	dd�Zdd�ZdS)rcCs&||_ttd�}tj|_||jd<dS)Nr'r3)�iteratorrrr/ZCO_ITERABLE_COROUTINEr)re)rJrer*rrr rA�s
z_AsyncIterator.__init__c�s$�zt|j�WStyYt�wr7)r�rer,r-r�rrr r��s��z_AsyncIterator.__anext__N)rrrrAr�rrrr r�srri)NFNNN)FFNNr�)��__all__r�r�rJr/r�r��builtinsr�typesrrrZ
unittest.utilr�	functoolsrrZ	threadingrrDrr�r�r
r(r�r2r6r+r;r?rFrVrQr`rcrhrqrlr�r�rr�r�rr�MISSINGr'ZDELETEDr�r�r�rar|r�r�r�rrDrAr�r`r�rdrrurwryrzr�r�r�rr�r�r�r�ZmultipleZstopallr�Z
magic_methodsZnumericsrrZinplace�rightZ
_non_defaultsr#rrbZ_sync_async_magicsZ
_async_magicsrcrr"rrrr	rrrrrrrr"rrr�r	r6rr)rbrCrrrFr�r9rr>r`rNr
rrrrrrr �<module>sD	



1h4
	R��
�2��R	��	���
	
	�	<+
:��
�
N

?>