Format: application/x-python-code
⬇ Download File (3.2 KB)
   1  o
   2  
   3  0'hH�@s�ddlmZddlZddlZddlmZmZmZddlm	Z	ddl
   4  mZddlm
   5  Z
   6  mZejdkr7dd	lmZe
   7  rBeeegefZGd
   8  d�d�Zddd�ZdS)�)�annotationsN)�Callable�Iterable�Mapping)�AbstractContextManager)�
   9  TracebackType)�
  10  TYPE_CHECKING�Any)���)�BaseExceptionGroupc@s4eZdZddd�Zddd�Zddd�Zddd�ZdS)�_Catcher�handler_map�2Mapping[tuple[type[BaseException], ...], _Handler]cCs
  11  ||_dS�N)�_handler_map)�selfr�r�KC:\Users\shubh\Videos\agent\nova\Lib\site-packages\exceptiongroup/_catch.py�__init__s
  12  z_Catcher.__init__�return�NonecCsdSrr)rrrr�	__enter__sz_Catcher.__enter__�etype�type[BaseException] | None�exc�BaseException | None�tb�TracebackType | None�boolcCs`|dur.|�|�}||urdS|durdSt|t�r+z||j�ty*|j|_�w||�dS)NFT)�handle_exception�
  13  isinstancer
  14  �	__cause__�__context__)rrrrZ	unhandledrrr�__exit__s
  15  
  16  �z_Catcher.__exit__�
  17  BaseExceptionc	CsPt|t�r|}ntd|g�}g}|j��D]m\}}|�|�\}}|r~zz|�ty2||�}YnwWn8tyV}z||urF|�|�n|�|j�WYd}~n,d}~wtyl}z|�|�WYd}~nd}~wwt	�
  18  |�r~td|�d|�d��|�|s�nq|r�t|�dkr�|dStd|�S|r�t|j�dkr�|jd|ur�|S|S)N�zError trying to handle z with z,. Exception handler must be a sync function.rr)
  19  r"r
  20  r�items�split�append�extend�
  21  exceptionsr&�inspect�iscoroutine�	TypeError�len)	rrZexcgroupZnew_exceptionsZ	exc_types�handlerZmatched�result�new_excrrrr!2sR
  22  ����
  23  ���
  24  �z_Catcher.handle_exceptionN)rr)rr)rrrrrrrr )rr&rr)�__name__�
  25  __module__�__qualname__rrr%r!rrrrrs
  26  
  27  
  28  
  29  r�
  30  __handlers�FMapping[type[BaseException] | Iterable[type[BaseException]], _Handler]r�AbstractContextManager[None]cCs�t|t�s	td��i}|��D]H\}}t|t�r!t|t�r!|f}nt|t�r+t|�}ntd��t	|�s7td��|D]}t|t�rEt|t�sItd��t|t
  31  �rRtd��q9|||<qt|�S)Nzthe argument must be a mappingzCeach key must be either an exception classes or an iterable thereofzhandlers must be callablezHcatching ExceptionGroup with catch() is not allowed. Use except instead.)r"rr/r(�type�
  32  issubclassr&r�tuple�callabler
  33  r)r7rZtype_or_iterabler1�iterable�exc_typerrr�catch`s<
  34  ��
  35  
  36  ���
  37  ��
  38  r@)r7r8rr9)�
  39  __future__rr-�sys�collections.abcrrr�
  40  contextlibr�typesr�typingrr	�version_info�_exceptionsr
  41  Z_Handlerrr@rrrr�<module>s
  42  O