a
    /§»aR/  ã                   @   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mZ ddlmZ erúddlmZ ddlmZ edƒZedƒZG dd„ dejƒZej Z!de"d< ej#dk�rDddl$m%Z& nddl&Z&edef e'dœdd„Z(e)e *d¡ƒZ+e,e-dœd d!„Z.e,e-dœd"d#„Z/e,e-dœd$d%„Z0dcee' e'd&œd'd(„Z1e2d)œd*d+„Z3dd,dd-œedef e'e-ee) ee'df d.œd/d0„Z4ej#d1k �red2d3„ ƒZ5ndd4lm5Z5 edef ee'df d5œd6d7„Z6d8d9„ e7d:ƒD ƒZ8e8 9e:d;ƒd<e:d=ƒd>e:d?ƒd@i¡ e'e'dAœdBdC„Z;e<e'fZ=e<e'dDœdEdF„Z>ee<e'f e'dDœdGdH„Z?ej@G dIdJ„ dJƒƒZAdKdL„ ZBdMdN„ ZCdOdP„ ZDee'eedQœdRdS„ZEe,e-dTœdUdV„ZFe�r2ej#dk�r$ddWlmGZG nddWlmGZG n"ej#dk�rLddWlmGZG ndXdY„ ZGej#dk�rnddZlmHZH n0dd[lmIZI dd\lmJZJ G d]d^„ d^eeef ƒZHd_d_d`œdadb„ZKdS )dz"Python version compatibility code.é    N)Úcontextmanager)Ú	Parameter)Ú	signature)ÚPath)ÚAny)ÚCallable)ÚGeneric)ÚOptional)ÚTuple)ÚTYPE_CHECKING)ÚTypeVar)ÚUnion)Úfail)ÚTEST_OUTCOME)ÚNoReturn)ÚFinalÚ_TÚ_Sc                   @   s   e Zd ZdZdS )Ú
NotSetTyper   N)Ú__name__Ú
__module__Ú__qualname__Útoken© r   r   úH/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/_pytest/compat.pyr   %   s   r   r   ÚNOTSET)é   é   )Úmetadata.©ÚfuncÚreturnc                 C   s   t t| ƒƒS ©N)Ústrr   ©r    r   r   r   Ú_format_args0   s    r%   Ú c                 C   s   t  | ¡}|ot| ƒ S r"   )ÚinspectÚisgeneratorfunctionÚiscoroutinefunction)r    Zgenfuncr   r   r   Úis_generator8   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)   Úgetattrr$   r   r   r   r)   =   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_functionI   s    r-   )Úcurdirr!   c                 C   sh   t | ƒ} tt | ¡ƒ}| jj}|d urXz| |¡}W n tyF   Y n0 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   ÚgetlocationO   s    r9   )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>g   s   ýz'num_mock_patch_args.<locals>.<listcomp>)r+   ÚsysÚmodulesÚgetÚobjectÚlen)r6   r:   r   r@   r   Únum_mock_patch_args]   s    þÿrG   F)ÚnameÚ	is_methodÚcls)r6   rH   rI   rJ   r!   c             
   C   s¶   zt | ƒj}W n@ ttfyN } z$td| ›d|› �dd� W Y d}~n
d}~0 0 tdd„ | ¡ D ƒƒ}|sp| j}|sŒ|r˜t|j	 
|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.
    z!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 r"   ©Úkindr   ÚPOSITIONAL_OR_KEYWORDÚKEYWORD_ONLYÚdefaultÚemptyrH   r=   r   r   r   Ú	<genexpr>•   s
   úz"getfuncargnames.<locals>.<genexpr>r/   Ú__wrapped__)r   Ú
