Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test_exceptions.cpython-38.pyc
U

>��g<��@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZddlmZGdd�de�ZGdd�de�ZGdd	�d	e�ZGd
d�dej�ZGdd
�d
ej�Zedkr�e��dS)�N)�TESTFN�captured_stderr�check_impl_detail�check_warnings�cpython_only�
gc_collect�
no_tracing�unlink�
import_module�
script_helper�SuppressCrashReport)�supportc@seZdZdd�ZdS)�NaiveExceptioncCs
||_dS�N��x��selfr�r�3/opt/cppython/lib/python3.8/test/test_exceptions.py�__init__szNaiveException.__init__N��__name__�
__module__�__qualname__rrrrrrsrc@seZdZdZdd�ZdS)�SlottedNaiveExceptionrcCs
||_dSrrrrrrrszSlottedNaiveException.__init__N)rrr�	__slots__rrrrrrsrc@seZdZdd�ZdS)�BrokenStrExceptioncCstd��dS)Nzstr() is broken)�	Exception�rrrr�__str__szBrokenStrException.__str__N)rrrr rrrrrsrc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zedd��Z	d
d�Z
e�e
jdkd�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zed#d$��Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Z d3d4�Z!d5d6�Z"d7d8�Z#d9d:�Z$d;d<�Z%d=d>�Z&d?d@�Z'dAdB�Z(dCdD�Z)dEdF�Z*dGdH�Z+dIdJ�Z,edKdL��Z-edMdN��Z.edOdP��Z/edQdR��Z0edSdT��Z1edUdV��Z2edWdX��Z3edYdZ��Z4ed[d\��Z5d]d^�Z6d_d`�Z7dadb�Z8edcdd��Z9dedf�Z:dgdh�Z;didj�Z<dkdl�Z=dmS)n�ExceptionTestsc
Cs�z|d��Wn*|k
r6}zt|�}W5d}~XYnXz|d��Wn*|k
rn}zt|�}W5d}~XYnX|�||�|�|j|�dS)NZspam)�str�assertEqualr)r�exc�excname�errZbuf1Zbuf2rrr�raise_catch$szExceptionTests.raise_catchc
Cs�|�td�|�tttd�|�td�ttd�}|��ttd�}tj	}z0zddl}|�d�Wntk
rvYnXW5|t_	|��t
t�X|�t
d�|�t
td	d�|�td
�|�ttd�|�td�g}|�t|jd
�|�td�i}|�t|jd�|�td�|�td�|�td�zt}Wntk
�rLYnX|�td�d}td�D]}||7}�qf|�td�|�td�|�td�ztd�Wntk
�r�YnX|�td�|�td�ztddd�Wntk
�r�YnX|� d�|�t!d �|�t"d!�|�t"tj#d�|�t$d"�zgd#Wnt$k
�r^YnX|�t%d$�|�t%t&d%�|�t'd&�zdd}Wnt'k
�r�YnX|�t(d'�zdd}Wn$t(k
�r�}zW5d}~XYnX|�t)d(�dS))N�AttributeErrorZundefined_attribute�EOFError�w�rr��OSErrorzthis file does not exist�ImportErrorZundefined_module�
IndexError�
�KeyError�key�KeyboardInterrupt�MemoryError�	NameError�
OverflowError���RuntimeError�RecursionError�SyntaxErrorz/
�IndentationError�TabErrorz"try:
	1/0
    	1/0
finally:
 pass
z<string>�execzTabError not raised�SystemError�
SystemExit�	TypeErrorr�
ValueErrori�ZeroDivisionErrorr�StopAsyncIteration)*r'r(�assertRaises�getattr�sysr)�openr�close�stdinr	�marshal�loadsr-r.�
__import__r/�__getitem__r1r3r4r5Zundefined_variabler6�ranger9r:r;r>r<r=�compile�failr?r@�exitrArB�chrrCrrD)r�fpZ	savestdinrKr�dummy�errr�testRaising0s�



�
zExceptionTests.testRaisingcs(�fdd�}d}||d�|dd�dS)Nc
s`zt|dd�Wn@tk
rP}z"|j|kr@��d||jf�W5d}~XYnX��d�dS�N�
<fragment>r>zexpected %s, got %sz"failed to get expected SyntaxError)rPr;�msgrQ)�srcrZrVrrr�ckmsg�s
&z4ExceptionTests.testSyntaxErrorMessage.<locals>.ckmsgzHif 1:
        try:
            continue
        except:
            passz'continue' not properly in loopz	continue
r�rr\�srrr�testSyntaxErrorMessage�s	
z%ExceptionTests.testSyntaxErrorMessagecs^tf�fdd�	}d}||d�d}||d�d}||d�d	}||d
t�d}||dt�dS)
Nc
s`zt|dd�Wn@|k
rP}z"|j|kr@��d||jf�W5d}~XYnX��d�dSrX)rPrZrQ)r[rZ�	exceptionrVrrrr\�s
&z:ExceptionTests.testSyntaxErrorMissingParens.<locals>.ckmsgzprint "old style"zHMissing parentheses in call to 'print'. Did you mean print("old style")?zprint "old style",zQMissing parentheses in call to 'print'. Did you mean print("old style", end=" ")?zexec "old style"z%Missing parentheses in call to 'exec'zif True:
print "No indent"zexpected an indented blockz6if True:
        print()
	exec "mixed tabs and spaces"z2inconsistent use of tabs and spaces in indentation)r;r<r=r]rrr�testSyntaxErrorMissingParens�s	


