AlkantarClanX12

Your IP : 18.116.86.160


Current Path : /lib64/python3.6/unittest/__pycache__/
Upload File :
Current File : //lib64/python3.6/unittest/__pycache__/mock.cpython-36.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)z�
    Given an arbitrary, possibly callable object, try to create a suitable
    signature object.
    Return a (reduced func, signature) tuple, or None.
    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)ztGiven an object, return True if the object is callable.
    For classes, return True if instances would be callable.r$NTF)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@s eZdZdZdd�Zdd�ZdS)�_SentinelObjectz!A unique, named, sentinel object.cCs
||_dS)N)r)�selfrrrrr!�sz_SentinelObject.__init__cCs
d|jS)Nzsentinel.%s)r)rfrrr�__repr__�sz_SentinelObject.__repr__N)r5r8�__qualname__r6r!rgrrrrre�srec@s eZdZdZdd�Zdd�ZdS)�	_SentinelzAAccess attributes to return a named object, usable as a sentinel.cCs
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)r5r8rhr6r!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@sHeZdZdZdd�ZdDdd�Zd	d
�ZdEdd�ZdFd
d�Zdd�Z	dd�Z
dZee	e
e�Z
edd��Zed�Zed�Zed�Zed�Zed�Zdd�Zdd�Zeee�ZdGddd�d d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Z d2d3�Z!d4d5�Z"d6d7�Z#d8d9�Z$d:d;�Z%d<d=�Z&dHd>d?�Z'd@dA�Z(dBdC�Z)dS)Ir
z A non-callable version of `Mock`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)z�
        Attach a mock as an attribute of this one, replacing its name and
        parent. Calls to the attached mock will be recorded in the
        `method_calls` and `mock_calls` attributes of this one.Nr�)rtrurvrwrz)rfr1�	attributerrr�attach_mock�s
zNonCallableMock.attach_mockcCs|j||�dS)z�Add a spec to a mock. `spec` can either be an object or a
        list of strings. Only attributes on the `spec` can be fetched as
        attributes from the mock.

        If `spec_set` is True then only attributes on the spec can be set.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)z-Restore the mock object to its initial state.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)aZSet attributes on the mock through keyword arguments.

        Attributes plus return values and side effects can be set on child
        mocks using standard dot notation and unpacking a dictionary in the
        method call:

        >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
        >>> mock.configure_mock(**attrs)cSs|djd�S)Nr�.)�count)�entryrrr�<lambda>8sz0NonCallableMock.configure_mock.<locals>.<lambda>)�keyr�N)�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)z8Filter the output of `dir(mock)` to only useful members.cSsg|]}|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)a
        Given a call (or simply an (args, kwargs) tuple), return a
        comparison key suitable for matching with other calls.
        This is a best effort method which relies on the spec's signature,
        if available, or falls back on the arguments themselves.
        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)z/assert that the mock was never called.
        rz7Expected '%s' to not have been called. Called %s times.r1N)r\rv�AssertionError)r*rfr�rrrrPs

z!NonCallableMock.assert_not_calledcCs(|}|jdkr$d|jpd}t|��dS)z6assert that the mock was called at least once
        rz"Expected '%s' to have been called.r1N)r\rvr�)r*rfr�rrrrOs

zNonCallableMock.assert_calledcCs.|}|jdks*d|jpd|jf}t|��dS)z3assert that the mock was called only once.
        r�z8Expected '%s' to have been called once. Called %s times.r1N)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)z�assert that the mock was called with the specified arguments.

        Raises an AssertionError if the args and keyword args passed in are
        different to the last call to the mock.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)ziassert that the mock was called exactly once and that that call was
        with the specified arguments.r�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)a�assert the mock has been called with the specified calls.
        The `mock_calls` list is checked for the calls.

        If `any_order` is False (the default) then the calls must be
        sequential. There can be extra calls before or after the
        specified calls.

        If `any_order` is True then the calls can be in any order, but
        they must all appear in `mock_calls`.csg|]}�j|��qSr)r�)r�c)rfrrr�Fsz4NonCallableMock.assert_has_calls.<locals>.<listcomp>Nc3s|]}�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)z�assert the mock has been called with the specified arguments.

        The assert passes if the mock has *ever* been called, unlike
        `assert_called_with` and `assert_called_once_with` that only pass if
        the call is the most recent one.csg|]}�j|��qSr)r�)rr�)rfrrr�fsz3NonCallableMock.assert_any_call.<locals>.<listcomp>Nz%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)aPCreate the child mocks for attributes and return value.
        By default child mocks will be the same type as the parent.
        Subclasses of Mock may want to override this to customize the way
        child mocks are made.

        For non-callable mocks the callable variant will be used (rather than
        any custom subclass).r�)rr�
CallableMixinrrr
rrA)rfr��_type�klassrrrr�os



zNonCallableMock._get_child_mock)NNNNNNr�NFNF)F)FF)N)F)*r5r8rhr6r�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
lsR

)
	


&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@seZdZdZdS)ra�	
    Create a new `Mock` object. `Mock` takes several optional arguments
    that specify the behaviour of the Mock object:

    * `spec`: This can be either a list of strings or an existing object (a
      class or instance) that acts as the specification for the mock object. If
      you pass in an object then a list of strings is formed by calling dir on
      the object (excluding unsupported magic attributes and methods). Accessing
      any attribute not in this list will raise an `AttributeError`.

      If `spec` is an object (rather than a list of strings) then
      `mock.__class__` returns the class of the spec object. This allows mocks
      to pass `isinstance` tests.

    * `spec_set`: A stricter variant of `spec`. If used, attempting to *set*
      or get an attribute on the mock that isn't on the object passed as
      `spec_set` will raise an `AttributeError`.

    * `side_effect`: A function to be called whenever the Mock is called. See
      the `side_effect` attribute. Useful for raising exceptions or
      dynamically changing return values. The function is called with the same
      arguments as the mock, and unless it returns `DEFAULT`, the return
      value of this function is used as the return value.

      If `side_effect` is an iterable then each call to the mock will return
      the next value from the iterable. If any of the members of the iterable
      are exceptions they will be raised instead of returned.

    * `return_value`: The value returned when the mock is called. By default
      this is a new Mock (created on first access). See the
      `return_value` attribute.

    * `wraps`: Item for the mock object to wrap. If `wraps` is not None then
      calling the Mock will pass the call through to the wrapped object
      (returning the real result). Attribute access on the mock will return a
      Mock object that wraps the corresponding attribute of the wrapped object
      (so attempting to access an attribute that doesn't exist will raise an
      `AttributeError`).

      If the mock has an explicit `return_value` set then calls are not passed
      to the wrapped object and the `return_value` is returned instead.

    * `name`: If the mock has a name then it will be used in the repr of the
      mock. This can be useful for debugging. The name is propagated to child
      mocks.

    Mocks can also be called with arbitrary keyword arguments. These will be
    used to set attributes on the mock after it is created.
    N)r5r8rhr6rrrrr�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|dd�|��|_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)zPerform the patch.FNzCan'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)	zUndo the patch.z stop called on unstarted patcherr6r8r9�__annotations__r:N)r6r8r9rr:)r��RuntimeErrorr�rrrzr�r�r�r�r�r�r�r
)rfrr�rrrr
Hs z_patch.__exit__cCs|j�}|jj|�|S)z-Activate a patch, returning any created mock.)r	�_active_patchesr�)rfrJrrr�start`sz_patch.startcCs.y|jj|�Wntk
r$YnX|j�S)zStop an active patch.)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)a
    patch the named member (`attribute`) on an object (`target`) with a mock
    object.

    `patch.object` can be used as a decorator, class decorator or a context
    manager. Arguments `new`, `spec`, `create`, `spec_set`,
    `autospec` and `new_callable` have the same meaning as for `patch`. Like
    `patch`, `patch.object` takes arbitrary keyword arguments for configuring
    the mock object it creates.

    When used as a class decorator `patch.object` honours `patch.TEST_PREFIX`
    for choosing which methods to wrap.
    cs�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)a�Perform multiple patches in a single call. It takes the object to be
    patched (either as an object or a string to fetch the object by importing)
    and keyword arguments for the patches::

        with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'):
            ...

    Use `DEFAULT` as the value if you want `patch.multiple` to create
    mocks for you. In this case the created mocks are passed into a decorated
    function by keyword, and a dictionary is returned when `patch.multiple` is
    used as a context manager.

    `patch.multiple` can be used as a decorator, class decorator or a context
    manager. The arguments `spec`, `spec_set`, `create`,
    `autospec` and `new_callable` have the same meaning as for `patch`. These
    arguments will be applied to *all* patches done by `patch.multiple`.

    When used as a class decorator `patch.multiple` honours `patch.TEST_PREFIX`
    for choosing which methods to wrap.
    cst��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�N)	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)a�

    `patch` acts as a function decorator, class decorator or a context
    manager. Inside the body of the function or with statement, the `target`
    is patched with a `new` object. When the function/with statement exits
    the patch is undone.

    If `new` is omitted, then the target is replaced with a
    `MagicMock`. If `patch` is used as a decorator and `new` is
    omitted, the created mock is passed in as an extra argument to the
    decorated function. If `patch` is used as a context manager the created
    mock is returned by the context manager.

    `target` should be a string in the form `'package.module.ClassName'`. The
    `target` is imported and the specified object replaced with the `new`
    object, so the `target` must be importable from the environment you are
    calling `patch` from. The target is imported when the decorated function
    is executed, not at decoration time.

    The `spec` and `spec_set` keyword arguments are passed to the `MagicMock`
    if patch is creating one for you.

    In addition you can pass `spec=True` or `spec_set=True`, which causes
    patch to pass in the object being mocked as the spec/spec_set object.

    `new_callable` allows you to specify a different class, or callable object,
    that will be called to create the `new` object. By default `MagicMock` is
    used.

    A more powerful form of `spec` is `autospec`. If you set `autospec=True`
    then the mock will be created with a spec from the object being replaced.
    All attributes of the mock will also have the spec of the corresponding
    attribute of the object being replaced. Methods and functions being
    mocked will have their arguments checked and will raise a `TypeError` if
    they are called with the wrong signature. For mocks replacing a class,
    their return value (the 'instance') will have the same spec as the class.

    Instead of `autospec=True` you can pass `autospec=some_object` to use an
    arbitrary object as the spec instead of the one being replaced.

    By default `patch` will fail to replace attributes that don't exist. If
    you pass in `create=True`, and the attribute doesn't exist, patch will
    create the attribute for you when the patched function is called, and
    delete it again afterwards. This is useful for writing tests against
    attributes that your production code creates at runtime. It is off by
    default because it can be dangerous. With it switched on you can write
    passing tests against APIs that don't actually exist!

    Patch can be used as a `TestCase` class decorator. It works by
    decorating each test method in the class. This reduces the boilerplate
    code when your test methods share a common patchings set. `patch` finds
    tests by looking for method names that start with `patch.TEST_PREFIX`.
    By default this is `test`, which matches the way `unittest` finds tests.
    You can specify an alternative prefix by setting `patch.TEST_PREFIX`.

    Patch can be used as a context manager, with the with statement. Here the
    patching applies to the indented block after the with statement. If you
    use "as" then the patched object will be bound to the name after the
    "as"; very useful if `patch` is creating a mock object for you.

    `patch` takes arbitrary keyword arguments. These will be passed to
    the `Mock` (or `new_callable`) on construction.

    `patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are
    available for alternate use-cases.
    )r r�)
