B
    Wc2                 @   s  U d Z ddlZddlZddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ ddl
mZ ddl
mZ dd	l
mZ dd
l
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddlZddlZddl
mZ erddlmZ edZedZejjZeedf edddZG dd dej Z!e!j"Z#de$d< ej%dkrVddl&Z'e'j(Z)nddl)Z)edef edddZ*e+e,dd d!Z-e+e,dd"d#Z.e+e,dd$d%Z/d^ee ed&d'd(Z0e1d)d*d+Z2d,d-dd.edef ee,ee3 eedf d/d0d1Z4edef eedf d2d3d4Z5d5d6 e6d7D Z7e78e9d8d9e9d:d;e9d<d=i eed>d?d@Z:e;efZ<e;edAdBdCZ=ee;ef edAdDdEZ>ej?G dFdG dGZ@dHdI ZAdJdK ZBdLdM ZCeeeedNdOdPZDe+e,dQdRdSZEerej%dkrddTl
mFZF nddTlmFZF n"ej%dkr*ddTl
mFZF ndUdV ZFej%dkrLddWlmGZG n$ddXl
mHZH G dYdZ dZeeef ZGeed[d\d]ZIdS )_z"Python version compatibility code.    N)	Parameter)	signature)Path)Any)Callable)Generic)NoReturn)Optional)Tuple)TYPE_CHECKING)TypeVar)Union)overload)Final_T_Szos.PathLike[str])pathreturnc             C   s   t | S )zBInternal wrapper to prepare lazy proxies for legacy_path instances)LEGACY_PATH)r    r   -lib/python3.7/site-packages/_pytest/compat.pylegacy_path2   s    r   c               @   s   e Zd ZdZdS )
NotSetTyper   N)__name__
__module____qualname__tokenr   r   r   r   r   :   s   r   r   NOTSET)      .)funcr   c             C   s   t t| S )N)strr   )r    r   r   r   _format_argsG   s    r"   c             C   s   t | }|ot|  S )N)inspectZisgeneratorfunctioniscoroutinefunction)r    Zgenfuncr   r   r   is_generatorK   s    
r%   c             C   s   t | pt| ddS )a{  Return True if func is a coroutine function (a function defined with async
    def syntax, and doesn't contain yield), or a function decorated with
    @asyncio.coroutine.

    Note: copied and modified from Python 3.5's builtin couroutines.py to avoid
    importing asyncio directly, which in turns also initializes the "logging"
    module as a side-effect (see issue #8).
    Z_is_coroutineF)r#   r$   getattr)r    r   r   r   r$   P   s    	r$   c             C   s   t | pt| S )zZReturn True if the given function seems to be an async function or
    an async generator.)r$   r#   Zisasyncgenfunction)r    r   r   r   is_async_function\   s    r'   )curdirr   c             C   sj   t | } tt| }| jj}|d k	rZy||}W n tk
rH   Y nX d||d f S d||d f S )Nz%s:%d   )get_real_funcr   r#   Zgetfile__code__co_firstlinenoZrelative_to
ValueError)functionr(   fnlinenoZrelfnr   r   r   getlocationb   s    r1   )r   c                sX   t | dd}|sdS t tjddt  t tjddt t fdd|D S )	z>Return number of arguments used up by mock arguments (if any).	patchingsNr   ZmockZDEFAULTzunittest.mockc                s*   g | ]"}|j s|j ks"|jkr|qS r   )Zattribute_namenew).0p)mock_sentinelut_mock_sentinelr   r   
<listcomp>{   s   z'num_mock_patch_args.<locals>.<listcomp>)r&   sysmodulesgetobjectlen)r.   r2   r   )r6   r7   r   num_mock_patch_argsp   s    r>    F)name	is_methodcls)r.   r@   rA   rB   r   c         
   C   s   yt | j}W nJ ttfk
rX } z(ddlm} |d| d| dd W dd}~X Y nX tdd	 | D }|sz| j}|s|rt	t
j||dd
ts|dd }t| dr|t| d }|S )aL  Return the names of a function's mandatory arguments.

    Should return the names of all function arguments that:
    * Aren't bound to an instance or type as in instance or class methods.
    * Don't have default values.
    * Aren't bound with functools.partial.
    * Aren't replaced with mocks.

    The is_method and cls arguments indicate that the function should
    be treated as a bound method even though it's not unless, only in
    the case of cls, the function is a static method.

    The name parameter should be the original name in which the function was collected.
    r   )failz!Could not determine arguments of z: F)ZpytraceNc             s   s8   | ]0}|j tjks|j tjkr|jtjkr|jV  qd S )N)kindr   POSITIONAL_OR_KEYWORDKEYWORD_ONLYdefaultemptyr@   )r4   r5   r   r   r   	<genexpr>   s   z"getfuncargnames.<locals>.<genexpr>)rG   r)   __wrapped__)r   