z+ExceptionTests.testSyntaxErrorMissingParenscs�d:�fdd�	}|ddd�|ddd	�|d
dd�|ddd
�|ddd
�|ddddd�|ddd�|ddd�|ddd�|ddd�|ddd�|ddd�|ddd�|ddd�|ddd�|d dd	�|d!dd"�|d#dd�|d$dd�|d%dd�|d&ddd'd�|d(dd)�|d*dd�|d+dd�|d,dd�|d-dd�|d.dd�|d/dd�|d0dd)�|d1dd�|d2dd�|d3dd�|d4dd�|d5dd)�|d6dd)�|d7dd�|d8dd�|d9dd�dS);N�utf-8c	s���t��}t|dd�W5QRX��|jj|���|jj|�|jjdk	r�t|t	�sd|�
|d�}|�d�|d}��|jj�d�|�dS)NrYr>�replace�
r7)
rEr;rPr#r`�lineno�offset�text�
isinstancer"�decode�split�rstrip)r[rerf�encoding�cm�linerrr�check�s
z3ExceptionTests.testSyntaxErrorOffset.<locals>.checkzdef fact(x):
	return x!
�r0z1 +
r7�z def spam():
  print(1)
 print(2)�zPython = "Python" +�uPython = "Ṕýţĥòñ" +s+# -*- coding: cp1251 -*-
Python = "ϳ���" +��cp1251)rlsPython = "ϳ���" +�zx = "a�zlambda x: x = 2zclass foo:return 1�zdef f():
  continuezdef f():
  breakz4try:
  pass
except:
  pass
except ValueError:
  passz(0x+1)zx = 0xI�z0010 + 2z
x = 32e-+4�zx = 0o9uα = 0xIsα = 0xIs## -*- coding: iso8859-7 -*-
� = 0xIz	iso8859-7z!x = [(yield i) for i in range(3)]�zdef f():
  from _ import *zdef f(x, x):
  passzdef f(x):
  nonlocal xzdef f(x):
  x = 1
  global xz
nonlocal xz def f():
  global x
  nonlocal xzfor 1 in []: passzdef f(*):
  passz[*x for x in xs]zdef f():
  x, y: intz
(yield i) = 2zfoo(x for x in range(10), 100)zfoo(1=2)z#from __future__ import doesnt_existzfrom __future__ import bracesz#x=1
from __future__ import division)rbr)rrorrr�testSyntaxErrorOffset�sZ��z$ExceptionTests.testSyntaxErrorOffsetcsjGdd�dt��Gdd�d����fdd�}��fdd�}��fd	d
�}tj�d�sf|�|�|�dS)Nc@seZdZdd�ZdS)z9ExceptionTests.testSettingException.<locals>.BadExceptioncSstd��dS)Nzcan't instantiate BadException)r9)Zself_rrrr�szBExceptionTests.testSettingException.<locals>.BadException.__init__Nrrrrr�BadException�sr}c@seZdZdS)z=ExceptionTests.testSettingException.<locals>.InvalidExceptionN�rrrrrrr�InvalidException�src
s�ddl}z|��d�WnXtk
rp}z:t��\}}}|jj}��|jd���	|j
�d��W5d}~XYnX��d�dS)Nrr7�
test_capi1�test_exceptions.py�Expected exception)
�	_testcapi�raise_exceptionrArG�exc_info�tb_frame�f_coder#�co_name�
assertTrue�co_filename�endswithrQ)r�r&r$�tb�co�r}rrrr�s$z7ExceptionTests.testSettingException.<locals>.test_capi1c
s�ddl}z|��d�Wnptk
r�}zRt��\}}}|jj}��|jd���	|j
�d��|jjj}��|jd�W5d}~XYnX��
d�dS)Nrrr��
test_capi2r�)r�r�r9rGr�r�r�r#r�r�r�r��f_backrQ)r�r&r$r�r�Zco2r�rrr�s
 z7ExceptionTests.testSettingException.<locals>.test_capi2csddl}��t|j�d�dS)Nrr7)r�rEr?r�)r�)rrrr�
test_capi3s

