a
    ˆÏ?eE5  ã                   @  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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ZddlmZ erÒddlmZ edƒZedƒZejjZdddœdd„ZG dd„ dejƒZej Z!de"d< ej#dk�r6ddl$Z%e%j&Z'nddl'Z'dddœdd„Z(d d!dœd"d#„Z)d d!dœd$d%„Z*d d!dœd&d'„Z+djd(dd)œd*d+„Z,d,d-œd.d/„Z-d0d1dd2œddd!d3d4d5œd6d7„Z.dd4d8œd9d:„Z/d;d<„ e0d=ƒD ƒZ1e1 2e3d>ƒd?e3d@ƒdAe3dBƒdCi¡ dddDœdEdF„Z4e5e6fZ7dGddHœdIdJ„Z8dKddHœdLdM„Z9ej:G dNdO„ dOƒƒZ;dPdQ„ Z<dRdS„ Z=dTdU„ Z>dVddVdVdWœdXdY„Z?d d!dZœd[d\„Z@e�r¸ej#dk�rªdd]lmAZA ndd]lmAZA n"ej#dk�rÒdd]lmAZA nd^d_„ ZAej#dk�rôdd`lmBZB nG dadb„ dbeeef ƒZBdcd-œddde„ZCdfdfdgœdhdi„ZDdS )kz"Python version compatibility code.é    )ÚannotationsN)Ú	Parameter)Ú	signature)ÚPath)ÚAny)ÚCallable)ÚGeneric)ÚNoReturn)ÚTYPE_CHECKING)ÚTypeVar)Úoverload)ÚFinalÚ_TÚ_Sz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   úQ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/_pytest/compat.pyÚlegacy_path0   s    r   c                   @  s   e Zd ZdZdS )Ú
NotSetTyper   N)Ú__name__Ú
__module__Ú__qualname__Útokenr   r   r   r   r   8   s   r   r   ÚNOTSET)é   é   zCallable[..., Any]Ústr©Úfuncr   c                 C  s   t t| ƒƒS ©N)r   r   ©r    r   r   r   Ú_format_argsE   s    r#   ÚobjectÚboolc                 C  s   t  | ¡}|ot| ƒ S r!   )ÚinspectÚisgeneratorfunctionÚiscoroutinefunction)r    Zgenfuncr   r   r   Úis_generatorI   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(   N   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_functionZ   s    r,   z
str | None)Ú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   Úgetlocation`   s    r8   Ú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>x   s   ýz'num_mock_patch_args.<locals>.<listcomp>)r*   ÚsysÚmodulesÚgetr$   Úlen)r5   r:   r   r@   r   Únum_mock_patch_argsn   s    þÿrF   Ú F)ÚnameÚ	is_methodÚclsztype | Noneztuple[str, ...])r5   rH   rI   rJ   r   c             
   C  sÄ   zt | ƒj}W nL ttfyZ } z0ddlm} |d| ›d|› �dd� W Y d}~n
d}~0 0 tdd	„ | ¡ D ƒƒ}|s|| j}|sš|r¦t	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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>)rP   r.   Ú__wrapped__)r   Ú
parametersr4   Ú	TypeErrorÚ_pytest.outcomesrK   ÚtupleÚvaluesr   Ú
isinstancer&   Úgetattr_staticÚstaticmethodÚhasattrrF   )r5   rH   rI   rJ   rT   ÚerK   Ú	arg_namesr   r   r   Úgetfuncargnames�   s0    þþ	ýÿü
r_   )r5   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!   rL   r=   r   r   r   rR   Ë   s   ýz(get_default_arg_names.<locals>.<genexpr>)rW   r   rT   rX   )r5   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   Úbytes)Úvalr   c                 C  s   |   dd¡S )NÚasciiÚbackslashreplace)Údecode)ro   r   r   r   Ú_bytes_to_asciiâ   s    rs   zbytes | strc                 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_escaperp   )rY   rn   rs   Úencoderr   rm   )ro   Úretr   r   r   Úascii_escapedæ   s    

rw   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   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__NrS   r   )Úsafereprz<could not find real function of {start}
stopped at {current})ÚstartÚcurrent)rc   r*   rY   rx   ry   Z_pytest._io.safereprr}   r4   ÚformatÚ	functoolsÚpartialr    )ry   Z	start_objrd   Znew_objr}   r   r   r   r/   
  s&    
ÿÿr/   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__)r\   r/   Ú	ExceptionÚcallabler„   )ry   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   Ú	getimfunc5  s    r‰   r   )r$   rH   rP   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)rV   rŠ   r*   )r$   rH   rP   rŠ   r   r   r   Úsafe_getattr<  s
    	r‹   )ry   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…   )ry   r   r   r   Úsafe_isclassM  s    r�   )Úfinalc                 C  s   | S r!   r   )Úfr   r   r   rŽ   ^  s    rŽ   )Úcached_propertyc                   @  sZ   e Zd ZdZdddœdd„Zedddd	d
œdd„ƒZeddddd
œdd„ƒZddd„ZdS )r�   ©r    rz   zCallable[[_S], _T]ÚNoner   c                 C  s   || _ |j| _d S r!   r‘   )Úselfr    r   r   r   Ú__init__i  s    zcached_property.__init__.ztype[_S] | Nonezcached_property[_S, _T])ÚinstanceÚownerr   c                 C  s   d S r!   r   ©r“   r•   r–   r   r   r   r„   m  s    zcached_property.__get__r   r   c                 C  s   d S r!   r   r—   r   r   r   r„   s  s    Nc                 C  s(   |d u r| S |   |¡ }|j| j j< |S r!   )r    Ú__dict__r   )r“   r•   r–   Úvaluer   r   r   r„   w  s    ).).)N)r   r   r   Ú	__slots__r”   r   r„   r   r   r   r   r�   f  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éÿÿÿÿ)rB   ÚplatformÚosÚgetuid)ÚERRORÚuidr   r   r   Úget_user_id~  s
    	r¢   r	   )r™   r   c                 C  s$   ds J d| › dt | ƒj› d�ƒ‚d S )NFzUnhandled value: z (ú))Útyper   )r™   r   r   r   Úassert_never²  s    r¥   )N)Erz   Ú
__future__r   ZdataclassesÚenumr�   r&   rž   rB   r   r   Úpathlibr   Útypingr   r   r   r	   r
   r   Úpyr   Ztyping_extensionsr   r   r   r   Úlocalr   r   ÚEnumr   r   r   r{   Úversion_infoÚimportlib.metadataÚ	importlibÚmetadataZimportlib_metadatar#   r)   r(   r,   r8   rF   r_   r`   rc   rl   ÚupdateÚordrm   rn   r   ZSTRING_TYPESrs   rw   Z	dataclassrx   r/   r‡   r‰   r‹   r�   rŽ   r�   r¢   r¥   r   r   r   r   Ú<module>   sŒ   
ûFÿÿ4