r�r�r�r�r�r�r�r,r�r�rrrr�sE
c@sVeZdZdZfdfdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
eZe
ZdS)�_patch_dicta#
    Patch a dictionary, or dictionary like object, and restore the dictionary
    to its original state after the test.

    `in_dict` can be a dictionary or a mapping like container. If it is a
    mapping then it must at least support getting, setting and deleting items
    plus iterating over keys.

    `in_dict` can also be a string specifying the name of the dictionary, which
    will then be fetched by importing it.

    `values` can be a dictionary of values to set in the dictionary. `values`
    can also be an iterable of `(key, value)` pairs.

    If `clear` is True then the dictionary will be cleared before the new
    values are set.

    `patch.dict` can also be called with arbitrary keyword arguments to set
    values in the dictionary::

        with patch.dict('sys.modules', mymodule=Mock(), other_module=Mock()):
            ...

    `patch.dict` can be used as a context manager, decorator or class
    decorator. When used as a class decorator `patch.dict` honours
    `patch.TEST_PREFIX` for choosing which methods to wrap.
    FcKs>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)zPatch the dict.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)zUnpatch the dict.F)r()rfr+rrrr
�sz_patch_dict.__exit__N)
r5r8rhr6r!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)z7Stop all active patches. LIFO to unroll nested patches.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)z:Turns a callable object (like a mock) into a real functioncs�|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@seZdZdZddd�ZdS)rz-A version of `MagicMock` that isn't callable.FcCs|j||�|j�dS)z�Add a spec to a mock. `spec` can either be an object or a
        list of strings. Only attributes on the `spec` can be fetched as
        attributes from the mock.

        If `spec_set` is True then only attributes on the spec can be set.N)r�r^)rfr�r�rrrr�Gsz"NonCallableMagicMock.mock_add_specN)F)r5r8rhr6r�rrrrrEsc@seZdZdZddd�ZdS)ra�
    MagicMock is a subclass of Mock with default implementations
    of most of the magic methods. You can use MagicMock without having to
    configure the magic methods yourself.

    If you use the `spec` or `spec_set` arguments then *only* magic
    methods that exist in the spec will be created.

    Attributes and the return value of a `MagicMock` will also be `MagicMocks`.
    FcCs|j||�|j�dS)z�Add a spec to a mock. `spec` can either be an object or a
        list of strings. Only attributes on the `spec` can be fetched as
        attributes from the mock.

        If `spec_set` is True then only attributes on the spec can be set.N)r�r^)rfr�r�rrrr�]szMagicMock.mock_add_specN)F)r5r8rhr6r�rrrrrRs
