a
    ˆÏ?e¦  ã                   @  sô   d 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 eee eee f ZedƒZddddœdd„ZG dd„ deƒZeG dd„ de
e ƒƒZeZdS )z"
Hook wrapper "result" utilities.
é    )Úannotations)ÚTracebackType)ÚCallable)Úcast)Úfinal)Ú	Generator)ÚGeneric)ÚNoReturn)ÚOptional)ÚTuple)ÚType)ÚTypeVarÚ
ResultTypezKGenerator[None, Result[ResultType], None] | Generator[None, object, object]Ústrr	   )Úwrap_controllerÚmsgÚreturnc                 C  s$   | j }td|j|j|j|f ƒ‚d S )Nzwrap_controller at %r %s:%d %s)Úgi_codeÚRuntimeErrorÚco_nameÚco_filenameÚco_firstlineno)r   r   Úco© r   úQ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pluggy/_result.pyÚ_raise_wrapfail   s    ÿÿr   c                   @  s   e Zd ZdZdS )ÚHookCallErrorzHook was called incorrectly.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   $   s   r   c                   @  sŒ   e Zd ZdZdZddddœdd„Zed	d
œdd„ƒZedd
œdd„ƒZe	dddœdd„ƒZ
dddœdd„Zdddœdd„Zdd
œdd„ZdS )ÚResultzYAn object used to inspect and set the result in a :ref:`hook wrapper
    <hookwrappers>`.©Ú_resultÚ
_exceptionzResultType | NonezBaseException | NoneÚNone)ÚresultÚ	exceptionr   c                 C  s   || _ || _dS ©ú:meta private:Nr"   )Úselfr&   r'   r   r   r   Ú__init__/   s    zResult.__init__z_ExcInfo | None)r   c                 C  s&   | j }|du rdS t|ƒ||jfS dS r(   )r$   ÚtypeÚ__traceback__)r*   Úexcr   r   r   Úexcinfo8   s    zResult.excinfoc                 C  s   | j S )r)   )r$   )r*   r   r   r   r'   A   s    zResult.exceptionzCallable[[], ResultType]zResult[ResultType])Úfuncr   c              
   C  sJ   d}d }}z
|ƒ }W n( t y> } z|}W Y d}~n
d}~0 0 | ||ƒS )r)   TN)ÚBaseException)Úclsr0   Ú__tracebackhide__r&   r'   r.   r   r   r   Ú	from_callF   s    
zResult.from_callr   )r&   r   c                 C  s   || _ d| _dS )a,  Force the result(s) to ``result``.

        If the hook was marked as a ``firstresult`` a single value should
        be set, otherwise set a (modified) list of results. Any exceptions
        found during invocation will be deleted.

        This overrides any previous result or exception.
        Nr"   )r*   r&   r   r   r   Úforce_resultQ   s    	zResult.force_resultr1   )r'   r   c                 C  s   d| _ || _dS )z�Force the result to fail with ``exception``.

        This overrides any previous result or exception.

        .. versionadded:: 1.1.0
        Nr"   )r*   r'   r   r   r   Úforce_exception]   s    zResult.force_exceptionc                 C  s.   d}| j }|du rtt| jƒS | |j¡‚dS )z®Get the result(s) for this hook call.

        If the hook was marked as a ``firstresult`` only a single value
        will be returned, otherwise a list of results.
        TN)r$   r   r   r#   Úwith_tracebackr-   )r*   r3   r.   r   r   r   Ú
get_resultg   s
    zResult.get_resultN)r   r   r   r    Ú	__slots__r+   Úpropertyr/   r'   Úclassmethodr4   r5   r6   r8   r   r   r   r   r!   (   s   	

r!   N)r    Ú
__future__r   Útypesr   Útypingr   r   r   r   r   r	   r
   r   r   r   r1   Z_ExcInfor   r   Ú	Exceptionr   r!   Z_Resultr   r   r   r   Ú<module>   s&   M