parametersr5   Ú	TypeErrorr   ÚtupleÚvaluesr   Ú
isinstanceÚ__dict__rD   ÚstaticmethodÚhasattrrG   )r6   rH   rI   rJ   rS   ÚeÚ	arg_namesr   r   r   Úgetfuncargnamesp   s(    ÿþ	ÿÿ
r]   )r   é   c                   c   s
   d V  d S r"   r   r   r   r   r   Únullcontext°   s    r_   )r_   )r6   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 r"   rK   r=   r   r   r   rQ   ½   s   ýz(get_default_arg_names.<locals>.<genexpr>)rU   r   rS   rV   )r6   r   r   r   Úget_default_arg_names¹   s    þr`   c                 C   s(   i | ] }|t d dƒvr|d|d›�“qS )é    é   z\xZ02x)Úrange)r>   Úir   r   r   Ú
<dictcomp>Å   s   re   é€   ú	z\túz\rÚ
z\n)Úsr!   c                 C   s
   |   t¡S r"   )Ú	translateÚ$_non_printable_ascii_translate_table)rj   r   r   r   Ú_translate_non_printableÍ   s    rm   )Úvalr!   c                 C   s   |   dd¡S )NÚasciiÚbackslashreplace)Údecode)rn   r   r   r   Ú_bytes_to_asciiÔ   s    rr   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.
    Úunicode_escapero   )rW   Úbytesrr   Úencoderq   rm   )rn   Úretr   r   r   Úascii_escapedØ   s    

rw   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__ÚattrÚibÚobjr   r   r   r   rx   ð   s   rx   c                 C   sŠ   | }t dƒD ]@}t| ddƒ}t|tƒr0|j}  qtt| ddƒ}|du rH qt|} q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__NrR   r   )Úsafereprz<could not find real function of {start}
stopped at {current})ÚstartÚcurrent)rc   r+   rW   rx   r|   Z_pytest._io.safereprr~   r5   ÚformatÚ	functoolsÚpartialr    )r|   Z	start_objrd   Znew_objr~   r   r   r   r0   ü   s&    
ÿÿr0   c                 C   sT   zt | dƒ}t| ƒ} W n ty,   |  Y S 0 |rPt | dƒrPt| jƒrP|  |¡} | S )z»Attempt 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__)rZ   r0   Ú	ExceptionÚcallabler…   )r|   ZholderrI   r   r   r   Úget_real_method  s    


rˆ   c                 C   s$   z| j W S  ty   |  Y S 0 d S r"   )r„   ÚAttributeErrorr$   r   r   r   Ú	getimfunc'  s    rŠ   )rE   rH   rO   r!   c                 C   s*   zt | ||ƒW S  ty$   | 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).
    N)r+   r   )rE   rH   rO   r   r   r   Úsafe_getattr.  s    	r‹   )r|   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'   Úisclassr†   )r|   r   r   r   Úsafe_isclass=  s    r�   )Úfinalc                 C   s   | S r"   r   )Úfr   r   r   rŽ   N  s    rŽ   )Úcached_property)Úoverload)Ú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    ry   Nr   c                 C   s   || _ |j| _d S r"   r“   )Úselfr    r   r   r   Ú__init__[  s    zcached_property.__init__.zcached_property[_S, _T])ÚinstanceÚownerr!   c                 C   s   d S r"   r   ©r”   r–   r—   r   r   r   r…   _  s    zcached_property.__get__c                 C   s   d S r"   r   r˜   r   r   r   r…   e  s    c                 C   s(   |d u r| S |   |¡ }|j| j j< |S r"   )r    rX   r   )r”   r–   r—   Úvaluer   r   r   r…   i  s    ).).)N)r   r   r   Ú	__slots__r   r   r   r•   r‘   r	   r’   r…   r   r   r   r   r�   X  s    ÿþr�   r   )r™   r!   c                 C   s   dsJ d  | t| ƒj¡ƒ‚d S )NFzUnhandled value: {} ({}))r�   Útyper   )r™   r   r   r   Úassert_never�  s    rœ   )N)Lry   Úenumr‚   r'   ÚrerB   Ú
contextlibr   r   r   Úpathlibr   Útypingr   r   r   r	   r
   r   r   r   rz   Z_pytest.outcomesr   r   r   Ztyping_extensionsr   r   r   ÚEnumr   r   r   Ú__annotations__Úversion_infoÚ	importlibr   Zimportlib_metadatar#   r%   r›   ÚcompileZ
REGEX_TYPErE   Úboolr*   r)   r-   r9   ÚintrG   r]   r_   r`   rc   rl   ÚupdateÚordrm   rt   ZSTRING_TYPESrr   rw   rj   rx   r0   rˆ   rŠ   r‹   r�   rŽ   r�   r‘   r’   rœ   r   r   r   r   Ú<module>   s¤   û

ú> ÿÿ7