�z7ExceptionTests.testSettingException.<locals>.test_capi3�java)rrG�platform�
startswith)rr�r�r�r)r}rrr�testSettingException�sz#ExceptionTests.testSettingExceptioncCs�ztWntk
rY�n�X|�tt�|�ttd��d�|�ttdd��d�tddd�}|�|jd�|�|jd�|�t|�d�td	ddd
�}|�|jd�|�|jd
�|�|jd�|�|j	d�|�|j
d�|�t|�d�td	ddd�}|�|jd
�|�|jd�|�|jd�|�|j	d�|�|j
d�|�t|�d�tdd�}|�|jd�|�|jd�|�|jd�|�|j	d�|�|j
d�dS)Ni�Z1001�messagez[Errno 1001] message�	�foo�barz[Errno 9] foo: 'bar'rrrrpz[WinError 3] foo: 'bar'�z[WinError 1001] foo)�WindowsErrorr5�assertIsr-r#r"�errno�winerror�strerror�filename�	filename2)rr*rrr�test_WindowsError&sB�
z ExceptionTests.test_WindowsError�win32ztest specific to Windowsc	Cs8td�}d}|�td|��|j�|�W5QRXdS)z:Should fill in unknown error code in Windows error message�ctypeslcs�@zWindows Error 0x%xN)r
�assertRaisesRegexr-Z	pythonapiZPyErr_SetFromWindowsErr)rr��coderrr�test_windows_messageMsz#ExceptionTests.test_windows_messagecCstdddiftdddiftdddiftdddiftdddd�ftddddddd�ftd	d	dddd
d�ftdd	dddd
d�ftd
d	ddd�ftdddddd�ftddddddd�ftdddddddd�ftddddddddd�ftddd ddddd!d"�ftd#dd#dddddd$�ftdddiftd%d%d&d'd(d)d*�ftd&td+�d(dd)fd&td+�d(dd)fd&d+d(d)d*�ftd,d,d&d+d(d)d*�ftd-d-d.d/d(dd0�ft	dddd1�ft
dddd1�fg}z"|�tdddddddd2�f�Wnt
k
�r�YnX|D�] \}}}z||�}Wn$td3||ftjd4��Yn�Xt|�j�d5��sF|�t|�jd6�t|�}|D]:}t||�}|�t|�t||�d7|||||f��qRtfD]n}	t|	jd�D]X}
|	�||
�}|	�|�}|D]6}tt||��}t||�}
|�||
d8||f��qĐq��q��q�dS)9Nr�args)r7)r�)r�r7r�)r�r�)r�r�r�r�r�)r�r�r�)r�r��bazr�)r�r�r�N�quuxr�)r�r�r�)�errnoStr�strErrorStr�filenameStr)r�r�r�r�r�)r�r�r�r�)r7r�r�)r7r�r7)r�r�r�r�r�)rZrgr�rerf�print_file_and_line)�msgStrr�)r�rgr�rZr�rerf)r�)r��	linenoStr�	offsetStr�textStrr�r�r�)rfrgr�r�rZr�re)r�r�r�r�r�Zprint_file_and_lineStr)rgr�r�rZr�rerf)�ascii�arr7�ordinal not in ranger�r�rr�)r�rl�object�start�reason��)r�r�rr7r�)�あrr7�ouchr�r�)r�r�r�r��end)r�r)r�r�r�r�r�r�z
exc=%r, args=%r)�filer�builtinsz%r.%s == %r, expected %rzpickled "%r", attribute "%s)�
BaseExceptionr@r-r;�UnicodeError�UnicodeEncodeError�UnicodeDecodeError�	bytearray�UnicodeTranslateErrorrr�appendr�r5�printrG�stderr�typerr�r#rr"rF�repr�picklerO�HIGHEST_PROTOCOL�dumpsrL)rZ
exceptionListr$r�ZexpectedrVr^ZcheckArgName�value�p�protocol�newZgotZwantrrr�testAttributesWs\���������
�������������������������O���


��

��zExceptionTests.testAttributescCs�ztd��Wnt��d}YnXt��|�}|�|t�|�|j|�td��|�}|�|t�|�|j|�Gdd�dt�}|��|�}|�||�|�|j|�dS)Nrqrpr{c@seZdZdS)z5ExceptionTests.testWithTraceback.<locals>.MyExceptionNr~rrrr�MyException�sr�)	r/rGr�r��with_traceback�assertIsInstancer#�
__traceback__r)rr�rVr�rrr�testWithTraceback�sz ExceptionTests.testWithTracebackc
CsNzdt�_Wn2tk
r>}z|�dt|��W5d}~XYnX|�d�dS)Nr{z!__traceback__ must be a tracebackzNo exception raised)rr�rA�assertInr"rQ�rrVrrr�testInvalidTraceback�s
"z#ExceptionTests.testInvalidTracebackcCsP|�ttt�dd�|�ttt�d�|�ttt�dd�|�ttt�d�dS)N�	__cause__r7�__context__)rErA�setattrr�delattrrrrr�testInvalidAttrs�szExceptionTests.testInvalidAttrscCsJztd��Wnt��d}YnXt�}||_d|_|�|jd�dS)Nrqrp)r/rGr�rr�r#)rr�rVrrr�testNoneClearsTracebackAttr�sz*ExceptionTests.testNoneClearsTracebackAttrcCsnt�}|�|j�|�|j�t�}|�|j�|�|j�Gdd�dt�}|�}|�|j�|�|j�dS)Nc@seZdZdS)z5ExceptionTests.testChainingAttrs.<locals>.MyExceptionNr~rrrrr�sr�)r�assertIsNoner�r�rAr-)rrVr�rrr�testChainingAttrssz ExceptionTests.testChainingAttrsc
Cs�z
t��Wn&tk
r0}z|}W5d}~XYnX|�|j�|�|j�|�|j�t�|_d|_|�|jt�|�|j�|�|j�d|_|�|j�dS)NF)	rr�r�r�ZassertFalse�__suppress_context__r5r�r�)rr$rVrrr�testChainingDescriptorss
z&ExceptionTests.testChainingDescriptorscCs<|jttdd�Gdd�dt�}|dd�}|�|jd�dS)Nr7)r�c@seZdZdd�ZdS)z8ExceptionTests.testKeywordArgs.<locals>.DerivedExceptioncSst�|�||_dSr)r�r�	fancy_arg)rr�rrrr+s
zAExceptionTests.testKeywordArgs.<locals>.DerivedException.__init__Nrrrrr�DerivedException*sr��*)r�)rErAr�r#r�)rr�rrrr�testKeywordArgs%s
zExceptionTests.testKeywordArgscs4�fdd��|�t���fdd��|�t��dS)Ncs��Srrr)�frrr�4sz/ExceptionTests.testInfiniteRecursion.<locals>.fcs$z��WStk
rYdSXdS)N����rBr��grrr�8sz/ExceptionTests.testInfiniteRecursion.<locals>.g)rEr:rr)r�r�r�testInfiniteRecursion2sz$ExceptionTests.testInfiniteRecursioncCs8|�tt��|�ttd���|�ttdd���dS)Nr��b)r�r"rrrrr�test_str?szExceptionTests.test_strc
CsLz
t��Wn.tk
r8}z|�|�~W5d}~XYnX|�dt��dS)NrV)rr�ZassertNotIn�localsr�rrr�testExceptionCleanupNamesEs

z(ExceptionTests.testExceptionCleanupNamescs�Gdd�dt��Gdd�d�}��fdd�}|��t���}z
|�Wn"�k
rh}zW5d}~XYnXd�|��|���|��t���}z
|�Wn�k
r�YnXd�|��|���|��t���}z
|�WnYnXd�|��|���|��t���}dD]&}z
|�WnY�q:YnX�qd�|��|���|��t���}z z
|�Wnt�YnXWnPtk
�r�}z0d|_d�|��tdd	��r�t�|���W5d}~XYnX|��t���}z
|�Wn>�k
�r(zz�W5�XWn�k
�r"YnXYnXd�tdd	��r@t�|��|���Gd
d�d�}|��t���}|��|�W5QRXd�tdd	��r�t�|��|���dS)Nc@seZdZdd�ZdS)z=ExceptionTests.testExceptionCleanupState.<locals>.MyExceptioncSs
||_dSr��obj�rr�rrrrTszFExceptionTests.testExceptionCleanupState.<locals>.MyException.__init__Nrrrrrr�Ssr�c@seZdZdS)z7ExceptionTests.testExceptionCleanupState.<locals>.MyObjNr~rrrr�MyObjVsr�cs�}����dSrr)Z	local_ref�r�r�rr�inner_raising_funcYszDExceptionTests.testExceptionCleanupState.<locals>.inner_raising_func)rF)Zcpythonc@seZdZdd�Zdd�ZdS)z9ExceptionTests.testExceptionCleanupState.<locals>.ContextcSs|Srrrrrr�	__enter__�szCExceptionTests.testExceptionCleanupState.<locals>.Context.__enter__cSsdS)NTr)r�exc_type�	exc_value�exc_tbrrr�__exit__�szBExceptionTests.testExceptionCleanupState.<locals>.Context.__exit__N)rrrr�r�rrrr�Context�sr�)r�weakref�refr�r1r�rr)rr�r��wrrV�ir�rr�r�testExceptionCleanupStateOs�

