c@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(eZdZdZdd�Zdd�Zdd�ZdS)	�_ANYz2A helper object that compares equal to everything.cCsdS)NTr)rfrSrrrrQ�sz_ANY.__eq__cCsdS)NFr)rfrSrrrrV�sz_ANY.__ne__cCsdS)Nz<ANY>r)rfrrrrg�sz
_ANY.__repr__N)r5r8rhr6rQrVrgrrrrrdsrdcCsdd|}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@sveZdZdZfddddfdd�Zfddddfdd	�Zd
d�ZejZdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)r�a�
    A tuple for holding the results of a call to a mock, either in the form
    `(args, kwargs)` or `(name, args, kwargs)`.

    If args or kwargs are empty then a call tuple will compare equal to
    a tuple without those values. This makes comparisons less verbose::

        _Call(('name', (), {})) == ('name',)
        _Call(('name', (1,), {})) == ('name', (1,))
        _Call(((), {'a': 'b'})) == ({'a': 'b'},)

    The `_Call` object provides a useful shortcut for comparing with call::

        _Call(((1, 2), {'a': 3})) == call(1, 2, a=3)
        _Call(('foo', (1, 2), {'a': 3})) == call.foo(1, 2, a=3)

    If the _Call has no name then it will match any name.
    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)z�For a call object that represents multiple calls, `call_list`
        returns a list of all the intermediate calls as well as the
        final call.N)rjr�rtrUr�)rf�valsr�rrr�	call_list?s


z_Call.call_list)r5r8rhr6r�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)aICreate a mock object using another object as a spec. Attributes on the
    mock will use the corresponding attribute on the `spec` object as their
    spec.

    Functions or methods being mocked will have their arguments checked
    to check that they are called with the correct signature.

    If `spec_set` is True then attempting to set attributes that don't exist
    on the spec object will raise an `AttributeError`.

    If a class is used as a spec then the return value of the mock (the
    instance of the class) will have the same spec. You can use a class as the
    spec for an instance object by passing `instance=True`. The returned mock
    will only be callable if instances of the mock are callable.

    `create_autospec` also takes arbitrary keyword arguments that are passed to
    the constructor of the created mock.r�r�NTr�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)z[
    Return whether we should skip the first argument on spec's `entry`
    attribute.
    rBFr0N)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|dkrttd	t	d
�}ttd����j
_t��dg�d�j
_d�j_d�j_d�j_|�j_���d<�d�j_|�j_����fd
d�}||_�|_|S)a�
    A helper function to create a mock to replace the use of `open`. It works
    for `open` called directly or used as a context manager.

    The `mock` argument is the mock object to configure. If `None` (the
    default) then a `MagicMock` will be created for you, with the API limited
    to methods or attributes available on standard file handles.

    `read_data` is a string for the `read` methoddline`, and `readlines` of the
    file handle to return.  This is an empty string by default.
    cs �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_effectNr�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(eZdZdZdd�Zdd�Zdd�ZdS)	r
aW
    A mock intended to be used as a property, or other descriptor, on a class.
    `PropertyMock` provides `__get__` and `__set__` methods so you can specify
    a return value when it is fetched.

    Fetching a `PropertyMock` instance from an object calls the mock, with
    no args. Setting it calls the mock with the value being set.
    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)r5r8rhr6r�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