AlkantarClanX12

Your IP : 18.119.141.115


Current Path : /opt/alt/python37/lib64/python3.7/unittest/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/unittest/__pycache__/mock.cpython-37.opt-2.pyc

B

YI~d�C�@s\dZdZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
ddlmZm
Z
dd�ee�D�ZefZdejkr�ddlZeejjfZd	ZeZd
d�Zdd
�Zdd�Zdd�Zd�dd�Zdd�Zdd�Zdd�Z dd�Z!d�dd�Z"dd �Z#d!d"�Z$Gd#d$�d$e%�Z&Gd%d&�d&e%�Z'e'�Z(e(j)Z)e(j*Z+e(j,Z-d'd(�Z.d)d*d+d,d-d.d/d0hZ/d1d2�Z0Gd3d4�d4e1�Z2d5d6�Z3Gd7d8�d8e%�Z4Gd9d:�d:e%�Z5Gd;d<�d<e5�Z6d=d>�Z7Gd?d@�d@e5�Z8GdAdB�dBe8e6�Z9dCdD�Z:dEdF�Z;dGdH�Z<GdIdJ�dJe%�Z=dKdL�Z>e)dddddfdMdN�Z?d�dOdP�Z@e)dddddfdQdR�ZAGdSdT�dTe%�ZBdUdV�ZCdWdX�ZDe?eA_%eBeA_Ee@eA_FeDeA_GdYeA_HdZZId[ZJd\�Kd]d^�eJ�L�D��ZMd\�Kd_d^�eJ�L�D��ZNd`dadbdcdddedfdgdhdidjdkdldmdndodpdqhZOdrds�ZPdtd�d\�KeIeJeMeNg��L�D�ZQeQeOBZRdudvdwdxdydzd{d|hZSd}d~�dd~�d�d~�d��ZTeUeUeUeUd�dddd�d�d	d�d��ZVd�d��ZWd�d��ZXd�d��ZYeWeXeYd��ZZd�d��Z[Gd�d��d�e%�Z\Gd�d��d�e\e6�Z]Gd�d��d�e\e9�Z^Gd�d��d�e%�Z_Gd�d��d�e%�Z`e`�Zad�d��ZbGd�d��d�ec�Zdeddd��Zed�d�d��Zfd�d��Zgd�d��ZhGd�d��d�e%�Ziejef�ejeajk�fZldamd�d��Znd�d�d��ZoGd�d��d�e9�Zpd�d��ZqdS)�)�Mock�	MagicMock�patch�sentinel�DEFAULT�ANY�call�create_autospec�
FILTER_DIR�NonCallableMock�NonCallableMagicMock�	mock_open�PropertyMock�sealz1.0�N)�
ModuleType�
MethodType)�wraps�partialcCsh|]}|�d�s|�qS)�_)�
startswith)�.0�name�r�2/opt/alt/python37/lib64/python3.7/unittest/mock.py�	<setcomp>&sr�javaTcCstt|�t�S)N)�
issubclass�typer
)�objrrr�_is_instance_mock5srcCst|t�pt|t�ot|t�S)N)�
isinstance�BaseExceptionsrr)rrrr�
_is_exception;s
r"cCs"t|t�rt|d�r|jS|SdS)N�mock)r �
FunctionTypes�hasattrr#)rrrr�
_extract_mockBsr&cCs�t|t�r4|s4y
|j}Wntk
r,dSXd}n*t|t�s^y
|j}Wntk
r\dSX|rnt|d�}n|}y|t�|�fSt	k
r�dSXdS)NT)
r r�__init__�AttributeErrorr$�__call__r�inspectZ	signature�
ValueError)�funcZas_instanceZeat_selfZsig_funcrrr�_get_signature_objectKs$


r-FcsNt|||���dkrdS�\}��fdd�}t||�|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�
__signature__)r,r#�	skipfirst�instancer3r)r2r�_check_signatureks

r9c	Cs>x8dD]0}yt||t||��Wqtk
r4YqXqWdS)N)�__name__�__doc__�__text_signature__�
__module__�__defaults__�__kwdefaults__)�setattr�getattrr()r,�funcopy�	attributerrrr4wsr4cCs@t|t�rdSt|tttf�r(t|j�St|dd�dk	r<dSdS)NTr)F)r r�staticmethod�classmethodr�	_callable�__func__rA)rrrrrF�s

rFcCst|�ttfkS)N)r�list�tuple)rrrr�_is_list�srJcCsHt|t�st|dd�dk	Sx(|f|jD]}|j�d�dk	r(dSq(WdS)Nr)TF)r rrA�__mro__�__dict__�get)r�baserrr�_instance_callable�s
rOcs�t|�sdSt|t�}t|||�}|dkr.|S|\}��fdd�}t||�|j}|��s^d}||d�}d|}	t|	|�||}
t|
|��|
S)Ncs�j||�dS)N)r.)r0r1)r2rrr3�sz _set_signature.<locals>.checksigrB)Z
_checksig_r#zYdef %s(*args, **kwargs):
    _checksig_(*args, **kwargs)
    return mock(*args, **kwargs))	rFr rr-r4r:�isidentifier�exec�_setup_func)r#�originalr8r7�resultr,r3r�context�srcrBr)r2r�_set_signature�s$