z(ExceptionTests.testExceptionCleanupStatec
sB�fdd�}ztWn(tk
r<�z
|�W5d��XYnXdS)Ncs�dSrrr�rVrr�print_error�szIExceptionTests.test_exception_target_in_nested_scope.<locals>.print_error)Z	somethingr)rrrrr�%test_exception_target_in_nested_scope�s
z4ExceptionTests.test_exception_target_in_nested_scopecCsdd�}|�}|�t|�t�|�t��dd�|�t|�t�|�t��dd�|�t|�d�ztd��Wn�tk
r�|�}|�t|�t�|�t��dt�|�t|�t�|�t��dt�|�t|�t�~|�t��dt�YnXdS)NcssPztd��Wn0tk
r<t��dVt��dVYnXt��dVdS)NZcaughtr)r1rGr�rrrr�yield_raise�sz:ExceptionTests.test_generator_leaking.<locals>.yield_raiserr�)r#�nextr1rGr�rA)rrr�rrr�test_generator_leaking�s$z%ExceptionTests.test_generator_leakingcCsjdd�}zt�Wn"tk
r2|�}t|�YnXzt|�Wntk
rTYnX|�t��d�dS)Ncss
dVdSrrrrrrr��sz1ExceptionTests.test_generator_leaking2.<locals>.g�NNN)r9r�
StopIterationr#rGr��rr��itrrr�test_generator_leaking2�sz&ExceptionTests.test_generator_leaking2c
Cs�dd�}|�}t|�zddWn`tk
r�}zB|�t��d|�|�|�}|�t��d|�|�||�W5d}~XYnX|�t��d�dS)Ncss2z
dVWn"tk
r,t��dVYnXdS�Nr7�rCrGr�rrrrr��s
z1ExceptionTests.test_generator_leaking3.<locals>.gr7rr	)rrCr�rGr��throwr#)rr�rrVZgen_excrrr�test_generator_leaking3�s
z&ExceptionTests.test_generator_leaking3c
Cs�dd�}|�}zt�Wntk
r2t|�}YnX|�|t�zt|�Wn6tk
r�}z|�t��d|�W5d}~XYnX|�t��d�dS)Ncss6zddWn$tk
r0t��dV�YnXdS)Nr7rrrrrrr�s
z1ExceptionTests.test_generator_leaking4.<locals>.gr7r	)rArr�rCrGr�r#)rr�r�tprVrrr�test_generator_leaking4s&z&ExceptionTests.test_generator_leaking4csJ�fdd�}|�}zt�Wntk
r6t|�YnX��tt|�dS)Nc3s.��t��dt�dV��t��d�dS)Nr7r	)r�rGr�r9r#rrrrr�*sz>ExceptionTests.test_generator_doesnt_retain_old_exc.<locals>.g)r9rrEr
rrrr�$test_generator_doesnt_retain_old_exc)sz3ExceptionTests.test_generator_doesnt_retain_old_exccs4dd���fdd�}|�t�|�t��d�dS)Ncss
dVdSrrrrrr�
simple_gen7szIExceptionTests.test_generator_finalizing_and_exc_info.<locals>.simple_gencs0��}zt�Wntk
r*t|�YSXdSr)r9r)�gen�rrr�run_gen9s
zFExceptionTests.test_generator_finalizing_and_exc_info.<locals>.run_genr	)rr#rGr�)rrrrr�&test_generator_finalizing_and_exc_info5s
z5ExceptionTests.test_generator_finalizing_and_exc_infocsnGdd�dt��Gdd�d�}��fdd�}|��t���}|�}t|�||�d}�|��|���dS)Nc@seZdZdd�ZdS)zFExceptionTests._check_generator_cleanup_exc_state.<locals>.MyExceptioncSs
||_dSrr�r�rrrrGszOExceptionTests._check_generator_cleanup_exc_state.<locals>.MyException.__init__Nrrrrrr�Fsr�c@seZdZdS)z@ExceptionTests._check_generator_cleanup_exc_state.<locals>.MyObjNr~rrrrr�Isr�c3s,z����Wn�k
r&dVYnXdSrrrr�rr�raising_genLszFExceptionTests._check_generator_cleanup_exc_state.<locals>.raising_gen)rr�r�rr�)rZtestfuncr�rrr�rr�r�"_check_generator_cleanup_exc_stateCs
z1ExceptionTests._check_generator_cleanup_exc_statecCsdd�}|�|�dS)NcSs*z|�t��Wntk
r$YnXdSr)rr9r�rrr�do_throw\szGExceptionTests.test_generator_throw_cleanup_exc_state.<locals>.do_throw�r)rrrrr�&test_generator_throw_cleanup_exc_state[sz5ExceptionTests.test_generator_throw_cleanup_exc_statecCsdd�}|�|�dS)NcSs|��dSr)rIr�rrr�do_closedszGExceptionTests.test_generator_close_cleanup_exc_state.<locals>.do_closer)rrrrr�&test_generator_close_cleanup_exc_statecsz5ExceptionTests.test_generator_close_cleanup_exc_statecCsdd�}|�|�dS)NcSsd}dSrrr�rrr�do_deliszCExceptionTests.test_generator_del_cleanup_exc_state.<locals>.do_delr)rr!rrr�$test_generator_del_cleanup_exc_statehsz3ExceptionTests.test_generator_del_cleanup_exc_statecs�fdd�}��|�dS)Ncs0zt|�Wntk
r YnX��d�dS�Nz should have raised StopIteration)rr
rQr�rrr�do_nextns
zEExceptionTests.test_generator_next_cleanup_exc_state.<locals>.do_nextr)rr$rrr�%test_generator_next_cleanup_exc_statemsz4ExceptionTests.test_generator_next_cleanup_exc_statecs�fdd�}��|�dS)Ncs2z|�d�Wntk
r"YnX��d�dSr#)�sendr
rQr�rrr�do_sendxs
zEExceptionTests.test_generator_send_cleanup_exc_state.<locals>.do_sendr)rr'rrr�%test_generator_send_cleanup_exc_statewsz4ExceptionTests.test_generator_send_cleanup_exc_statecsBG�fdd�d�}d�zt|���WnYnX|��d�dS)NcseZdZ�fdd�ZdS)z*ExceptionTests.test_3114.<locals>.MyObjectcst���dSr)rGr�rrrr�__del__�sz2ExceptionTests.test_3114.<locals>.MyObject.__del__N�rrrr)rrrr�MyObject�sr+rr	)rr#)rr+rrr�	test_3114�szExceptionTests.test_3114cCsftddddd�}|�t|�d�d|_|�t|�d�d|_d	|_|�t|�d
�d|_|�t|�d�d
|_|�t|�d�tddddd�}|�t|�d�d|_|�t|�d�d|_d	|_|�t|�d�d|_|�t|�d�d
|_|�t|�d�tdddd�}|�t|�d�d|_|�t|�d�d|_d	|_|�t|�d�d
|_|�t|�d�dS)Nr�Zxxxxxr7r{r�z8'baz' codec can't encode characters in position 1-4: foorpz<'baz' codec can't encode character '\x78' in position 1: foolESh
MQ)EzJ'baz' codec can't encode characters in position 1-4: 965230951443685724997i�zK'4000' codec can't encode characters in position 1-4: 965230951443685724997i�zN'4000' codec can't encode characters in position 1000-4: 965230951443685724997sxxxxxz3'baz' codec can't decode bytes in position 1-4: fooz5'baz' codec can't decode byte 0x78 in position 1: foozE'baz' codec can't decode bytes in position 1-4: 965230951443685724997zF'4000' codec can't decode bytes in position 1-4: 965230951443685724997zI'4000' codec can't decode bytes in position 1000-4: 965230951443685724997Zxxxxz/can't translate characters in position 1-4: fooz3can't translate character '\x78' in position 1: foozAcan't translate characters in position 1-4: 965230951443685724997zDcan't translate characters in position 1000-4: 965230951443685724997)	r�r#r"r�r�rlr�r�r�)r�urrr�test_unicode_change_attributes�s>z-ExceptionTests.test_unicode_change_attributescCs.tttf}|D]}|�t|�|��d�qdS)N�)r�r�r�r#r"�__new__)rZklasses�klassrrr�test_unicode_errors_no_object�s
z,ExceptionTests.test_unicode_errors_no_objectcs�Gdd�dt�}Gdd�dt|d�}t��n}z
t��WnR|k
rb}z|�d�W5d}~XYn2tk
rtYn |�d�YnX|�d�W5QRX�fdd	����\}}}|�|tt|��|�d
t|��dS)Nc@seZdZdd�ZdS)z/ExceptionTests.test_badisinstance.<locals>.MetacSs
t��dSrr�)�cls�subclassrrr�__subclasscheck__�szAExceptionTests.test_badisinstance.<locals>.Meta.__subclasscheck__N)rrrr5rrrr�Meta�sr6c@seZdZdS)z6ExceptionTests.test_badisinstance.<locals>.MyExceptionNr~rrrrr��sr�)�	metaclassz%exception should not be a MyExceptionzShould have raised KeyErrorcs*z��WStk
r$t��YSXdSr)r:rGr�rr�rrr��sz,ExceptionTests.test_badisinstance.<locals>.gz maximum recursion depth exceeded)	r�rrr1rQr�r:r�r")rr6r�r�rV�vr�rr�r�test_badisinstance�s 
z!ExceptionTests.test_badisinstancecCsdd�}|�t��dS)NcSst�}td�D]
}|j}qdS)Ni@B)r�rO�__dir__)�orrrrr��sz3ExceptionTests.test_trashcan_recursion.<locals>.foo)r
r)rr�rrr�test_trashcan_recursion�sz&ExceptionTests.test_trashcan_recursioncCsPdt}t�dd|�\}}}|�|d�|�d|�|�d|�|�d|�dS)Na�if 1:
            import sys
            from _testcapi import get_recursion_depth

            class MyException(Exception): pass

            def setrecursionlimit(depth):
                while 1:
                    try:
                        sys.setrecursionlimit(depth)
                        return depth
                    except RecursionError:
                        # sys.setrecursionlimit() raises a RecursionError if
                        # the new recursion limit is too low (issue #25274).
                        depth += 1

            def recurse(cnt):
                cnt -= 1
                if cnt:
                    recurse(cnt)
                else:
                    generator.throw(MyException)

            def gen():
                f = open(%a, mode='rb', buffering=0)
                yield

            generator = gen()
            next(generator)
            recursionlimit = sys.getrecursionlimit()
            depth = get_recursion_depth()
            try:
                # Upon the last recursive invocation of recurse(),
                # tstate->recursion_depth is equal to (recursion_limit - 1)
                # and is equal to recursion_limit when _gen_throw() calls
                # PyErr_NormalizeException().
                recurse(setrecursionlimit(depth + 2) - depth - 1)
            finally:
                sys.setrecursionlimit(recursionlimit)
                print('Done.')
        z-Wd�-cr7sRecursionErrorsResourceWarning�Done.)�__file__r�assert_python_failurer#r��rr��rc�outr&rrr�$test_recursion_normalizing_exception�s(�)z3ExceptionTests.test_recursion_normalizing_exceptioncCs>d}t�d|�\}}}|�|d�|�d|�|�d|�dS)Nz�if 1:
            import _testcapi
            try:
                raise _testcapi.RecursingInfinitelyError
            finally:
                print('Done.')
        r=r7sORecursionError: maximum recursion depth exceeded while normalizing an exceptionr>)rr@r#r�rArrr�-test_recursion_normalizing_infinite_exception#s�z<ExceptionTests.test_recursion_normalizing_infinite_exceptionc	Cs8d}t��$t�d|�\}}}|�d|�W5QRXdS)Na+if 1:
            import _testcapi
            class C(): pass
            def recurse(cnt):
                cnt -= 1
                if cnt:
                    recurse(cnt)
                else:
                    _testcapi.set_nomemory(0)
                    C()
            recurse(16)
        r=sRFatal Python error: Cannot recover from MemoryErrors while normalizing exceptions.)rrr@r�rArrr�)test_recursion_normalizing_with_no_memory5s�z8ExceptionTests.test_recursion_normalizing_with_no_memorycs@ddl�ddlm����fdd�}|�}|�}��||�dS)Nr��raise_memoryerrorc
sHz
��Wn(tk
r2}z
|j}W5d}~XYnX��d���|�S)Nz Should have raises a MemoryError)r4r�rQ�	format_tb)rVr��rHr�	tracebackrr�
raiseMemErrorRs

z6ExceptionTests.test_MemoryError.<locals>.raiseMemError)rKr�rHr#)rrLZtb1Ztb2rrJr�test_MemoryErrorLs	zExceptionTests.test_MemoryErrorc
Cs"ddl}d}d}|�t|jd�|�d�}|�t|�t�|�t|t��|�	|j
�|�d|�}|�|j
|�|jd|d�}|�t||��Gd	d
�d
t�}|�d|||f�}|�t||��|�t||��|�|j
|�|�dd
|ddi�}	|�t|	|��|�|	j
d�|�|	j
d
�dS)NrzThis is a test docstring.zThis is another test docstring.�error1z_testcapi.error1z_testcapi.error2z_testcapi.error3)�basec@seZdZdS)z1ExceptionTests.test_exception_with_doc.<locals>.CNr~rrrr�CxsrPz_testcapi.error4z_testcapi.error5r/r�r7)r�rEr?Zmake_exception_with_docr�r�r��
issubclassrr��__doc__r#r�r�)
rr�Zdoc2Zdoc4rNZerror2Zerror3rPZerror4Zerror5rrr�test_exception_with_doc_s<
�
���z&ExceptionTests.test_exception_with_docc
s�ddlm�Gdd�d��d����fdd�}z
|�Wn0tk
rh}z|���d�W5d}~XYnX|�d�|���d�dS)NrrGc@seZdZdS)z3ExceptionTests.test_memory_error_cleanup.<locals>.CNr~rrrrrP�srPcs��}t�|����dSr�r�r���c�rPrHrrr�inner�s
z7ExceptionTests.test_memory_error_cleanup.<locals>.innerzMemoryError not raised)r�rHr4�assertNotEqualrQr#)rrXrVrrWr�test_memory_error_cleanup�s
 
z(ExceptionTests.test_memory_error_cleanupc
szGdd�d��d����fdd��z
��Wn0tk
r\}z|���d�W5d}~XYnX|�d�|���d�dS)Nc@seZdZdS)z6ExceptionTests.test_recursion_error_cleanup.<locals>.CNr~rrrrrP�srPcs��}t�|����dSrrTrU�rPrXrrrrX�s
z:ExceptionTests.test_recursion_error_cleanup.<locals>.innerzRecursionError not raised)r:rYrQr#r�rr[r�test_recursion_error_cleanup�s
 
z+ExceptionTests.test_recursion_error_cleanupc	Cs:|�t��}t�t�W5QRX|�|jjtj|j�dSr)	rEr-�os�listdirr?r#r`r�ZENOTDIR)rrmrrr�test_errno_ENOTDIR�sz!ExceptionTests.test_errno_ENOTDIRc	CsNGdd�d�}|�}t���(}~|�|jj|j�|�|jj�W5QRXdS)Nc@seZdZdd�ZdS)z1ExceptionTests.test_unraisable.<locals>.BrokenDelcSstd�}|�dS)Nz
del is brokenr��rr$rrrr)�sz9ExceptionTests.test_unraisable.<locals>.BrokenDel.__del__Nr*rrrr�	BrokenDel�sra)r
Zcatch_unraisable_exceptionr#Z
unraisabler�r)ZassertIsNotNone�
exc_traceback)rrar�rmrrr�test_unraisable�s
zExceptionTests.test_unraisablecCs�ttfD]�}|�|���z|d�}|�Wn4|k
r\t��}tjt���W5QRXYnX|��}|�d|�|�d|�|�|j	|�|tkr�|�d|�n|�d|�|�
|�d��W5QRXqdS)Nztest messager�z	raise excz<exception str() failed>rd)rBrZsubTestrrG�__excepthook__r��getvaluer�rr�r�)rr�r$r�Zreportrrr�test_unhandled�s zExceptionTests.test_unhandledcCsFd}tdd�D]2}t�d||�\}}}|�|d�|�d|�qdS)Nz�if 1:
            import _testcapi
            class C(): pass
            _testcapi.set_nomemory(0, %d)
            C()
        r7rsr=)r7�xsMemoryError)rOrr@r�)rr�rrBrCr&rrr�"test_memory_error_in_PyErr_PrintEx�s

