U
    42‹i!  ã                   @  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 eee ee
e f Ze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)ÚGeneric)ÚOptional)ÚTuple)ÚType)ÚTypeVarÚ
ResultTypec                   @  s   e Zd ZdZdS )ÚHookCallErrorzHook was called incorrectly.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   ú2/tmp/pip-unpacked-wheel-c7483y97/pluggy/_result.pyr      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Ú	exceptionÚreturnc                 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krdS t|ƒ||jfS dS r   )r   ÚtypeÚ__traceback__)r   Úexcr   r   r   Úexcinfo*   s    zResult.excinfoc                 C  s   | j S )r   )r   )r   r   r   r   r   3   s    zResult.exceptionzCallable[[], ResultType]zResult[ResultType])Úfuncr   c              
   C  sH   d}d }}z
|ƒ }W n& t k
r< } z|}W 5 d}~X Y nX | ||ƒS )r   TN)ÚBaseException)Úclsr$   Ú__tracebackhide__r   r   r"   r   r   r   Ú	from_call8   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_resultC   s    	zResult.force_resultr%   )r   r   c                 C  s   d| _ || _dS )zForce the result to fail with ``exception``.

        This overrides any previous result or exception.

        .. versionadded:: 1.1.0
        Nr   )r   r   r   r   r   Úforce_exceptionO   s    zResult.force_exceptionc                 C  s.   d}| j }|dk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   r'   r"   r   r   r   Ú
get_resultY   s
    zResult.get_resultN)r   r   r   r   Ú	__slots__r   Úpropertyr#   r   Úclassmethodr(   r)   r*   r,   r   r   r   r   r      s   	

r   N)r   Ú
__future__r   Útypesr   Útypingr   r   r   r   r   r	   r
   r   r%   Z_ExcInfor   Ú	Exceptionr   r   Z_Resultr   r   r   r   Ú<module>   s    M