U
    +5øix
  ã                   @  s€   d dl mZ d dlZd dlZd dlZd dlZdgZddœdd„ZejdkrXd d	l	m
Z
 nG d
d„ deƒZ
ejG dd„ dƒƒZdS )é    )ÚannotationsNÚExceptionGroupz	list[str]©Úreturnc                   C  s   t S ©N)Ú__all__© r   r   ú4/tmp/pip-unpacked-wheel-xj899fla/packaging/errors.pyÚ__dir__   s    r
   )é   é   )r   c                   @  sB   e Zd ZU dZded< ded< ddddœdd	„Zdd
œdd„ZdS )r   zËA minimal implementation of :external:exc:`ExceptionGroup` from Python 3.11.

        If :external:exc:`ExceptionGroup` is already defined by Python itself,
        that version is used instead.
        ÚstrÚmessageúlist[Exception]Ú
exceptionsÚNone)r   r   r   c                 C  s   || _ || _d S r   )r   r   )Úselfr   r   r   r   r	   Ú__init__   s    zExceptionGroup.__init__r   c                 C  s   | j j› d| j›d| j›d�S )Nú(z, ú))Ú	__class__Ú__name__r   r   )r   r   r   r	   Ú__repr__!   s    zExceptionGroup.__repr__N)r   Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   r   r   r   r	   r      s
   
c                   @  st   e Zd ZU dZejedd�Zded< dddœd	d
„Z	e
jdddœdd„ƒZe
jdddœdd„ƒZdddœdd„ZdS )Ú_ErrorCollectoraò  
    Collect errors into ExceptionGroups.

    Used like this:

        collector = _ErrorCollector()
        # Add a single exception
        collector.error(ValueError("one"))

        # Supports nesting, including combining ExceptionGroups
        with collector.collect():
            raise ValueError("two")
        collector.finalize("Found some errors")

    Since making a collector and then calling finalize later is a common pattern,
    a convenience method ``on_exit`` is provided.
    F)Údefault_factoryÚinitr   Úerrorsr   r   )Úmsgr   c                 C  s   | j rt|| j ƒ‚dS )z0Raise a group exception if there are any errors.N)r    r   ©r   r!   r   r   r	   Úfinalize;   s    z_ErrorCollector.finalizez-typing.Generator[_ErrorCollector, None, None]c                 c  s   | V  |   |¡ dS )zx
        Calls finalize if no uncollected errors were present.

        Uncollected errors are raised normally.
        N)r#   r"   r   r   r	   Úon_exit@   s    z_ErrorCollector.on_exitztype[Exception]z$typing.Generator[(None, None, None)])Úerr_clsr   c              
   g  sv   |pt f}z
dV  W n\ tk
rD } z| j |j¡ W 5 d}~X Y n. |k
rp } z| j |¡ W 5 d}~X Y nX dS )z•
        Context manager to collect errors into the error list.

        Must be inside loops, as only one error can be collected at a time.
        N)Ú	Exceptionr   r    Úextendr   Úappend)r   r%   Zerror_classesÚerrorr   r   r	   ÚcollectJ   s    

z_ErrorCollector.collectr&   )r)   r   c                 C  s   | j  |¡ dS )zAdd an error to the list.N)r    r(   )r   r)   r   r   r	   r)   Y   s    z_ErrorCollector.errorN)r   r   r   r   ÚdataclassesÚfieldÚlistr    r   r#   Ú
contextlibÚcontextmanagerr$   r*   r)   r   r   r   r	   r   %   s   
	r   )Ú
__future__r   r.   r+   ÚsysÚtypingr   r
   Úversion_infoÚbuiltinsr   r&   Z	dataclassr   r   r   r   r	   Ú<module>   s   