z1ExceptionTests.test_memory_error_in_PyErr_PrintExc	sdGdd�dt��Gdd�dt����fdd�}|�}|�d�|����|����W5QRXdS)Nc@seZdZdS)zBExceptionTests.test_yield_in_nested_try_excepts.<locals>.MainErrorNr~rrrr�	MainError�sric@seZdZdS)zAExceptionTests.test_yield_in_nested_try_excepts.<locals>.SubErrorNr~rrrr�SubError�srjc3sFz
���Wn6�k
r@z
dVWn�k
r8YnX�YnXdSrrr�rirjrr�main�s

z=ExceptionTests.test_yield_in_nested_try_excepts.<locals>.main)rr&rEr)rrl�cororrkr� test_yield_in_nested_try_excepts�s

z/ExceptionTests.test_yield_in_nested_try_exceptscsT�fdd�}|�}zt�Wn$tk
r>��t|�d�YnX��t|�d�dS)Nc3s>zt�Wntk
r"dVYnX��t��d�dVdS)Nr7r	rp)rBr#rGr�rrrrr�sz?ExceptionTests.test_generator_doesnt_retain_old_exc2.<locals>.gr7rp)r/r#r)rr�rrrr�%test_generator_doesnt_retain_old_exc2sz4ExceptionTests.test_generator_doesnt_retain_old_exc2c	CsRdd�}|�t��6|�}zddWnt|�t|�YnXW5QRXdS)NcssdV�dVdS)Nr7rprrrrrr�sz1ExceptionTests.test_raise_in_generator.<locals>.gr7r)rErCr)rr�rrrr�test_raise_in_generatorsz&ExceptionTests.test_raise_in_generatorcCs�Gdd�dt�}zt�Wn&tk
r>}z|}W5d}~XYnXz|�Wntk
r\YnXtd�D]6}zt�Wn"tk
r�}zW5d}~XYnXt�qfdS)Nc@seZdZdS)zBExceptionTests.test_memory_error_subclasses.<locals>.TestExceptionNr~rrrr�
TestException-srqr0)r4rrOr)rrqr$�inst�_rrr�test_memory_error_subclasses$s	z+ExceptionTests.test_memory_error_subclassesN)>rrrr'rWr_rar|rr�r��unittestZ
skipUnlessrGr�r�r�r�r�r�r�r�r�r�rr�r�r�rrrr
rrrrrrr r"r%r(r,r.r2r9r<rDrErFrMrSrZr\r_rcrfrhrnrorprtrrrrr!"s�T@
/'�
~


