U
    42i,                     @  s  U d Z ddlm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	Z	ddl
m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ZejjZdddddZG dd dejZejZded< dddddZdddddZdddddZdUdddd d!Zd"d#d$d%Z d&dd'd(dd)d*d+d,d-Z!d.d*d/d0d1Z"d2d3 e#d4D Z$e$%e&d5d6e&d7d8e&d9d:i d;dd<d=d>Z'ej(G d?d@ d@Z)dAdB Z*dCdD Z+dEdF Z,dGddGdGdHdIdJZ-dddKdLdMZ.dNd#dOdPZ/dQdQdRdSdTZ0dS )Vz"Python version compatibility code.    )annotationsN)	Parameter)	signature)Path)Any)Callable)Final)NoReturnzstr | os.PathLike[str]LEGACY_PATH)pathreturnc                 C  s   t | S )zBInternal wrapper to prepare lazy proxies for legacy_path instances)r
   )r    r   2/tmp/pip-unpacked-wheel-7n2p7kht/_pytest/compat.pylegacy_path    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objectbool)funcr   c                 C  s   t | }|ot|  S N)inspectisgeneratorfunctioniscoroutinefunction)r   Zgenfuncr   r   r   is_generator.   s    
r   c                 C  s   t | pt| ddS )az  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 coroutines.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   3   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   isasyncgenfunctionr   r   r   r   is_async_function?   s    r!   zstr | os.PathLike[str] | Nonestr)curdirr   c                 C  sj   t | } tt| }| jj}|d k	rZz||}W n tk
rH   Y nX d||d f S d||d f S )Nz%s:%d   )get_real_funcr   r   getfile__code__co_firstlinenorelative_to
ValueError)functionr#   fnlinenoZrelfnr   r   r   getlocationE   s    r.   int)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mockDEFAULTzunittest.mockc                   s*   g | ]"}|j s|j ks"|jkr|qS r   )Zattribute_namenew.0pZmock_sentinelZut_mock_sentinelr   r   
<listcomp>]   s
   
 
z'num_mock_patch_args.<locals>.<listcomp>)r   sysmodulesgetr   len)r+   r0   r   r6   r   num_mock_patch_argsS   s    r<    )nameclszCallable[..., object]ztype | Noneztuple[str, ...])r+   r>   r?   r   c             
   C  s   zt | j}W nJ ttfk
rX } z(ddlm} |d| d| dd W 5 d}~X Y nX tdd	 | D }|sz| j}|rt	t
j||dd
ts|dd }t| dr|t| d }|S )a   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 cls arguments indicate that the function should be treated as a bound
    method even though it's not unless 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 r   kindr   POSITIONAL_OR_KEYWORDKEYWORD_ONLYdefaultemptyr>   r3   r   r   r   	<genexpr>   s
   z"getfuncargnames.<locals>.<genexpr>)rE   r$   __wrapped__)r   
parametersr*   	TypeError_pytest.outcomesr@   tuplevaluesr   
isinstancer   getattr_staticstaticmethodhasattrr<   )r+   r>   r?   rI   er@   	arg_namesr   r   r   getfuncargnamesf   s0    	 
rT   zCallable[..., Any])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 r   rA   r3   r   r   r   rG      s   z(get_default_arg_names.<locals>.<genexpr>)rL   r   rI   rM   )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\nzbytes | str)valr   c                 C  s2   t | tr| dd}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 strings 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.
    asciibackslashreplaceZunicode_escape)rN   bytesdecodeencode	translate$_non_printable_ascii_translate_table)r_   retr   r   r   ascii_escaped   s    
rh   c                   @  s   e Zd ZU dZded< 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.
    r   objN)r   r   r   __doc____annotations__r   r   r   r   ri      s   
ri   c                 C  s   | }t dD ]@}t| dd}t|tr0|j}  qvt| dd}|dkrH qv|} qddlm} td|| 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__NrH   r   )safereprz could not find real function of z
stopped at )rX   r   rN   ri   rj   Z_pytest._io.safereprrn   r*   	functoolspartialr   )rj   Z	start_objrY   Znew_objrn   r   r   r   r%      s"    
r%   c                 C  sV   zt | d}t| } W n tk
r.   |  Y S X |rRt | drRt| jrR| |} | 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__)rQ   r%   	Exceptioncallablerr   )rj   ZholderZ	is_methodr   r   r   get_real_method   s    


ru   c                 C  s&   z| j W S  tk
r    |  Y S X d S r   )rq   AttributeErrorr   r   r   r   	getimfunc
  s    rw   r   )r   r>   rE   r   c                 C  s8   ddl m} zt| ||W S  |k
r2   | Y 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)rK   rx   r   )r   r>   rE   rx   r   r   r   safe_getattr  s
    	ry   )rj   r   c                 C  s(   zt | W S  tk
r"   Y dS X dS )z0Ignore any exception via isinstance on Python 3.FN)r   isclassrs   )rj   r   r   r   safe_isclass"  s    r{   z
int | Nonec                  C  s8   t jdkst jdkrdS d} t }|| kr0|S dS dS )zReturn the current process's real user id or None if it could not be
    determined.

    :return: The user id or None if it could not be determined.
    win32Z
emscriptenN)r8   platformosgetuid)ERRORuidr   r   r   get_user_id*  s
    	r   r	   )valuer   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)1rk   
__future__r   Zdataclassesenumro   r   r   r   r   pathlibr   r8   typingr   r   r   r	   pyr   localr
   r   Enumr   r   r   rl   r   r   r!   r.   r<   rT   rU   rX   rf   updateordrh   Z	dataclassri   r%   ru   rw   ry   r{   r   r   r   r   r   r   <module>   sX   D4