HEX
Server: Apache
System: Linux bd12.noc223.com 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User: handcraf (1693)
PHP: 8.1.28
Disabled: NONE
Upload Files
File: //opt/alt/python312/lib64/python3.12/test/__pycache__/test_fileinput.cpython-312.opt-2.pyc
�

�h�ej���f�	ddlZddlZddlZddlZddlZddlZddlZddlZddlZ	ddl	Z		ddlZddlmZm
Z
ddlmZmZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZGd�d�ZGd
�d�ZGd�deej<�ZGd�d�Z Gd�deej<�Z!Gd�d�Z"Gd�dej<�Z#Gd�de#�Z$Gd�de#�Z%Gd�de#�Z&Gd�d e#�Z'Gd!�d"e#�Z(Gd#�d$e#�Z)Gd%�d&e#�Z*Gd'�d(e#�Z+Gd)�d*e#�Z,Gd+�d,�Z-Gd-�d.ej<�Z.Gd/�d0ej<�Z/Gd1�d2ej<�Z0e1d3k(rejd�yy#e
$rdZ	Y��vwxYw#e
$rdZY��wxYw)4�N)�BytesIO�StringIO)�	FileInput�hook_encoded)�Path)�verbose)�TESTFN)�unlink)�	os_helper)�support)�mockc��eZdZdd�d�Zy)�	BaseTests�w��modec���tj�\}}|jtj|�d|vrdnd}t|||��5}|j
|�ddd�|S#1swY|SxYw)N�b�utf-8��encoding)�tempfile�mkstemp�
addCleanuprr
�open�write)�self�contentr�fd�namer�fs       �:/opt/alt/python312/lib64/python3.12/test/test_fileinput.py�writeTmpzBaseTests.writeTmp+si���#�#�%���D����	�(�(�$�/��$�;�4�G��
�"�d�X�
.�	�!�
�G�G�G��	���	���s�A*�*A4N)�__name__�
__module__�__qualname__r#��r"rr(s��),�r(rc�>�eZdZd�Zed��Zd�Zdd�Zd	d�Zd�Z	y)
�
LineReaderc��g|_y�N��
_linesread�rs r"�__init__zLineReader.__init__5s	����r(c�H�	|jddg|_S#g|_wxYwr,r-r/s r"�	linesreadzLineReader.linesread8s"��	!��?�?�1�%� �D�O��b�D�O�s��	!c�D�t|jd��|_|S�NT)�iter�
splitlines�it)r�filenamers   r"�openhookzLineReader.openhook?s���x�*�*�4�0�1����r(Nc�h�t|jd�}|jj|�|S)N�)�nextr7r.�append)r�size�lines   r"�readlinezLineReader.readlineCs)���D�G�G�R� �������t�$��r(c��g}d}	|j�}|s|S|j|�|t|�z
}||k\r|S�;�Nr)r@r=�len)r�hint�linesr>r?s     r"�	readlineszLineReader.readlinesHsM��������=�=�?�D�����L�L����C��I��D��t�|���r(c��yr,r'r/s r"�closezLineReader.closeTs��r(r,)���)
r$r%r&r0�propertyr2r9r@rFrHr'r(r"r*r*3s/����!��!���

�
r(r*c��eZdZd�Zy)�BufferSizesTestsc��|jdjd�td�D���}|jdjd�td�D���}|jdjd�td�D���}|jdjd�td	�D���}tjd
�}t
rt
d�t||||fd�
�}t|�}|j�|jt|�d�|j|dd�|j|dd�|j|j�d�|j|j�|�t
rt
d�t||||fd�
�}d}|r|dk7r|j�}|r|dk7r�|j|j�|�|j|j�d�|j|j�d�|j!|j#��|j!|j%��t
rt
d�|j'�|j|j�d�|j|j�d�|j�t
rt
d�t||||dfd�
�}t(j*}		t-d�t(_t|�}|jt|�d�|j|dd �|j|j�d!�|j'�|	t(_t
rt
d"�t||||fd�
�}|j|j�d#�|j|j�d�|j'�|j|j�d#�|j|j�d�t
rt
d$�t(j.}
	t||||fd	d�%�}|D] }|dd&j1�}t
|��"|j�|
t(_t||||fd�
�}|D]u}|j|d&d'�|j3|dd&�}|j5|d�|jt7|j9d	��|j���w|j�y#|	t(_wxYw#|
t(_wxYw)(Nr;c3�,K�|]}d|dzz���y�w)zLine %s of file 1
�Nr'��.0�is  r"�	<genexpr>z5BufferSizesTests.test_buffer_sizes.<locals>.<genexpr>Z�����"T�Q�#8�A�a�C�#@�"T����c3�,K�|]}d|dzz���y�w)zLine %s of file 2
rONr'rPs  r"rSz5BufferSizesTests.test_buffer_sizes.<locals>.<genexpr>[rTrU�
c3�,K�|]}d|dzz���y�w)zLine %s of file 3
rONr'rPs  r"rSz5BufferSizesTests.test_buffer_sizes.<locals>.<genexpr>\�����"S�Q�#8�A�a�C�#@�"S�rU�c3�,K�|]}d|dzz���y�w)zLine %s of file 4
rONr'rPs  r"rSz5BufferSizesTests.test_buffer_sizes.<locals>.<genexpr>]rZrUrOzLINE (\d+) OF FILE (\d+)z1. Simple iterationr��filesr��zLine 5 of file 1
�zLine 1 of file 4
z2. Status variables�xzLine 6 of file 2
��z3. NextfilezLine 1 of file 3
�z4. Stdin�-z Line 1 of stdin
Line 2 of stdin
�!� zLine 2 of stdin
z<stdin>z5. Boundary conditionsrz
6. Inplace�r^�inplacerrI�
)r#�join�range�re�compiler�printr�listrH�assertEqualrC�linenor8r@�
filelineno�assertFalse�isfirstline�isstdin�nextfile�sys�stdinr�stdout�upper�match�assertNotEqual�int�group)
r�t1�t2�t3�t4�pat�firE�s�	savestdin�
savestdoutr?�ms
             r"�test_buffer_sizesz"BufferSizesTests.test_buffer_sizesXsS��
�]�]�2�7�7�"T�%�PR�)�"T�T�
U��
�]�]�2�7�7�"T�%�PR�)�"T�T�
U��
�]�]�2�7�7�"S�%�PQ�(�"S�S�
T��
�]�]�2�7�7�"S�%�PQ�(�"S�S�
T���j�j�4�5����'�(�
�b�"�b�"�-��
@���R���
���
�����U��R�(�����q��#7�8�����r��$8�9��������b�)���������+���'�(�
�b�"�b�"�-��
@�����A�-�-����
�A��A�-�-���������+��������b�)��������!�,�������)�*��������&���-� �
���
��������(<�=��������b�)�
���
���*��
�b�"�b�"�c�2�W�
E���I�I�	�	"� �!E�F�C�I���H�E����S��Z��,����U�2�Y�(;�<����R�[�[�]�I�6��K�K�M�!�C�I���*�+�
�b�"�b�"�-��
@���������a�(���������-�
���
��������a�(���������-���,���Z�Z�
�	$��"�b�"�b�!1�1�w�O�B��
���C�R�y���(���d��
�
�H�H�J�#�C�J�
�b�"�b�"�-��
@���	?�D����T�"�X�t�,��	�	�$�s��)�$�A�����4�(����S������_�b�m�m�o�>�		?�
	���
��;"�C�I��*$�C�J�s�A?U*�<AU:�*
U7�:
VN)r$r%r&r�r'r(r"rLrLWs��Pr(rLc��eZdZd�Zd�Zy)�UnconditionallyRaisec� �||_d|_y�NF)�exception_type�invoked)rr�s  r"r0zUnconditionallyRaise.__init__�s��,�����r(c�0�d|_|j��r4)r�r��r�args�kwargss   r"�__call__zUnconditionallyRaise.__call__�s������!�!�#�#r(N�r$r%r&r0r�r'r(r"r�r��s���$r(r�c��eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�FileInputTestsc���|jd�}|jd�}|jd�}|jd�}t||||fd��}|j�}|j|d�|j|j	�d�|j|j�d�|j|j
�|�|j�}|j|�|j|j	�d�|j|j�d�|j|j
�|�|j�y)Nr;zThe only line there is.
rr]rOr)	r#rr@rrrsrtr8rurH)rr�r�r�r�r�r?s       r"�test_zero_byte_filesz#FileInputTests.test_zero_byte_files�s��
�]�]�2�
��
�]�]�2�
��
�]�]�6�
7��
�]�]�2�
��
�b�"�b�"�-��
@���{�{�}������:�;��������a�(��������!�,���������+��{�{�}��������������a�(��������!�,���������+�
���
r(c�$�|jd�}|jd�}t||fd��}t|�}|j|gd��|j|j	�d�|j|j�d�y)N�A
B
C�D
E
Frr]��A
�B
�CzD
zE
�F�rd)r#rrqrrrtrs�rr�r�r�rEs     r"�%test_files_that_dont_end_with_newlinez4FileInputTests.test_files_that_dont_end_with_newline�st��
�]�]�9�
%��
�]�]�9�
%��
�b�"�X��
8���R������� F�G��������!�,��������a�(r(c��|jd�}|jd�}t||fd��}|j|j�d�t	|�}|j|j�d�|j
�|j|j�d�t|�}|j|j�d�y)NzA
BzC
Drr]rI)r#rrr�filenor<r~rxrq)rr�r�r�r?s     r"�test_filenozFileInputTests.test_fileno�s���
�]�]�6�
"��
�]�]�6�
"��
�b�"�X��
8���������b�)��B�x�����B�I�I�K��,�
���
��������b�)��B�x���������b�)r(c���dD]G}|j|��5|jt�5t|��ddd�ddd��Iy#1swY�xYw#1swY�`xYw)N)r�rU�Ur)�subTest�assertRaises�
ValueErrorr)rrs  r"�test_invalid_opening_modez(FileInputTests.test_invalid_opening_mode�sd��$�	)�D����4��(�
)��&�&�z�2�)��4�(�)�
)�
)�	)�)�)��
)�
)�s!�A�
A�A�A�A�A#	c���tjd�5}td�|_t	dgd��}t|�}|j
|dg�ddd�y#1swYyxYw)Nz	sys.stdin�spam, bacon, sausage, and spamrf�rb�r^r)r
�patchr�bufferrrqrr)r�m_stdinr�rEs    r"�test_stdin_binary_modez%FileInputTests.test_stdin_binary_mode�sa��
�Z�Z��
$�	I��$�%F�G�G�N��#��T�2�B���H�E����U�%F�$G�H�		I�	I�	I�s�=A�A%c�.�tj}	td�t_|jt	tjd��tdgd��}t
|�}|j|dg�|t_y#|t_wxYw)Nr�r�rfr�r�)ryrzrru�hasattrrrqrr)r�
orig_stdinr�rEs    r"�test_detached_stdin_binary_modez.FileInputTests.test_detached_stdin_binary_mode�sp���Y�Y�
�	#�� A�B�C�I����W�S�Y�Y��9�:��#��T�2�B���H�E����U�%F�$G�H�"�C�I��
�C�I�s�A)B�
Bc��	tdd���}|jd�	td��}|jd�Gd�d�}|jd	�}|�}t|g|��5}|j	�ddd�|j|jd
�y#t$rY��wxYw#t$rY��wxYw#1swY�DxYw)NrOc��yr,r')r!r�s  r"�<lambda>z7FileInputTests.test_file_opening_hook.<locals>.<lambda>��r()rjr9zGFileInput should raise if both inplace and openhook arguments are given�r9z2FileInput should check openhook for being callablec��eZdZd�Zd�Zy)�=FileInputTests.test_file_opening_hook.<locals>.CustomOpenHookc��d|_yr�)r�r/s r"r0zFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__init__s	��$��r(c�&�d|_t|ddi�S)NTrr)r�r)rr��kargss   r"r�zFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__call__s��#����T�4�G�4�4r(Nr�r'r(r"�CustomOpenHookr�s��
%�
5r(r�rkzopenhook not invoked)r�failr�r#r@�
assertTruer�)rr�r��t�custom_open_hooks     r"�test_file_opening_hookz%FileInputTests.test_file_opening_hooks���	��1�/@�A�B��I�I�@�
A�	��A�&�B��I�I�J�K�	5�	5�
�M�M�$���)�+��
��s�%5�
6�	�"��K�K�M�	����(�0�0�2H�I��'�	��	��
�	��	��	�	�s.�B%�B4�/C�%	B1�0B1�4	C�?C�Cc�:�ttd�5}|jd�|jddz�|jd�ddd�|jtt�ttt
d���5}	|j|j�d�|j|j�d	�|j|j�d
�|jt�5t|�ddd�|j|j�d�|j|j�d�ddd�y#1swY��xYw#t$r|jd�Y��wxYw#1swY�xYw#1swYyxYw)
N�wbsA
B
C
s
123456789
i����ascii�r^r9r�r��C
zRead to end of filer;)
rr	rr�safe_unlinkrrrrr@�UnicodeDecodeErrorr�r�rq�rr!r�s   r"�
test_readlinezFileInputTests.test_readlinesJ��
�&�$�
�	�1�
�G�G�N�#�
�G�G�N�T�)�*�
�G�G�G��	�	
����V�,�
�V� ,�W� 5�7�	0�:<�
1�� � ������6�� � ������6�� � ������6��"�"�#5�6�
��R��
�
���R�[�[�]�B�/����R�[�[�]�B�/�	0�	0�	�	��&�
1��	�	�/�0�
1��
�
��	0�	0�sU�7E�F�A E%�&F�;F�AF�E"�%F�?F�F�F�F	�
F�Fc�0�ttd�5}|jd�ddd�|jtt�ttd��5}|j
|j�d�|j
|j�d�|j
|j�d�|j
|j�d�|j
|j�d�ddd�y#1swY��xYw#1swYyxYw)	Nr�sA
B
C
Dr�r�sA
sB
sC
Dr()rr	rrr�rrrr@r�s   r"�test_readline_binary_modez(FileInputTests.test_readline_binary_mode2s���
�&�$�
�	%�1�
�G�G�O�$�	%�����V�,�
�V�$�
/�	1�2����R�[�[�]�F�3����R�[�[�]�H�5����R�[�[�]�G�4����R�[�[�]�C�0����R�[�[�]�C�0�
	1�	1�		%�	%��	1�	1�s�D�B!D�D	�Dc�t�|jdd��}t|dd��5}|j�}|j|d�tj
j
d�ddd�t|d�5}|j|j�d�ddd�y#1swY�?xYw#1swYyxYw)Ns
Initial text.r�rr�T)rrjs	New line.)	r#rr@rrryr{rr�read�r�	temp_file�fobjr?r!s     r"�test_inplace_binary_write_modez-FileInputTests.test_inplace_binary_write_mode?s����M�M�"2��M�>�	�
�y�t�T�
:�	+�d��=�=�?�D����T�#3�4��J�J���\�*�		+�
�)�T�
"�	5�a����Q�V�V�X�|�4�	5�	5�	+�	+��
	5�	5�s�AB"�8!B.�"B+�.B7c�l�|jdd��}t|ddd��5}|j�}|j|d�t	d	�ddd�t|d