t

%



:



'


r!c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ImportErrorTestsc	CsVtd�}|�|j�|�|j�tddd�}|�|jd�|�|j�tddd�}|�|jd�|�|j�tdddd�}|�|jd�|�|jd�d}|�t|��tdd	d
�W5QRX|�t|��tddd	d�W5QRX|�t|��tdd
d	d�W5QRX|�t|��td	d
�W5QRX|�t|��tdd	dd�W5QRXdS)N�testZ
somemodule��name�somepath��path�somename)r|ryz8'invalid' is an invalid keyword argument for ImportError�keyword)�invalidry)ryrr|)r|rT)rZanother)r.r�ryr|r#r�rA)rr$rZrrr�test_attributesDs.z ImportErrorTests.test_attributescCs�tdddd�}|�|jd�|�|jd�|�|jd�|�|jd�|��|�|jd�|�|jd�|�|jd�|�|jd�dS)Nrwryr|�ryr|�rwr)r.r#r�rZryr|rr`rrr�test_reset_attributesfsz&ImportErrorTests.test_reset_attributesc	Cs@tdtfdd��&d}t|�}|�t|�t|��W5QRXdS)Nr/T)�quietsabc)r�BytesWarningr.r#r")r�argr$rrr�test_non_str_argumenttsz&ImportErrorTests.test_non_str_argumentcCs�t�tdd�tdd�tddd�fD]�}td	|�}ttjd�D]R}t�t�||��}|�|jd�|�|j	d�|�|j
|j
�|�|j|j�q>tjtj
fD]H}||�}|�|jd�|�|j	d�|�|j
|j
�|�|j|j�q�q"dS)
Nr}rxrzr{r�rwr7r�)rw)�dictr.rOr�r�rLr�r#r�rZryr|�copy�deepcopy)r�kwargsZorig�protor$rVrrr�test_copy_pickle{s$
�
z!ImportErrorTests.test_copy_pickleN)rrrr�r�r�r�rrrrrvBs"rv�__main__)r��gcr]rGrur�r�r�Ztest.supportrrrrrrrr	r
rrrwr
rrrrZTestCaser!rvrrlrrrr�<module>s44*M

F1le Man4ger