rWcs���_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)r0r1)r#rrrX�sz'_setup_func.<locals>.assert_called_withcs�j||�S)N)�
assert_called)r0r1)r#rrrY�sz"_setup_func.<locals>.assert_calledcs�j||�S)N)�assert_not_called)r0r1)r#rrrZ�sz&_setup_func.<locals>.assert_not_calledcs�j||�S)N)�assert_called_once)r0r1)r#rrr[�sz'_setup_func.<locals>.assert_called_oncecs�j||�S)N)�assert_called_once_with)r0r1)r#rrr\�sz,_setup_func.<locals>.assert_called_once_withcs�j||�S)N)�assert_has_calls)r0r1)r#rrr]�sz%_setup_func.<locals>.assert_has_callscs�j||�S)N)�assert_any_call)r0r1)r#rrr^�sz$_setup_func.<locals>.assert_any_callcs:t��_t��_����j}t|�r6|�k	r6|��dS)N)�	_CallList�method_calls�
mock_calls�
reset_mock�return_valuer)�ret)rBr#rrrb�sz_setup_func.<locals>.reset_mockFr)r#r�called�
call_count�	call_argsr_�call_args_listr`rarc�side_effect�_mock_childrenrXr\r]r^rbrYrZr[r6�_mock_delegate)rBr#r2rXrYrZr[r\r]r^rbr)rBr#rrR�s<rRcCsd|dd�|kS)Nz__%s__����r)rrrr�	_is_magic�srnc@s$eZdZdd�Zdd�Zdd�ZdS)�_SentinelObjectcCs
||_dS)N)r)�selfrrrrr'�sz_SentinelObject.__init__cCs
d|jS)Nzsentinel.%s)r)rprrr�__repr__�sz_SentinelObject.__repr__cCs
d|jS)Nzsentinel.%s)r)rprrr�
__reduce__sz_SentinelObject.__reduce__N)r:r=�__qualname__r'rqrrrrrrro�sroc@s$eZdZdd�Zdd�Zdd�ZdS)�	_SentinelcCs
i|_dS)N)�
_sentinels)rprrrr'sz_Sentinel.__init__cCs|dkrt�|j�|t|��S)N�	__bases__)r(ru�
setdefaultro)rprrrr�__getattr__
sz_Sentinel.__getattr__cCsdS)Nrr)rprrrrrsz_Sentinel.__reduce__N)r:r=rsr'rxrrrrrrrtsrtcCs$t|�ttttfkr t|�|�S|S)N)r�dictrHrI�set)�valuerrr�_copysr|rc�_mock_return_valueri�_mock_side_effect�_mock_parent�_mock_new_parent�
_mock_name�_mock_new_namecCs8t�|�d|}||fdd�}||fdd�}t||�S)NZ_mock_cSs"|j}|dkrt||�St||�S)N)rkrA)rpr�	_the_namer2rrr�_get+s
z"_delegating_property.<locals>._getcSs*|j}|dkr||j|<nt|||�dS)N)rkrLr@)rpr{rr�r2rrr�_set0sz"_delegating_property.<locals>._set)�_allowed_names�add�property)rr�r�r�rrr�_delegating_property(s

r�c@seZdZdd�Zdd�ZdS)r_cCsnt|t�st�||�St|�}t|�}||kr2dSx6td||d�D] }||||�}||krFdSqFWdS)NFr�T)r rH�__contains__�len�range)rpr{Z	len_valueZlen_self�iZsub_listrrrr�=s
z_CallList.__contains__cCst�t|��S)N)�pprintZpformatrH)rprrrrqKsz_CallList.__repr__N)r:r=rsr�rqrrrrr_;sr_cCs�t|�}t|�sdS|js4|js4|jdk	s4|jdk	r8dS|}x|dk	rZ||krRdS|j}q>W|rl||_||_|r|||_||_dS)NFT)r&rr�r�rr�)�parentr{r�new_name�_parentrrr�_check_and_set_parentOs&



r�c@s$eZdZdd�Zdd�Zdd�ZdS)�	_MockItercCst|�|_dS)N)�iterr)rprrrrr'ksz_MockIter.__init__cCs|S)Nr)rprrr�__iter__msz_MockIter.__iter__cCs
t|j�S)N)�nextr)rprrr�__next__osz_MockIter.__next__N)r:r=rsr'r�r�rrrrr�jsr�c@seZdZeZdZdd�ZdS)�BaseNcOsdS)Nr)rpr0r1rrrr'usz
Base.__init__)r:r=rsrr}r~r'rrrrr�rsr�c@sTeZdZdd�ZdGdd�Zdd	�ZdHd
d�ZdIdd
�Zdd�Zdd�Z	dZ
eee	e
�Zedd��Z
ed�Zed�Zed�Zed�Zed�Zdd�Zdd�Zeee�ZdJddd�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%d=d>�Z&d?d@�Z'dKdAdB�Z(dCdD�Z)dEdF�Z*dS)Lr
cOs$t|j|fd|ji�}t�|�}|S)Nr;)rr:r;�object�__new__)�clsr0�kw�newr8rrrr�}s
zNonCallableMock.__new__N�FcKs�|dkr|}|j}
||
d<||
d<||
d<||
d<d|
d<|dk	rJ|}d}|
dkrZ|dk	}
|�|||	|
�i|
d<||
d	<d|
d
<d|
d<d|
d<d
|
d<t�|
d<t�|
d<t�|
d<||
d<|r�|jf|�tt|��||||||�dS)Nrr�r�r�F�_mock_sealedTrj�_mock_wrapsrkZ_mock_calledZ_mock_call_argsrZ_mock_call_countZ_mock_call_args_listZ_mock_mock_callsr`�_mock_unsafe)rL�_mock_add_specr_�configure_mock�_safe_superr
r')rp�specrr�spec_setr��_spec_state�	_new_name�_new_parent�_spec_as_instance�	_eat_selfZunsafer1rLrrrr'�s:




zNonCallableMock.__init__cCs0t|�}d|_d|_d|_d|_t|||�dS)Nr�)r&rr�r�r�r@)rpr#rCZ
inner_mockrrr�attach_mock�szNonCallableMock.attach_mockcCs|�||�dS)N)r�)rpr�r�rrr�
mock_add_spec�szNonCallableMock.mock_add_specc	Cszd}d}|dk	rPt|�sPt|t�r(|}nt|�}t|||�}|oF|d}t|�}|j}||d<||d<||d<||d<dS)Nr��_spec_class�	_spec_set�_spec_signature�
_mock_methods)rJr r�
_get_classr-�dirrL)	rpr�r�r�r�r�r�ZresrLrrrr��s
zNonCallableMock._mock_add_speccCs8|j}|jdk	r|jj}|tkr4|j|dd�}||_|S)Nz())r�r�)r}rkrcr�_get_child_mock)rprdrrrZ__get_return_value�s

z"NonCallableMock.__get_return_valuecCs,|jdk	r||j_n||_t||dd�dS)Nz())rkrcr}r�)rpr{rrrZ__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)rprrr�	__class__�s
zNonCallableMock.__class__rerfrgrhracCsN|j}|dkr|jS|j}|dk	rJt|�sJt|t�sJt|�sJt|�}||_|S)N)rkr~ri�callabler r�r")rp�	delegatedZsfrrrZ__get_side_effectsz!NonCallableMock.__get_side_effectcCs(t|�}|j}|dkr||_n||_dS)N)�	_try_iterrkr~ri)rpr{r�rrrZ__set_side_effects
z!NonCallableMock.__set_side_effect)rcricCs�|dkrg}t|�|krdS|�t|��d|_d|_d|_t�|_t�|_t�|_|r^t	|_
|rhd|_x0|j�
�D]"}t|t�st|tkr�qt|�|�qtW|j
}t|�r�||k	r�|�|�dS)NFr)�id�appendrergrfr_rarhr`rr}r~rj�valuesr �
_SpecState�_deletedrbr)rpZvisitedrcri�childrdrrrrbs,zNonCallableMock.reset_mockcKs`xZt|��dd�d�D]B\}}|�d�}|��}|}x|D]}t||�}q:Wt|||�qWdS)NcSs|d�d�S)Nr�.)�count)�entryrrr�<lambda>I�z0NonCallableMock.configure_mock.<locals>.<lambda>)�keyr�)�sorted�items�split�poprAr@)rpr1�arg�valr0�finalrr�rrrr�<s	


zNonCallableMock.configure_mockcCs�|dkrt|��n:|jdk	r<||jks.|tkrLtd|��nt|�rLt|��|jsd|�d�rdt|��|j�|�}|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)N>r�r�zMock object has no attribute %r)�assertZassret)r�rrr�r�)r(r��_all_magicsrnr�rrjrMr�r�rAr�r r�rr�r�r8r�r)rprrTrrrrrxRs6






zNonCallableMock.__getattr__cCs�|jg}|j}|}d}|dgkr$d}t�}xT|dk	r~|}|�|j|�d}|jdkrZd}|j}t|�|krnP|�t|��q,Wtt|��}|jp�d}t	|�dkr�|ddkr�|d7}||d<d�
|�S)Nr�z()r�r#r�)z()z().r)r�r�rzr�r�r�rH�reversedr�r��join)rpZ
_name_listr�Zlast�dot�seenZ_firstrrr�_extract_mock_namexs0



z"NonCallableMock._extract_mock_namecCs^|��}d}|dkrd|}d}|jdk	rDd}|jr8d}||jj}dt|�j||t|�fS)Nr�)r#zmock.z name=%rz spec=%rz spec_set=%rz<%s%s%s id='%s'>)r�r�r�r:rr�)rprZname_stringZspec_stringrrrrq�s
zNonCallableMock.__repr__cCsvtst�|�S|jpg}tt|��}t|j�}dd�|j�	�D�}dd�|D�}dd�|D�}t
t||||��S)NcSsg|]\}}|tk	r|�qSr)r�)rZm_nameZm_valuerrr�
<listcomp>�sz+NonCallableMock.__dir__.<locals>.<listcomp>cSsg|]}|�d�s|�qS)r)r)r�errrr��scSs"g|]}|�d�rt|�r|�qS)r)rrn)rr�rrrr��s)r	r��__dir__r�r�rrHrLrjr�r�rz)rp�extrasZ	from_typeZ	from_dictZfrom_child_mocksrrrr��s


zNonCallableMock.__dir__csT|tkrt��||�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,|dkr�|�_dSt
�|||��r|�j|<�j�rFt�|��sF����d|��}td|����t��||�S)Nz!Mock object has no attribute '%s'z.Attempting to set unsupported magic method %r.cs��f|�|�S)Nr)r0r�)rSrprrr��r�z-NonCallableMock.__setattr__.<locals>.<lambda>r�r�zCannot set )r�r��__setattr__r�r�rLr(�_unsupported_magicsr�rr@r�_get_methodr�rjr�r�r%r�)rprr{�msg�	mock_namer)rSrprr��s8