�5}|j|j
�jd�d�ddd�y#1swY�NxYw#1swYyxYw)
NsInitial text �r�rTr��replace)rjr�errorsuInitial text �uNew line ˆr�s
s
New line ?)r#rr@rrrprr��rstripr�s     r"�test_inplace_encoding_errorsz+FileInputTests.test_inplace_encoding_errorsIs����M�M�"6�T�M�B�	�
�y�$� '�	�;�	#�>B��=�=�?�D����T�#8�9��/�"�		#�
�)�T�
"�	F�a����Q�V�V�X�_�_�W�5�}�E�	F�	F�	#�	#��
	F�	F�s�.B�%0B*�B'�*B3c��d�}|jd�}t|g|��5}|j�}ddd�|jd�y#1swY�xYw)Nc�,�tjd�S)N�(I used to receive only filename and mode)�ior�r8rs  r"�old_hookzFFileInputTests.test_file_hook_backward_compatibility.<locals>.old_hookTs���;�;�I�J�Jr(rkr�r�)r#rr@rr)rr�r�r��results     r"�%test_file_hook_backward_compatibilityz4FileInputTests.test_file_hook_backward_compatibilitySsU��	K��M�M�$���
��s�X�
.�	#�"��[�[�]�F�	#�����!K�L�	#�	#�s�A�Ac��|jd�}|jd�}t||fd��5}t|�}ddd�|jgd��|jj	�d�|j|j�d�|j|jd�y#1swY�zxYw)	Nr�r�rr]r�r�rdr')r#rrqrrrtrs�_filesr�s     r"�test_context_managerz#FileInputTests.test_context_manager[s���
�]�]�9�
%��
�]�]�9�
%��
�b�"�X��
8�	�B���H�E�	����� F�G��������!�,��������a�(�������B�'�	�	�s�B7�7Cc��|jd�}	t|d��5}t�#1swYyxYw#t$r|jjd�YywxYw)Nr;rr]r')r#r�OSErrorrrr�)rr�r�s   r"�test_close_on_exceptionz&FileInputTests.test_close_on_exceptionesX��
�]�]�2�
��	,���g�6�
�"��
�
�
���	,����R�Y�Y��+�	,�s�
3�'�0�3�3�%A�Ac��tgd��5}|j|jd�ddd�y#1swYyxYw)Nrr])rf)rrrr�)rr�s  r"�.test_empty_files_list_specified_to_constructorz=FileInputTests.test_empty_files_list_specified_to_constructorms7��
�R�'�
2�	0�b����R�Y�Y��/�	0�	0�	0�s�4�=c��	tj}tt�}	|j	d�}|jt|dz�t|gdd��5}t|�|t_|j�ddd�|t_|j|jd�y#1swY�1xYw#|t_wxYw)Nrkz.bakTrrizos.unlink() was not invoked)�osr
r�r�r#rr�rr<rxr�r�)r�os_unlink_orig�os_unlink_replacementr�r�s     r"�%test_nextfile_oserror_deleting_backupz4FileInputTests.test_nextfile_oserror_deleting_backupqs���	����� 4�W� =��	'��
�
�d�#�A��O�O�K��V��4��!��d�W�E�
���R��1��	����
�
�
'�B�I�	
���-�5�5�5�	7�
�
��
'�B�I�s#�9B>�'B2�B>�2B;�7B>�>
Cc�T�	tj}tt�}	|j	d�}t|gdd��5}|t_|j
�ddd�|t_|j|jd�y#1swY�1xYw#|t_wxYw�NrkTrrizos.fstat() was not invoked)	r��fstatr�r�r#rr@r�r�)r�
os_fstat_orig�os_fstat_replacementr�r�s     r"�%test_readline_os_fstat_raises_OSErrorz4FileInputTests.test_readline_os_fstat_raises_OSError����	;����
�3�G�<��	%��
�
�d�#�A��!��d�W�E�
��/������
�
�%�B�H�	
���,�4�4�4�	6�
�
��%�B�H��#� B�B�B�B�B�
B'c�T�	tj}tt�}	|j	d�}t|gdd��5}|t_|j
�ddd�|t_|j|jd�y#1swY�1xYw#|t_wxYwr�)	r��chmodr�r�r#rr@r�r�)r�
os_chmod_orig�os_chmod_replacementr�r�s     r"�%test_readline_os_chmod_raises_OSErrorz4FileInputTests.test_readline_os_chmod_raises_OSError�r�rc�f�Gd�dt�}|�}|jd�}t|gd��5}|j}	||_|j	�}||_	ddd�|j|jd�|jdd�y#||_wxYw#1swY�ExYw)	Nc��eZdZd�Zd�Zy)�QFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueErrorc�8�tj|t�yr,)r�r0r�r/s r"r0zZFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.__init__�s��$�-�-�d�J�?r(c�$�|j�yr,)r�r/s r"r�zXFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.fileno�s���
�
�r(N)r$r%r&r0r�r'r(r"�FilenoRaisesValueErrorr�s
��
@�
 r(rrkrr]z_file.fileno() was not invokedrIzfileno() should return -1)r�r#r�_filer�r�r�rr)rr� unconditionally_raise_ValueErrorr�r��file_backupr�s       r"�"test_fileno_when_ValueError_raisedz1FileInputTests.test_fileno_when_ValueError_raised�s���	 �%9�	 �,B�+C�(��M�M�$���
�a�S�7�
3�	'�r��(�(�K�
'�;��������&���
	'�	
���8�@�@�8�	:�	
�����%@�A��
'����
	'�	'�s#�
B'�B�B'�	B$�$B'�'B0c��t�}tddg|j��5}|j|jg�|j|j�d�|j|jdg�|j|j�d�|j|jdg�|j|j�d�|j|jddg�|j|j�d�|j|jdg�|j|j�d�|j|jg�ddd�y#1swYyxYw�Nzline1
line2zline3
r�zline1
�line2r;)r*rr9rrr2r@�r�srcr�s   r"�test_readline_bufferingz&FileInputTests.test_readline_buffering�s'���l��
�n�i�8� #���.�	0�13����S�]�]�B�/����R�[�[�]�I�6����S�]�]�Y�K�8����R�[�[�]�G�4����S�]�]�W�I�6����R�[�[�]�I�6����S�]�]�R��O�<����R�[�[�]�B�/����S�]�]�R�D�1����R�[�[�]�B�/����S�]�]�B�/�	0�	0�	0�s�EE;�;Fc���t�}tddg|j��5}|j|jg�|jt|�d�|j|jdg�|jt|�d�|j|jdg�|jt|�d�|j|jddg�|j
tt
|�|j|jdg�|j
tt
|�|j|jg�ddd�y#1swYyxYwr)r*rr9rrr2r<r��
StopIterationrs   r"�test_iteration_bufferingz'FileInputTests.test_iteration_buffering�s���l��
�n�i�8� #���.�	0�13����S�]�]�B�/����T�"�X�y�1����S�]�]�Y�K�8����T�"�X�w�/����S�]�]�W�I�6����T�"�X�y�1����S�]�]�R��O�<����m�T�2�6����S�]�]�R�D�1����m�T�2�6����S�]�]�B�/�	0�	0�	0�s�D5E"�"E+c��t|jd��}t|d��5}|j�}|j	|d�|j	|j�d�|j	|j
�d�|j	|j�tj|��ddd�y#1swYyxYw)N�
Pathlib file.rrrO)
rr#rr@rrrsrtr8r��fspath)rr�r�r?s    r"�test_pathlib_filez FileInputTests.test_pathlib_file�s���
�$�-�-��0�
1��
�r�G�
,�	;���;�;�=�D����T�?�3����R�Y�Y�[�!�,����R�]�]�_�a�0����R�[�[�]�B�I�I�b�M�:�	;�	;�	;�s�BC�Cc�b�t|jd��}t|dd��5}|j�}|j	|d�td|z�ddd�t
|d��5}|j	|j�d�ddd�y#1swY�@xYw#1swYyxYw)NrTr)rjrzModified %srzModified Pathlib file.
)rr#rr@rrrprr�)rr�r�r?r!s     r"�test_pathlib_file_inplacez(FileInputTests.test_pathlib_file_inplace�s���
�$�-�-��0�
1��
�r�4�'�
:�	(�b��;�;�=�D����T�?�3��-�$�&�'�	(��"�w�
'�	C�1����Q�V�V�X�'A�B�	C�	C�		(�	(��	C�	C�s�1B�/!B%�B"�%B.N)r$r%r&r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrr'r(r"r�r��s{���()�(
*�)�I�	#�J�60�.1�5�F�M�(�,�0�7�*6�$6�$B�.0� 0� ;�Cr(r�c�R�eZdZ	d
ddddd�d�Zd�Zd�Zd�Zd�Zd	�Zd
�Z	d�Z
d�Zy)�
MockFileInputN�r)rr9rr�c��||_||_||_||_||_||_||_d|_tjd��|_
i|_y)Nc��yrBr'r'r(r"r�z(MockFileInput.__init__.<locals>.<lambda>r�r()r^rj�backuprr9rr�r�collections�defaultdict�invocation_counts�
return_values)rr^rjr$rr9rr�s        r"r0zMockFileInput.__init__�sU����
���������	� ��
� ��
������
�!,�!8�!8��!C�����r(c�2�|jdxxdz
cc<y)NrHrO)r'r/s r"rHzMockFileInput.closes�����w�'�1�,�'r(c�N�|jdxxdz
cc<|jdS)NrxrO�r'r(r/s r"rxzMockFileInput.nextfile�)�����z�*�a�/�*��!�!�*�-�-r(c�N�|jdxxdz
cc<|jdS)Nr8rOr+r/s r"r8zMockFileInput.filenamer,r(c�N�|jdxxdz
cc<|jdS)NrsrOr+r/s r"rszMockFileInput.lineno�)�����x�(�A�-�(��!�!�(�+�+r(c�N�|jdxxdz
cc<|jdS)NrtrOr+r/s r"rtzMockFileInput.filelinenos)�����|�,��1�,��!�!�,�/�/r(c�N�|jdxxdz
cc<|jdS)Nr�rOr+r/s r"r�zMockFileInput.filenor/r(c�N�|jdxxdz
cc<|jdS)NrvrOr+r/s r"rvzMockFileInput.isfirstlines)�����}�-��2�-��!�!�-�0�0r(c�N�|jdxxdz
cc<|jdS)NrwrOr+r/s r"rwzMockFileInput.isstdins)�����y�)�Q�.�)��!�!�)�,�,r()NFr;)r$r%r&r0rHrxr8rsrtr�rvrwr'r(r"r r �s@��N� ��D�4�� �-�.�.�,�0�,�1�-r(r c� �eZdZ	d�Zd�Zd�Zy)�BaseFileInputGlobalMethodsTestc�v�tj|_tj|_t
t_yr,)�	fileinput�_state�_orig_stater�_orig_FileInputr r/s r"�setUpz$BaseFileInputGlobalMethodsTest.setUp's&��$�+�+���(�2�2���+�	�r(c�X�|jt_|jt_yr,)r:r7rr9r8r/s r"�tearDownz'BaseFileInputGlobalMethodsTest.tearDown,s��"�2�2�	���+�+�	�r(c��|j|}|j|d|�t|j�}|j|d�y)NrO)r'rrrC)r�mock_file_input�method_name�actual_count�actual_total_counts     r"�assertExactlyOneInvocationz9BaseFileInputGlobalMethodsTest.assertExactlyOneInvocation0sF��&�8�8��E������q�+�6� ��!B�!B�C�����+�Q�/r(N)r$r%r&r;r=rCr'r(r"r5r5#s�� �,�
,�0r(r5c�&�eZdZ	d�Zd�Zd�Zd�Zy)�Test_fileinput_inputc�X�	t�}t�|_|t_|jt�5}tj�ddd�|jdjj�|j|tjd�y#1swY�QxYw)N)zinput() already active�fileinput._state)r �objectrr7r8r��RuntimeError�inputrr�	exceptionr��assertIs)r�instance�cms   r"�1test_state_is_not_None_and_state_file_is_not_NonezFTest_fileinput_input.test_state_is_not_None_and_state_file_is_not_None;s���	$�!�?������#�	��
�
�
�|�
,�	���O�O��	����4�b�l�l�6G�6G�H��
�
�h�	� 0� 0�2D�E�	�	�s�B � B)c�^�	t�}d|_|t_|j	�yr,)r rr7r8�do_test_call_input�rrMs  r"�-test_state_is_not_None_and_state_file_is_NonezBTest_fileinput_input.test_state_is_not_None_and_state_file_is_NoneHs,��	@�
!�?�����#�	�����!r(c�<�	dt_|j�yr,)r7r8rQr/s r"�test_state_is_Nonez'Test_fileinput_input.test_state_is_NoneSs��	�
 �	�����!r(c��	t�}t�}t�}t�}t�}t�}tj||||||��}|j|tjd�|j||j
