a
    *ñ»j¦)  ã                   @  s  U d Z ddlmZ ddlm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Zejdkr¬ddlm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!dVd"d#d$œd%d&„Z"d'd(œd)d*„Z#d+dd,œd-d#d.d/d0œd1d2„Z$dd/d3œd4d5„Z%d6d7„ e&d8ƒD ƒZ'e' (e)d9ƒd:e)d;ƒd<e)d=ƒd>i¡ d?d#d@œdAdB„Z*dCdD„ Z+dEdF„ Z,dGd#dGdGdHœdIdJ„Z-dddœdKdL„Z.dMd(œdNdO„Z/dPdPdQœdRdS„Z0G dTdU„ dUƒZ1dS )Wz"Python version compatibility code.é    )Úannotations)ÚCallableN)Ú	Parameter)Ú	Signature)ÚPath)ÚAny)ÚFinal)ÚNoReturn©é   é   )ÚFormatz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   ú4E:\soccer\ml_env\Lib\site-packages\_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  | ¡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)ÚinspectÚiscoroutinefunctionÚgetattr©r   r   r   r   r   1   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Callable[..., Any]r   )Úobjr   c                 C  s$   t jdkrtj| tjd�S t | ¡S )z0Return signature without evaluating annotations.r
   )Zannotation_format)ÚsysÚversion_infor   Ú	signaturer   ÚSTRING©r#   r   r   r   r&   C   s    
r&   zstr | os.PathLike[str] | NoneÚstr)Úcurdirr   c                 C  sl   t | ƒ} tt | ¡ƒ}| jj}|d urZz| |¡}W n tyF   Y n0 |› d|d › �S |› d|d › �S )Nú:é   )Úget_real_funcr   r   ÚgetfileÚ__code__Úco_firstlinenoÚrelative_toÚ
ValueError)Úfunctionr*   ÚfnÚlinenoZrelfnr   r   r   ÚgetlocationJ   s    r6   Ú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ˆ u s"|jˆu r|‘qS r   )Zattribute_nameÚnew©Ú.0Úp©Zmock_sentinelZut_mock_sentinelr   r   Ú
<listcomp>b   s   ýz'num_mock_patch_args.<locals>.<listcomp>)r   r$   ÚmodulesÚgetr   Úlen)r3   r9   r   r?   r   Únum_mock_patch_argsX   s    þÿrD   Ú )ÚnameÚclszCallable[..., object]ztype | Noneztuple[str, ...])r3   rF   rG   r   c             
   C  sÒ   zt | ƒj ¡ }W nL ttfy^ } z0ddlm} |d| ›d|› �dd� W Y d}~n
d}~0 0 tdd	„ |D ƒƒ}|s|| j}t	d
d	„ |D ƒƒs´|r´t
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u s|j tju r|jtju r|jV  qd S ©N©Úkindr   ÚPOSITIONAL_OR_KEYWORDÚKEYWORD_ONLYÚdefaultÚemptyrF   r<   r   r   r   Ú	<genexpr>‘   s
   úz"getfuncargnames.<locals>.<genexpr>c                 s  s   | ]}|j tju V  qd S rI   )rK   r   ÚPOSITIONAL_ONLYr<   r   r   r   rP       ó    )rN   r,   Ú__wrapped__)r&   Ú
parametersÚvaluesr2   Ú	TypeErrorÚ_pytest.outcomesrH   Útupler   ÚanyÚ
isinstancer   Úgetattr_staticÚstaticmethodÚhasattrrD   )r3   rF   rG   rT   ÚerH   Ú	arg_namesr   r   r   Úgetfuncargnamesk   s0    þþ	ýÿü
r`   )r3   r   c                 C  s   t dd„ t| ƒj ¡ D ƒƒS )Nc                 s  s2   | ]*}|j tjtjfv r|jtjur|jV  qd S rI   rJ   r<   r   r   r   rP   ³   s   ýz(get_default_arg_names.<locals>.<genexpr>)rX   r&   rT   rU   )r3   r   r   r   Úget_default_arg_names¯   s    þra   c                 C  s(   i | ] }|t d dƒvr|d|d›�“qS )é    é   z\xÚ02x)Úrange)r=   Úir   r   r   Ú
<dictcomp>»   s   rg   é€   ú	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ÚbackslashreplaceÚunicode_escape)rZ   ÚbytesÚdecodeÚencodeÚ	translateÚ$_non_printable_ascii_translate_table)rl   Úretr   r   r   Úascii_escapedÃ   s    
rv   c                 C  s    t  | ¡} t| tjƒr| j} | S )z{Get the real function object of the (possibly) wrapped object by
    :func:`functools.wraps`, or :func:`functools.partial`.)r   ÚunwraprZ   Ú	functoolsÚpartialr   r(   r   r   r   r-   Ú   s    
r-   c                 C  s$   z| j W S  ty   |  Y S 0 d S rI   )Ú__func__ÚAttributeErrorr    r   r   r   Ú	getimfuncä   s    r|   r   )r   rF   rN   r   c                 C  s6   ddl m} zt| ||ƒW S  |y0   | Y S 0 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)rW   r}   r   )r   rF   rN   r}   r   r   r   Úsafe_getattrë   s
    	r~   c                 C  s&   zt  | ¡W S  ty    Y dS 0 dS )z0Ignore any exception via isinstance on Python 3.FN)r   ÚisclassÚ	Exceptionr(   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 )zšReturn 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éÿÿÿÿ)r$   ÚplatformÚosÚgetuid)ÚERRORÚuidr   r   r   Úget_user_id  s
    	r‰   r	   ©Úvaluer   c                 C  s$   ds J d| › dt | ƒj› d�ƒ‚d S )NFzUnhandled value: z (ú))Útyper   )r‹   r   r   r   Úassert_never8  s    rŽ   c                   @  s<   e Zd ZdZdddœdd„Zddœdd	„Zddœd
d„ZdS )ÚCallableBoola'  
    A bool-like object that can also be called, returning its true/false value.

    Used for backwards compatibility in cases where something was supposed to be a method
    but was implemented as a simple attribute by mistake (see `TerminalReporter.isatty`).

    Do not use in new code.
    r   ÚNonerŠ   c                 C  s
   || _ d S rI   ©Ú_value)Úselfr‹   r   r   r   Ú__init__F  s    zCallableBool.__init__r8   c                 C  s   | j S rI   r‘   ©r“   r   r   r   Ú__bool__I  s    zCallableBool.__bool__c                 C  s   | j S rI   r‘   r•   r   r   r   Ú__call__L  s    zCallableBool.__call__N)r   r   r   Ú__doc__r”   r–   r—   r   r   r   r   r�   <  s   	r�   )N)2r˜   Ú
__future__r   Úcollections.abcr   Úenumrx   r   r   r   r…   Úpathlibr   r$   Útypingr   r   r	   Úpyr%   Zannotationlibr   r   Úlocalr   r   ÚEnumr   r   r   Ú__annotations__r   r"   r&   r6   rD   r`   ra   re   rt   ÚupdateÚordrv   r-   r|   r~   r�   r‰   rŽ   r�   r   r   r   r   Ú<module>   sV   
üDÿÿ
4