zNonCallableMock.__setattr__cCs�|tkr2|t|�jkr2tt|�|�||jkr2dS|j�|t�}||jkr\tt|��	|�n|t
krlt|��|tk	r||j|=t
|j|<dS)N)r�rrL�delattrrjrM�_missingr�r
�__delattr__r�r()rprrrrrr��s

zNonCallableMock.__delattr__cCs|jpd}t|||�S)Nr#)r��_format_call_signature)rpr0r1rrrr�_format_mock_call_signature�s
z+NonCallableMock._format_mock_call_signaturecCsDd}|�||�}|j}t|�dkr.|dd�}|j|�}|||fS)Nz!Expected call: %s
Actual call: %s�r�)r�rgr�)rpr0r1�message�expected_stringrgZ
actual_stringrrr�_format_mock_failure_message�s
z,NonCallableMock._format_mock_failure_messagecCsl|s
|jSd}|�dd��d�}|j}x@|D]8}|�|�}|dksLt|t�rPPq,t|�}|j}|j}q,W|S)Nz()r�r�)r��replacer�rjrMr r�r&)rprr2�namesZchildrenr�rrr�_get_call_signature_from_names


z-NonCallableMock._get_call_signature_from_namec
Cs�t|t�r&t|�dkr&|�|d�}n|j}|dk	r�t|�dkrNd}|\}}n
|\}}}y||j||�fStk
r�}z
|�d�Sd}~XYq�Xn|SdS)Nrlrr�)r rIr�r�r�r.�	TypeError�with_traceback)rp�_callr2rr0r1r�rrr�
_call_matcher(s

zNonCallableMock._call_matchercCs.|}|jdkr*d|jpd|jf}t|��dS)Nrz7Expected '%s' to not have been called. Called %s times.r#)rfr��AssertionError)r/rpr�rrrrZBs

z!NonCallableMock.assert_not_calledcCs(|}|jdkr$d|jpd}t|��dS)Nrz"Expected '%s' to have been called.r#)rfr�r�)r/rpr�rrrrYKs

zNonCallableMock.assert_calledcCs.|}|jdks*d|jpd|jf}t|��dS)Nr�z8Expected '%s' to have been called once. Called %s times.r#)rfr�r�)r/rpr�rrrr[Ts

z"NonCallableMock.assert_called_oncecs||��jdkr(�����}td|f�����fdd�}����f�}���j�}||krxt|t�rh|nd}t|��|�dS)NzExpected call: %s
Not calledcs�����}|S)N)r�)r�)r0r1rprr�_error_messagegsz:NonCallableMock.assert_called_with.<locals>._error_message)rgr�r�r�r �	Exception)r/r0r1�expectedr��actual�causer)r0r1rprrX]s
z"NonCallableMock.assert_called_withcOs6|}|jdks*d|jpd|jf}t|��|j||�S)Nr�z1Expected '%s' to be called once. Called %s times.r#)rfr�r�rX)r/r0r1rpr�rrrr\qs
z'NonCallableMock.assert_called_once_withc		s��fdd�|D�}tdd�|D�d�}t�fdd��jD��}|s�||kr�|dkrXd}nd�dd�|D��}td	|t|��jf�|�dSt|�}g}x:|D]2}y|�|�Wq�tk
r�|�|�Yq�Xq�W|r�td
t	|�f�|�dS)Ncsg|]}��|��qSr)r�)r�c)rprrr��sz4NonCallableMock.assert_has_calls.<locals>.<listcomp>css|]}t|t�r|VqdS)N)r r�)rr�rrr�	<genexpr>�sz3NonCallableMock.assert_has_calls.<locals>.<genexpr>c3s|]}��|�VqdS)N)r�)rr�)rprrr��szCalls not found.z+Error processing expected calls.
Errors: {}cSsg|]}t|t�r|nd�qS)N)r r�)rr�rrrr��sz%s
Expected: %r
Actual: %rz%r not all found in call list)
r�r_ra�formatr�rH�remover+r�rI)	rpZcallsZ	any_orderr�r�Z	all_callsZproblemZ	not_foundZkallr)rprr]|s4


z NonCallableMock.assert_has_callscsZ��||f�}�fdd��jD�}||krVt|t�r8|nd}��||�}td|�|�dS)Ncsg|]}��|��qSr)r�)rr�)rprrr��sz3NonCallableMock.assert_any_call.<locals>.<listcomp>z%s call not found)r�rhr r�r�r�)rpr0r1r�r�r�r�r)rprr^�szNonCallableMock.assert_any_callcKsxt|�}t|t�s2t|t�r"t}q<t|t�r<t}n
|jd}|jrnd|krVd|dnd}|�	�|}t
|��|f|�S)Nr�rr�z())rr�
CallableMixinrrr
rrKr�r�r()rpr��_type�klassrCr�rrrr��s



zNonCallableMock._get_child_mock)NNNNNNr�NFNF)F)FF)N)F)+r:r=rsr�r'r�r�r�Z"_NonCallableMock__get_return_valueZ"_NonCallableMock__set_return_valueZ"_NonCallableMock__return_value_docr�rcr�r�rerfrgrhraZ!_NonCallableMock__get_side_effectZ!_NonCallableMock__set_side_effectrirbr�rxr�rqr�r�r�r�r�r�r�rZrYr[rXr\r]r^r�rrrrr
zsT