d�|j||jd�|j||jd�|j||jd�|j||jd�y)N)r^rjr$rr9rrGr^rjr$rr9)
rHr7rJrLr8r^rjr$rr9)rr^rjr$rr9rr�s        r"rQz'Test_fileinput_input.do_test_call_input\s���	F�����(������x���8���8�����u�g�f���8�=��	
�
�
�f�i�.�.�0B�C�	
�
�
�e�V�\�\�7�3��
�
�g�v�~�~�y�9��
�
�f�f�m�m�X�6��
�
�d�F�K�K��0��
�
�h�����<r(N)r$r%r&rOrSrUrQr'r(r"rErE8s��*�F�	"�"�=r(rEc��eZdZ	d�Zd�Zy)�Test_fileinput_closec��	dt_tj�|jtj�yr,)r7r8rH�assertIsNoner/s r"rUz'Test_fileinput_close.test_state_is_Nonezs-��	��	���������)�*�*�+r(c��	t�}|t_tj�|j	|d�|jtj�y)NrH)r r7r8rHrCrZrRs  r"�test_state_is_not_Nonez+Test_fileinput_close.test_state_is_not_None�sD��	#� �?��#�	�������'�'��'�:����)�*�*�+r(N�r$r%r&rUr\r'r(r"rXrXws��*�,�,r(rXc��eZdZ	d�Zd�Zy)�Test_fileinput_nextfilec�"�	dt_|jt�5}tj�ddd�|jdjj�|jtj�y#1swY�OxYw�N)zno active input())	r7r8r�rIrxrrrKr�rZ�rrNs  r"rUz*Test_fileinput_nextfile.test_state_is_None��q��	3� �	��
�
�
�|�
,�	!����� �	!����/����1B�1B�C����)�*�*�+�	!�	!���B�Bc��	t�}t�}||jd<|t_tj
�}|j
|d�|j||�|jtj|�y)Nrx)rHr r(r7r8rxrCrL)r�nextfile_retvalrM�retvals    r"r\z.Test_fileinput_nextfile.test_state_is_not_None��o��	.�!�(�� �?��-<����z�*�#�	���#�#�%���'�'��*�=��
�
�f�o�.��
�
�i�&�&��1r(Nr]r'r(r"r_r_����-�,�2r(r_c��eZdZ	d�Zd�Zy)�Test_fileinput_filenamec�"�	dt_|jt�5}tj�ddd�|jdjj�|jtj�y#1swY�OxYwra)	r7r8r�rIr8rrrKr�rZrbs  r"rUz*Test_fileinput_filename.test_state_is_None�rcrdc��	t�}t�}||jd<|t_tj
�}|j
|d�|j||�|jtj|�y)Nr8)rHr r(r7r8r8rCrL)r�filename_retvalrMrgs    r"r\z.Test_fileinput_filename.test_state_is_not_None�rhr(Nr]r'r(r"rkrk�rir(rkc��eZdZ	d�Zd�Zy)�Test_fileinput_linenoc�"�	dt_|jt�5}tj�ddd�|jdjj�|jtj�y#1swY�OxYwra)	r7r8r�rIrsrrrKr�rZrbs  r"rUz(Test_fileinput_lineno.test_state_is_None��q��	3� �	��
�
�
�|�
,�	������	����/����1B�1B�C����)�*�*�+�	�	�rdc��	t�}t�}||jd<|t_tj
�}|j
|d�|j||�|jtj|�y)Nrs)rHr r(r7r8rsrCrL)r�
lineno_retvalrMrgs    r"r\z,Test_fileinput_lineno.test_state_is_not_None�so��	.���
� �?��+8����x�(�#�	���!�!�#���'�'��(�;��
�
�f�m�,��
�
�i�&�&��1r(Nr]r'r(r"rprp�s��+�,�2r(rpc��eZdZ	d�Zd�Zy)�Test_fileinput_filelinenoc�"�	dt_|jt�5}tj�ddd�|jdjj�|jtj�y#1swY�OxYwra)	r7r8r�rIrtrrrKr�rZrbs  r"rUz,Test_fileinput_filelineno.test_state_is_None�sq��	3� �	��
�
�
�|�
,�	#��� � �"�	#����/����1B�1B�C����)�*�*�+�	#�	#�rdc��	t�}t�}||jd<|t_tj
�}|j
|d�|j||�|jtj|�y)Nrt)rHr r(r7r8rtrCrL)r�filelineno_retvalrMrgs    r"r\z0Test_fileinput_filelineno.test_state_is_not_None�sq��	.�#�H�� �?��/@����|�,�#�	���%�%�'���'�'��,�?��
�
�f�/�0��
�
�i�&�&��1r(Nr]r'r(r"rvrv�s��/�,�2r(rvc��eZdZ	d�Zd�Zy)�Test_fileinput_filenoc�"�	dt_|jt�5}tj�ddd�|jdjj�|jtj�y#1swY�OxYwra)	r7r8r�rIr�rrrKr�rZrbs  r"rUz(Test_fileinput_fileno.test_state_is_None�rrrdc� �	t�}t�}||jd<||_|t_t	j�}|j|d�|j||�|jtj
|�y)Nr�)	rHr r(�
fileno_retvalr7r8r�rCrL)rr~rMrgs    r"r\z,Test_fileinput_fileno.test_state_is_not_Nonesw��	.���
� �?��+8����x�(�!.���#�	���!�!�#���'�'��(�;��
�
�f�m�,��
�
�i�&�&��1r(Nr]r'r(r"r{r{�s��+�,�
2r(r{c��eZdZ	d�Zd�Zy)�Test_fileinput_isfirstlinec�"�	dt_|jt�5}tj�ddd�|jdjj�|jtj�y#1swY�OxYwra)	r7r8r�rIrvrrrKr�rZrbs  r"rUz-Test_fileinput_isfirstline.test_state_is_Nonesq��	3� �	��
�
�
�|�
,�	$���!�!�#�	$����/����1B�1B�C����)�*�*�+�	$�	$�rdc��	t�}t�}||jd<|t_tj
�}|j
|d�|j||�|jtj|�y)Nrv)rHr r(r7r8rvrCrL)r�isfirstline_retvalrMrgs    r"r\z1Test_fileinput_isfirstline.test_state_is_not_Nonesq��	.�$�X�� �?��0B����}�-�#�	���&�&�(���'�'��-�@��
�
�f�0�1��
�
�i�&�&��1r(Nr]r'r(r"r�r�s��0�,�2r(r�c��eZdZ	d�Zd�Zy)�Test_fileinput_isstdinc�"�	dt_|jt�5}tj�ddd�|jdjj�|jtj�y#1swY�OxYwra)	r7r8r�rIrwrrrKr�rZrbs  r"rUz)Test_fileinput_isstdin.test_state_is_None0sq��	3� �	��
�
�
�|�
,�	 ������	 ����/����1B�1B�C����)�*�*�+�	 �	 �rdc��	t�}t�}||jd<|t_tj
�}|j
|d�|j||�|jtj|�y)Nrw)rHr r(r7r8rwrCrL)r�isstdin_retvalrMrgs    r"r\z-Test_fileinput_isstdin.test_state_is_not_None:so��	.� ��� �?��,:����y�)�#�	���"�"�$���'�'��)�<��
�
�f�n�-��
�
�i�&�&��1r(Nr]r'r(r"r�r�-s��,�,�2r(r�c��eZdZd�Zd�Zy)�InvocationRecorderc��d|_yrB)�invocation_countr/s r"r0zInvocationRecorder.__init__Js
�� !��r(c�h�|xjdz
c_||f|_tjd�S)NrOs
some bytes)r��last_invocationr�rr�s   r"r�zInvocationRecorder.__call__Ms.������"�� $�f�~����z�z�-�(�(r(Nr�r'r(r"r�r�Hs��"�)r(r�c���eZdZ	d�Zd�Zd�Zejed�d��Z	ejed�d��Z
ejed�d��Zd	�Z
d
�Zd�Zd�Zd
�Zd�Zd�Zed��Zy)�Test_hook_compressedc�"�t�|_yr,)r��	fake_openr/s r"r;zTest_hook_compressed.setUpVs��+�-��r(c�(�|jdd�y)Nr;r!��do_test_use_builtin_open_textr/s r"�test_empty_stringz&Test_hook_compressed.test_empty_stringYs���*�*�2�s�3r(c�(�|jdd�y�N�abcdr!r�r/s r"�test_no_extz Test_hook_compressed.test_no_ext\����*�*�6�3�7r(zRequires gzip and zlibc�N�tj}|jt_	tjdd�}|t_|j|jjd�|j|jjdif�y#|t_wxYw)N�test.gzr!rO)r�r!)�gziprr�r7�hook_compressedrrr�r��r�
original_openr�s   r"�test_gz_ext_fakez%Test_hook_compressed.test_gz_ext_fake_sy���	�	�
��N�N��	�	&��.�.�y�#�>�F�%�D�I�������8�8�!�<�������7�7�:J�B�9O�P��&�D�I���B�
B$c���tj}d�t_	tjddd��}|t_|j	t|�dg�y#|t_wxYw)Nc�,�tjd�S)NsEx-binary string)r�rr�s  r"r�zATest_hook_compressed.test_gz_with_encoding_fake.<locals>.<lambda>ns��2�:�:�6I�+J�r(r�r!rrzEx-binary string)r�rr7r�rrrqr�s   r"�test_gz_with_encoding_fakez/Test_hook_compressed.test_gz_with_encoding_fakeksU���	�	�
�J��	�	&��.�.�y�#��P�F�%�D�I�����f��(:�';�<��&�D�I�s�A�
A+zRequires bz2c�N�tj}|jt_	tjdd�}|t_|j|jjd�|j|jjdif�y#|t_wxYw)N�test.bz2r!rO)r�r!)�bz2�BZ2Filer�r7r�rrr�r�r�s   r"�test_bz2_ext_fakez&Test_hook_compressed.test_bz2_ext_fakeusy�����
��n�n���	(��.�.�z�3�?�F�'�C�K�������8�8�!�<�������7�7�:K�R�9P�Q��(�C�K�r�c�(�|jdd�y)Nz	abcd.blahr���do_test_use_builtin_open_binaryr/s r"�
test_blah_extz"Test_hook_compressed.test_blah_ext�s���,�,�[�$�?r(c�(�|jdd�y)Nzabcd.Gzr�r�r/s r"�test_gz_ext_builtinz(Test_hook_compressed.test_gz_ext_builtin�s���,�,�Y��=r(c�(�|jdd�y)Nzabcd.Bz2r�r�r/s r"�test_bz2_ext_builtinz)Test_hook_compressed.test_bz2_ext_builtin�s���,�,�Z��>r(c�(�|jdd�y)Nr�r�r�r/s r"�test_binary_mode_encodingz.Test_hook_compressed.test_binary_mode_encoding�s���,�,�V�T�:r(c�(�|jdd�yr�r�r/s r"�test_text_mode_encodingz,Test_hook_compressed.test_text_mode_encoding�r�r(c�\�|j|j�}	tj||�}|j|�|j	|jj
d�|j	|jj||fddd�f�y#|j|�wxYw)NrO�rr���replace_builtin_openr�r7r�rrr�r��rr8rr�r�s     r"r�z4Test_hook_compressed.do_test_use_builtin_open_binary�s����1�1�$�.�.�A�
�	5��.�.�x��>�F��%�%�m�4�������8�8�!�<�������7�7�#�T�*���,N�O�	Q��
�%�%�m�4���B�B+c�\�|j|j�}	tj||�}|j|�|j	|jj
d�|j	|jj||fddd�f�y#|j|�wxYw)NrO�localer�r�r�s     r"r�z2Test_hook_compressed.do_test_use_builtin_open_text�s����1�1�$�.�.�A�
�	5��.�.�x��>�F��%�%�m�4�������8�8�!�<�������7�7�#�T�*��T�,R�S�	U��
�%�%�m�4�r�c�<�tj}|t_|Sr,)�builtinsr)�
new_open_funcr�s  r"r�z)Test_hook_compressed.replace_builtin_open�s�� �
�
�
�%��
��r(N)r$r%r&r;r�r��unittest�
skipUnlessr�r�r�r�r�r�r�r�r�r�r�r��staticmethodr�r'r(r"r�r�Ss���4�.�4�8��X����7�8�	Q�9�	Q��X����7�8�=�9�=��X����n�-�	R�.�	R�@�>�?�;�8�	Q�	U����r(r�c� �eZdZ	d�Zd�Zd�Zy)�Test_hook_encodedc�f�t�}t�}tj||��}t�}tj
}|t_	t�}t�}|||�}|t_|j
|jd�|j\}	}
|j|	d|�|j|	d|�|j|
jd�|�|j|
jd�|�|j|
�y#|t_wxYw)N�r�rOrrr�)rHr7rr�r�rrrr�r�rL�popru)rrr�r�r�r�r8r�open_resultr�r�s           r"�testzTest_hook_encoded.test�s����8������'�'���@��&�(�	� �
�
�
�!��
�	*��x�H��8�D� ��4�0�K�)�H�M�����3�3�Q�7� �0�0���f��
�
�d�1�g�x�(��
�
�d�1�g�t�$��
�
�f�j�j��,�h�7��
�
�f�j�j��*�F�3����� ��*�H�M�s�D#�#
D0c�T��ttd�5}|jd�ddd��jtt��fd�}|ddg��jt�5|ddg�ddd�|ddg�|d	d
g�y#1swY�oxYw#1swY�*xYw)Nr�s�abcc���ttdtd|����5}t|�}ddd��j	|�y#1swY�xYw)Nr!rr��r^rr9�rr	rrqrr)r��expected_linesr�rErs    �r"�checkz,Test_hook_encoded.test_errors.<locals>.check�sM�����c�$0���$H�J�
!�MO��R���
!�
���U�N�3�
!�
!�s�A�A�ignore�abc�strictr�u�abc�backslashreplacez\x80abc)rr	rrr�r�r��rr!r�s`  r"�test_errorszTest_hook_encoded.test_errors�s����
�&�$�
�	 �1�
�G�G�J��	 �����V�,�	4�	�h��� �
�
�
�1�
2�	%��(�U�G�$�	%�
�i�+��'�
� �:�,�/�	 �	 ��	%�	%�s�B�*B�B�B'c�0��ttd�5}|jd�ddd��jtt��fd�}|dgd���jt�5|dgd��ddd�y#1swY�]xYw#1swYyxYw)Nr�s
A
B
C
D+IKw-c���tt|td���5}t|�}ddd��j	|�y#1swY�xYw)Nzutf-7r�r�)rr�r�rErs    �r"r�z+Test_hook_encoded.test_modes.<locals>.check�sJ�����d�$0��$9�;�
!�>@��R���
!�
���U�N�3�
!�
!�s�A�A
r!)r�r�r��D€r�)r�zB
zC
r�)rr	rrr�r�r�r�s`  r"�
test_modeszTest_hook_encoded.test_modes�s����
�&�$�
�	*�1�
�G�G�(�)�	*�	
����V�,�	4�	�c�3�4�
�
�
�z�
*�	<��$�:�;�	<�	<�	*�	*��	<�	<�s�B�+B�B	�BN)r$r%r&r�r�r�r'r(r"r�r��s��1�!�00�"<r(r�c��eZdZd�Zy)�MiscTestc�8�tj|t�yr,)r�check__all__r7r/s r"�test_allzMiscTest.test_all�s�����T�9�-r(N)r$r%r&r�r'r(r"r�r��s��.r(r��__main__)3r�r�ryrnr7r%r�rr�r��ImportErrorr�rrrr�pathlibr�test.supportr�test.support.os_helperr	r
r�rr�rr
rr*�TestCaserLr�r�r r5rErXr_rkrprvr{r�r�r�r�r�r�r$�mainr'r(r"�<module>r�s����
�	�
�	����������!�-�� �)�8�"���	�	�"
�"
�HQ�y�(�"3�"3�Q�f$�$�C�Y�� 1� 1�C�D
--�--�^0�X�%6�%6�0�*==�9�==�~,�9�,�&2�<�2�62�<�2�62�:�2�62� >�2�62�:�2�82�!?�2�62�;�2�6)�)�W�8�,�,�W�r:<��)�)�:<�z.�x� � �.��z���H�M�M�O���}��
�C������D��s"�F�F%�F"�!F"�%F0�/F0