parametersr-   	TypeError_pytest.outcomesrC   tuplevaluesr   
isinstancer#   Zgetattr_staticstaticmethodhasattrr>   )r.   r@   rA   rB   rK   erC   Z	arg_namesr   r   r   getfuncargnames   s(    
rT   )r.   r   c             C   s   t dd t| j D S )Nc             s   s2   | ]*}|j tjtjfkr|jtjk	r|jV  qd S )N)rD   r   rE   rF   rG   rH   r@   )r4   r5   r   r   r   rI      s   z(get_default_arg_names.<locals>.<genexpr>)rN   r   rK   rO   )r.   r   r   r   get_default_arg_names   s    rU   c             C   s(   i | ] }|t d dkrd|d|qS )       z\xZ02x)range)r4   ir   r   r   
<dictcomp>   s   rZ      	z\tz\r
z\n)sr   c             C   s
   |  tS )N)	translate$_non_printable_ascii_translate_table)r_   r   r   r   _translate_non_printable   s    rb   )valr   c             C   s   |  ddS )Nasciibackslashreplace)decode)rc   r   r   r   _bytes_to_ascii   s    rg   c             C   s,   t | trt| }n| dd}t|S )a  If val is pure ASCII, return it as an str, otherwise, escape
    bytes objects into a sequence of escaped bytes:

    b'\xc3\xb4\xc5\xd6' -> r'\xc3\xb4\xc5\xd6'

    and escapes unicode objects into a sequence of escaped unicode
    ids, e.g.:

    r'4\nV\U00043efa\x0eMXWB\x1e\u3028\u15fd\xcd\U0007d944'

    Note:
       The obvious "v.decode('unicode-escape')" will return
       valid UTF-8 unicode if it finds them in bytes, but we
       want to return escaped bytes for any byte, even if they match
       a UTF-8 string.
    Zunicode_escaperd   )rP   bytesrg   encoderf   rb   )rc   Zretr   r   r   ascii_escaped   s    

rj   c               @   s   e Zd ZdZe ZdS )_PytestWrappera%  Dummy wrapper around a function object for internal use only.

    Used to correctly unwrap the underlying function object when we are
    creating fixtures, because we wrap the function object ourselves with a
    decorator to issue warnings when the fixture function is called directly.
    N)r   r   r   __doc__attrZibobjr   r   r   r   rk      s   rk   c             C   s   | }xnt dD ]<}t| dd}t|tr0|j} P t| dd}|dkrFP |} qW ddlm} tdj|||| dt| t	j
r| j} | S )	zjGet the real function object of the (possibly) wrapped object by
    functools.wraps or functools.partial.d   Z__pytest_wrapped__NrJ   r   )safereprz<could not find real function of {start}
stopped at {current})startZcurrent)rX   r&   rP   rk   rn   Z_pytest._io.safereprrp   r-   format	functoolspartialr    )rn   Z	start_objrY   Znew_objrp   r   r   r   r*     s"    
r*   c             C   sR   yt | d}t| } W n tk
r*   | S X |rNt | drNt| jrN| |} | S )zAttempt to obtain the real function object that might be wrapping
    ``obj``, while at the same time returning a bound method to ``holder`` if
    the original object was a bound method.__func____get__)rR   r*   	Exceptioncallablerv   )rn   ZholderrA   r   r   r   get_real_method)  s    

ry   c             C   s    y| j S  tk
r   | S X d S )N)ru   AttributeError)r    r   r   r   	getimfunc7  s    r{   )r<   r@   rG   r   c             C   s2   ddl m} yt| ||S  |k
r,   |S X dS )aR  Like getattr but return default upon any Exception or any OutcomeException.

    Attribute access can potentially fail for 'evil' Python objects.
    See issue #214.
    It catches OutcomeException because of #2490 (issue #580), new outcomes
    are derived from BaseException instead of Exception (for more details
    check #2707).
    r   )TEST_OUTCOMEN)rM   r|   r&   )r<   r@   rG   r|   r   r   r   safe_getattr>  s
    	r}   )rn   r   c             C   s$   y
t | S  tk
r   dS X dS )z0Ignore any exception via isinstance on Python 3.FN)r#   Zisclassrw   )rn   r   r   r   safe_isclassO  s    
r~   )finalc             C   s   | S )Nr   )fr   r   r   r   `  s    r   )cached_property)Typec               @   st   e Zd ZdZeegef ddddZedde	e
e  ddd	d
Zedee	e
e  eddd
Zddd
ZdS )r   )r    rl   N)r    r   c             C   s   || _ |j| _d S )N)r    rl   )selfr    r   r   r   __init__l  s    zcached_property.__init__.zcached_property[_S, _T])instanceownerr   c             C   s   d S )Nr   )r   r   r   r   r   r   rv   p  s    zcached_property.__get__c             C   s   d S )Nr   )r   r   r   r   r   r   rv   v  s    c             C   s(   |d kr| S |  | }|j| j j< |S )N)r    __dict__r   )r   r   r   valuer   r   r   rv   z  s    ).).)N)r   r   r   	__slots__r   r   r   r   r   r	   r   rv   r   r   r   r   r   i  s   r   )r   r   c             C   s$   ds t d|  dt| j dd S )NFzUnhandled value: z ())AssertionErrortyper   )r   r   r   r   assert_never  s    r   )N)Jrl   enumrs   r#   osr9   r   r   Zpathlibr   typingr   r   r   r   r	   r
   r   r   r   rm   pyr   Ztyping_extensionsr   r   r   r   localr   r!   r   Enumr   r   r   __annotations__version_infoZimportlib.metadata	importlibZmetadataZimportlib_metadatar"   r<   boolr%   r$   r'   r1   intr>   r   rT   rU   rX   ra   updateordrb   rh   ZSTRING_TYPESrg   rj   r_   rk   r*   ry   r{   r}   r~   r   r   r   r   r   r   r   r   <module>   s   
@ 7