*
	


& '
!			
*r
cCsF|dkr|St|�r|St|�r$|Syt|�Stk
r@|SXdS)N)r"rFr�r�)rrrrr��sr�c
@sBeZdZddedddddddf
dd�Zdd�Zdd�Zd	d
�ZdS)r�Nr�c	Ks6||jd<tt|�j|||||||	|
f|�||_dS)Nr})rLr�r�r'ri)rpr�rircrrr�r�r�r�r�r1rrrr'�s



zCallableMixin.__init__cOsdS)Nr)rpr0r1rrrr5�szCallableMixin._mock_check_sigcOs|j||�|j||�S)N)r5�
_mock_call)r/r0r1rrrr)�szCallableMixin.__call__cOs�|}d|_|jd7_t||fdd�}||_|j�|�t�}|jdk	}|j}|j	}|dk}	|j
�td||f��|j}
x�|
dk	�r*|r�|
j�t|||f��|
jdk	}|r�|
jd|}t|||f�}|
j
�|�|
j	�r|	r�d}nd}|
j	dk}	|
j	||}|
j}
t
|
�}
|
|k�rP|�|
�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�)rerf�_Callrgrhr�rzrr�r�rar�r`r�r�rir"rFr�rr}rcr�)r/r0r1rpr�r�Zdo_method_callsZmethod_call_nameZmock_call_nameZ	is_a_callr�Zthis_mock_callr�Z_new_parent_idZeffectrTrrrr��s`









zCallableMixin._mock_call)r:r=rsrr'r5r)r�rrrrr��sr�c@seZdZdS)rN)r:r=rsrrrrrIs1rcCs2y
t||�Stk
r,t|�t||�SXdS)N)rAr(�
__import__)�thing�comp�import_pathrrr�_dot_lookup~s

rcCsF|�d�}|�d�}t|�}x$|D]}|d|7}t|||�}q"W|S)Nr�rz.%s)r�r�r�r)�targetZ
componentsrr�r�rrr�	_importer�s


rcCs
t|d�S)N�is_local)r%)�patcherrrr�_is_started�src@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+�getterrCr��new_callabler��createZ	has_localr��autospecr1�additional_patchers)
rprrCr�r�r
r�rr	r1rrrr'�s$z_patch.__init__c
CsHt|j|j|j|j|j|j|j|j|j	�	}|j
|_
dd�|jD�|_|S)NcSsg|]}|���qSr)�copy)r�prrrr��sz_patch.copy.<locals>.<listcomp>)rrrCr�r�r
r�rr	r1�attribute_namer)rprrrrr
�sz_patch.copycCst|t�r|�|�S|�|�S)N)r r�decorate_class�decorate_callable)rpr,rrrr)�s

z_patch.__call__cCsRxLt|�D]@}|�tj�sq
t||�}t|d�s2q
|��}t||||��q
W|S)Nr))r�rr�TEST_PREFIXrAr%r
r@)rpr��attr�
attr_valuerrrrr�s

z_patch.decorate_classcs<t�d�r�j�|��St����fdd���|g�_�S)N�	patchingsc	srg}t���\}xB�jD]8}|�|�}|jdk	r:|�|�q|jtkr|�|�qW|t	|�7}�||�SQRXdS)N)
�
contextlib�	ExitStackr�
enter_contextr�updater�rr�rI)r0Zkeywargs�
extra_args�
exit_stack�patchingr�)r,�patchedrrr�s



z)_patch.decorate_callable.<locals>.patched)r%rr�r)rpr,r)r,rrr�s
z_patch.decorate_callablec	Cs�|��}|j}t}d}y|j|}Wn$ttfk
rHt||t�}YnXd}|tkrft|t	�rfd|_
|j
s�|tkr�td||f��||fS)NFTz!%s does not have the attribute %r)rrCrrLr(�KeyErrorrA�	_builtinsr rr
)rprrrS�localrrr�get_original�sz_patch.get_originalcCsn|j|j|j}}}|j|j}}|j}|��|_|dkr@d}|dkrLd}|dkrXd}|dk	rp|dk	rptd��|dk	s�|dk	r�|dkr�td��|�	�\}}|t
k�rR|dk�rRd}	|dkr�|}|dkr�|}d}n&|dk	r�|dkr�|}d}n|dkr�|}|dk	�s|dk	�r.|t
k�rtd��t|t��r.d}	t
}
i}|dk	�rF|}
nN|dk	�sZ|dk	�r�|}|dk	�rl|}t|��r�d|k}
n
t|�}
|
�r�t}
|dk	�r�||d<|dk	�r�||d	<t|
t��r�t|
t��r�|j�r�|j|d
<|�|�|
f|�}|	�r�t|��r�|}|dk	�r|}t|��s0t|��s0t}
|�d
�|
f|dd�|��|_nl|dk	�r�|t
k	�rntd
��|t
k�r�td��t|�}|dk�r�|}t|f||jd�|��}n|�r�td��|}||_||_t��|_yrt |j|j|�|j!dk	�rHi}|jt
k�r|||j!<x2|j"D](}|j�#|�}|jt
k�r|�|��qW|S|S|j$t%�&���sd�YnXdS)NFzCan't specify spec and autospec)TNz6Can't provide explicit spec_set *and* spec or autospecTz!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)'r�r�r�rr1r	rrr�r!rr rrrJr�rrr
rCrrrOr�rc�boolr�
temp_originalrrr�_exit_stackr@rrr�__exit__�sys�exc_info)rpr�r�r�rr1r	rSr Zinherit�Klass�_kwargsZ	this_specZnot_callableZnew_attrrrr�rrr�	__enter__s�





















z_patch.__enter__cGs�t|�std��|jr4|jtk	r4t|j|j|j�n>t|j|j�|j	srt
|j|j�r`|jdkrrt|j|j|j�|`|`|`|j}|`|j|�S)Nz stop called on unstarted patcher)r;r=r>�__annotations__r?)
r�RuntimeErrorrr$rr@rrCr�r
r%r%r&)rpr(rrrrr&�s
z_patch.__exit__cCs|��}|j�|�|S)N)r+�_active_patchesr�)rprTrrr�start�sz_patch.startcCs4y|j�|�Wntk
r$YnX|�ddd�S)N)r.r�r+r&)rprrr�stop�s
z_patch.stop)r:r=rsrr.r'r
r)rrr!r+r&r/r0rrrrr�s
rc	sPy��dd�\�}Wn&ttfk
r:td�f��YnX�fdd�}||fS)Nr�r�z.Need a valid target to patch. You supplied: %rcst��S)N)rr)rrrr��r�z_get_target.<locals>.<lambda>)�rsplitr�r+)rrCrr)rr�_get_target�sr2c

s>t��tkrt��d����fdd�}	t|	||||||||�	S)Nz3 must be the actual object to be patched, not a strcs�S)Nrr)rrrr��r�z_patch_object.<locals>.<lambda>)r�strr�r)
rrCr�r�r
r�rr	r1rr)rr�
_patch_object�s
r4c
s�t��tkr�fdd�}n�fdd�}|s2td��t|���}|d\}	}
t||	|
|||||i�	}|	|_xB|dd�D]2\}	}
t||	|
|||||i�	}|	|_|j�|�qvW|S)Ncst��S)N)rr)rrrr��r�z!_patch_multiple.<locals>.<lambda>cs�S)Nrr)rrrr��r�z=Must supply at least one keyword argument with patch.multiplerr�)	rr3r+rHr�rrrr�)
rr�r
r�rr	r1rr�rCr�rZthis_patcherr)rr�_patch_multiple�s&

r5c

Ks$t|�\}}	t||	|||||||�	S)N)r2r)
rr�r�r
r�rr	r1rrCrrrrsE
rc@sNeZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	eZ
e	ZdS)�_patch_dictrFcKs,||_t|�|_|j�|�||_d|_dS)N)�in_dictryr�r�clear�	_original)rpr7r�r8r1rrrr'ts

z_patch_dict.__init__cs.t�t�r����St����fdd��}|S)Ncs"���z
�||�S���XdS)N)r6�
_unpatch_dict)r0r�)�frprr�_inner�s
z$_patch_dict.__call__.<locals>._inner)r rrr)rpr;r<r)r;rprr)}s

z_patch_dict.__call__cCs\xVt|�D]J}t||�}|�tj�r
t|d�r
t|j|j|j	�}||�}t
|||�q
W|S)Nr))r�rArrrr%r6r7r�r8r@)rpr�rrZ	decoratorZ	decoratedrrrr�s

z_patch_dict.decorate_classcCs|��dS)N)r6)rprrrr+�sz_patch_dict.__enter__cCs�|j}t|jt�rt|j�|_|j}|j}y|��}Wn2tk
rhi}x|D]}||||<qPWYnX||_|r|t	|�y|�
|�Wn.tk
r�x|D]}||||<q�WYnXdS)N)r�r r7r3rr8r
r(r9�_clear_dictr)rpr�r7r8rSr�rrrr6�s&

z_patch_dict._patch_dictcCsV|j}|j}t|�y|�|�Wn.tk
rPx|D]}||||<q8WYnXdS)N)r7r9r=rr()rpr7rSr�rrrr:�s
z_patch_dict._unpatch_dictcGs|��dS)NF)r:)rpr0rrrr&�sz_patch_dict.__exit__N)rF)r:r=rsr'r)rr+r6r:r&r/r0rrrrr6Ws
	
r6cCsBy|��Wn0tk
r<t|�}x|D]
}||=q*WYnXdS)N)r8r(rH)r7�keysr�rrrr=�s
r=cCs xttj�D]}|��qWdS)N)r�rr.r0)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)rrArrrr��s�__get__�__set__�
__delete__�__reversed__�__missing__rr�
__reduce_ex__Z__getinitargs__�__getnewargs__�__getstate__�__setstate__�
__getformat__Z
__setformat__rqr��__subclasses__�
__format__�__getnewargs_ex__cs�fdd�}||_|S)Ncs�|f|�|�S)Nr)rpr0r�)r,rr�methodsz_get_method.<locals>.method)r:)rr,rOr)r,rr�sr�cCsh|]}d|�qS)z__%s__r)rrOrrrrsrxr�r'r��__prepare__�__instancecheck__�__subclasscheck__�__del__cCs
t�|�S)N)r��__hash__)rprrrr�r�r�cCs
t�|�S)N)r��__str__)rprrrr�r�cCs
t�|�S)N)r��
__sizeof__)rprrrr�r�)rTrUrVr�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__r}r�NotImplemented)�other�ret_val)rprrra0sz_get_eq.<locals>.__eq__r)rprar)rpr�_get_eq/srecs�fdd�}|S)Ncs �jjtk	rtS�|krdStS)NF)�__ne__r}rrb)rc)rprrrf:s
z_get_ne.<locals>.__ne__r)rprfr)rpr�_get_ne9srgcs�fdd�}|S)Ncs �jj}|tkrtg�St|�S)N)r�r}rr�)rd)rprrr�Csz_get_iter.<locals>.__iter__r)rpr�r)rpr�	_get_iterBsrh)rarfr�cCs�t�|t�}|tk	r||_dSt�|�}|dk	rdy||�}Wntk
rXt|�}YnX||_dSt�|�}|dk	r�||�|_dS)N)�_return_valuesrMrrc�_calculate_return_valuer(�_side_effect_methodsri)r#rOrZfixedZreturn_calculatorrcZ
side_effectorrrr�_set_return_valueTs

rlc@seZdZdd�Zdd�ZdS)�
MagicMixincOs&|��tt|�j||�|��dS)N)�_mock_set_magicsr�rmr')rpr0r�rrrr'lszMagicMixin.__init__cCs�t}t|dd�dk	rTt�|j�}t�}t|}x$|D]}|t|�jkr4t||�q4W|tt|�j�}t|�}x|D]}t||t	||��qtWdS)Nr�)
�_magicsrA�intersectionr�rzrrLr�r@�
MagicProxy)rpZthese_magicsZ
remove_magicsr�r�rrrrnrs

zMagicMixin._mock_set_magicsN)r:r=rsr'rnrrrrrmksrmc@seZdZddd�ZdS)rFcCs|�||�|��dS)N)r�rn)rpr�r�rrrr��sz"NonCallableMagicMock.mock_add_specN)F)r:r=rsr�rrrrr�src@seZdZddd�ZdS)rFcCs|�||�|��dS)N)r�rn)rpr�r�rrrr��szMagicMock.mock_add_specN)F)r:r=rsr�rrrrr�src@s.eZdZdd�Zdd�Zdd�Zd
dd	�ZdS)rqcCs||_||_dS)N)rr�)rprr�rrrr'�szMagicProxy.__init__cOs|��}|||�S)N)�create_mock)rpr0r1�mrrrr)�szMagicProxy.__call__cCs8|j}|j}|j|||d�}t|||�t|||�|S)N)rr�r�)rr�r�r@rl)rpr�r�rsrrrrr�szMagicProxy.create_mockNcCs|��S)N)rr)rprr�rrrrB�szMagicProxy.__get__)N)r:r=rsr'r)rrrBrrrrrq�s	rqc@s$eZdZdd�Zdd�Zdd�ZdS)�_ANYcCsdS)NTr)rprcrrrra�sz_ANY.__eq__cCsdS)NFr)rprcrrrrf�sz_ANY.__ne__cCsdS)Nz<ANY>r)rprrrrq�sz
_ANY.__repr__N)r:r=rsrarfrqrrrrrt�srtcCsdd|}d}d�dd�|D��}d�dd�t|���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�r{rrrr��s)r�r�r�)rr0r1r�Zformatted_args�args_stringZ
kwargs_stringrrrr��sr�c@s^eZdZddd�Zddd	�Zd
d�ZejZdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)r�rr�NFTcCs�d}i}t|�}|dkr$|\}}}nr|dkrd|\}	}
t|	t�rX|	}t|
t�rR|
}qb|
}q�|	|
}}n2|dkr�|\}t|t�r�|}nt|t�r�|}n|}|r�t�|||f�St�||||f�S)Nrr�rlr�)r�r r3rIr�)r�r{rr�r��	from_kallr0r1�_len�first�secondrrrr��s.



z
_Call.__new__cCs||_||_||_dS)N)r�r�_mock_from_kall)rpr{rr�r�rwrrrr'sz_Call.__init__cCsf|tkrdSyt|�}Wntk
r,dSXd}t|�dkrH|\}}n
|\}}}t|dd�rzt|dd�rz|j|jkrzdSd}|dkr�di}}n�|dkr�|\}}}n�|d	kr�|\}	t|	t�r�|	}i}n"t|	t�r�|	}di}}nd}|	}nV|dk�r>|\}
}t|
t��r2|
}t|t��r&|i}}n
d|}}n
|
|}}ndS|�rV||k�rVdS||f||fkS)
NTFr�rlrrrr�r�)rr�r�rArr rIr3)rprcZ	len_otherZ	self_nameZ	self_argsZself_kwargsZ
other_nameZ
other_argsZother_kwargsr{ryrzrrrrasP




z_Call.__eq__cOs<|jdkrtd||fdd�S|jd}t|j||f||d�S)Nr�z())r)rr�)r�r�)rpr0r1rrrrr)Ys

z_Call.__call__cCs2|jdkrt|dd�Sd|j|f}t||dd�S)NF)rrwz%s.%s)rr�rw)r�r�)rprrrrrrxas
z_Call.__getattr__cOs|�d�||�S)Nr�)rx)rpr0r1rrrr�hsz_Call.countcOs|�d�||�S)N�index)rx)rpr0r1rrrr|ksz_Call.indexcCs||js&|jpd}|�d�r"d|}|St|�dkr@d}|\}}n0|\}}}|sTd}n|�d�shd|}nd|}t|||�S)Nrz()zcall%srlzcall.%s)r{r�rr�r�)rprr0r1rrrrqns





z_Call.__repr__cCs8g}|}x"|dk	r*|jr"|�|�|j}q
Wtt|��S)N)r{r�rr_r�)rpZvalsr�rrr�	call_list�s


z_Call.call_list)rr�NFT)rNNFT)r:r=rsr�r'rar�rfr)rxr�r|rqr}rrrrr��s

7r�)rwc	Ks$t|�rt|�}t|t�}d|i}|r0d|i}n|dkr<i}|rL|rLd|d<|�|�t}t�|�rji}n"t|�sxt}n|r�|r�t	|�s�t}|�
d|�}|}	|dkr�d}	|f|||	|d�|��}
t|t�r�t|
|�}
nt
||
||�|dk	r�|s�|
|j|<|�r$|�s$d|k�r$t||dd	|
d
�|
_x�t|�D]�}t|��r@�q.yt||�}Wntk
�rh�w.YnXd|i}|�r�d|i}t|t��s�t|||
||�}
|
|
j|<nZ|
}t|t��r�|
j}t|||�}||d<tf||||d�|��}
|
|
j|<t
||
|d
�t|
t��r.t|
||
��q.W|
S)Nr�r�Tr�rr�)r�r�r�rrcz())r8r"r�r�)r�rr�r�)r7)rJrr rrr*ZisdatadescriptorrFrrOr�r$rWr9rjrrcr�rnrAr(r�r#�
_must_skipr@)r�r�r8r�r"r1�is_typer*r)r�r#r�rSr�r�r7rrrr�st










rcCstt|t�s$|t|di�krdS|j}xJ|jD]@}|j�|t�}|tkrHq,t|tt	f�rZdSt|t
�rh|SdSq,W|S)NrLF)r rrAr�rKrLrMrrDrEr$)r�r�rr�rTrrrr~	s

r~cCs$y|jStk
rt|�SXdS)N)r�r(r)rrrrr�)	sr�c@seZdZddd�ZdS)r�FNcCs(||_||_||_||_||_||_dS)N)r��idsr�r�r8r)rpr�r�r�rr�r8rrrr'3	sz_SpecState.__init__)FNNNF)r:r=rsr'rrrrr�1	sr�cCs"t|t�rt�|�St�|�SdS)N)r �bytes�io�BytesIO�StringIO)�	read_datarrr�
_to_streamH	s

r�r�cs&t��}|dg���fdd�}��fdd�}��fdd����fdd����fd	d
�}tdkr�ddl}ttt|j���tt|j����a|dkr�t	dt
d
�}t	td����j_d�j
_d�j_d�j_d�j_|�j_���d<�d�j_|�j_��j_|�j_����fdd�}||_�|_|S)Ncs$�jjdk	r�jjS�dj||�S)Nr)�	readlinesrc)r0r1)�_state�handlerr�_readlines_side_effect^	sz)mock_open.<locals>._readlines_side_effectcs$�jjdk	r�jjS�dj||�S)Nr)�readrc)r0r1)r�r�rr�_read_side_effectc	sz$mock_open.<locals>._read_side_effectc?s(��EdHx�dj||�VqWdS)Nr)�readline)r0r1)�_iter_side_effectr�rr�_readline_side_effecth	sz(mock_open.<locals>._readline_side_effectc3s8�jjdk	rx�jjVqWx�dD]
}|Vq&WdS)Nr)r�rc)�line)r�r�rrr�m	s
z$mock_open.<locals>._iter_side_effectcs �jjdk	r�jjSt�d�S)Nr)r�rcr�r)r�r�rr�_next_side_effectt	sz$mock_open.<locals>._next_side_effectr�open)rr�)r�r�cs6t���d<�jj�dkr2���d<�d�j_tS)Nrr�)r�r�rir)r0r1)r�r�r�r�rr�
reset_data�	s

zmock_open.<locals>.reset_data)r��	file_spec�_iorHrzr��
TextIOWrapper�unionr�rr�r+rc�writer�r�r�rir�r�)r#r�Z
_read_datar�r�r�r�r�r)r�r�r�r�r�rrO	s8"

rc@s$eZdZdd�Zdd�Zdd�ZdS)r
cKs
tf|�S)N)r)rpr1rrrr��	szPropertyMock._get_child_mockcCs|�S)Nr)rprZobj_typerrrrB�	szPropertyMock.__get__cCs||�dS)Nr)rprr�rrrrC�	szPropertyMock.__set__N)r:r=rsr�rBrCrrrrr
�	s	r
c	Cs`d|_xTt|�D]H}yt||�}Wntk
r8wYnXt|t�sFq|j|krt|�qWdS)NT)r�r�rAr(r r
r�r)r#rrsrrrr�	s


r)F)F)NFNNN)FFNN)Nr�)r�__all__�__version__r�r*r�r'�builtinsr�typesrr�	functoolsrrr�r�
BaseExceptionr!�platformr�langZ	Throwabler	�superr�rr"r&r-r9r4rFrJrOrWrRrnr�rortrr�MISSINGr�ZDELETEDr�r|r�r�rHr_r�r�r�r
r�r�rrrrrr2r4r5rr6r=r?ryZmultipleZstopallrZ
magic_methodsZnumericsr�r�Zinplace�rightZ
_non_defaultsr�ror�r�rjrbrirergrhrkrlrmrrrqrtrr�rIr�rrr~r�r�rrar$r�r�rr
rrrrr�<module>s
	 



5Zi5
1Jv	

	
,

w
N