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: //proc/self/root/opt/alt/python312/lib64/python3.12/test/__pycache__/test_io.cpython-312.pyc
�

~h�e����0
�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZmZddlmZmZddlmZddlmZmZmZddlmZddlmZdd	lmZdd
lm Z ddlm!Z!ddl"m#Z#ddl$Z$ddl%Z%ddl&Z'	ddl(Z(d
�Z)Gd�de(jT�Z+ejZxse	j\j^Z0d�Z1e
jde3ed�d�Z4Gd�d�Z5Gd�d�Z6Gd�de6e%jn�Z8Gd�de6e'jn�Z9Gd�de6�Z:Gd�de:e%jn�Z;Gd �d!e:e'jn�Z<Gd"�d#e:�Z=Gd$�d%e=e%jn�Z>Gd&�d'e=e'jn�Z?Gd(�d)e:�Z@Gd*�d+e@e%jn�ZAGd,�d-e@e'jn�ZBGd.�d/e:�ZCGd0�d1eCe%jn�ZDGd2�d3eCe'jn�ZEGd4�d5�ZFGd6�d7eFe%j��ZHGd8�d9eFe'j��ZIGd:�d;�ZJGd<�d=eJe%j��ZKGd>�d?eJe'j��ZLGd@�dA�ZMGdB�dCeMe%jn�ZNGdD�dEeMe'jn�ZOGdF�dGe
j��ZQGdH�dIeQ�ZRej�GdJ�dKe
j���ZTGdL�dMeQ�ZUej�GdN�dOe
j���ZVGdP�dQ�ZWGdR�dS�ZXGdT�dUe
j�eW�ZYGdV�dWeYeX�ZZGdX�dYeY�Z[GdZ�d[e
j�eW�Z\Gd\�d]e\eX�Z]Gd^�d_e\�Z^Gd`�dae
j��Z_Gdb�dce_�Z`Gdd�dee_�ZaGdf�dgeYe\�ZbGdh�diebeX�ZcGdj�dkeb�ZdGdl�dme$j��Zfdn�ZgGdo�dpe
j��ZhGdq�dre
j��ZiGds�dte%j��Zjdu�ZkGdv�dwei�ZlGdx�dyei�ZmGdz�d{e
j��ZnGd|�d}en�ZoGd~�den�ZpGd��d�e
j��ZqGd��d�eq�ZrGd��d�eq�Zse
j�ej�d�k(d��Gd��d�e
j���ZvGd��d�ev�ZwGd��d�ev�Zxd��Zyezd�k(re
j��yy#e,$rd�Z)Y��hwxYw)�zUnit tests for the io module.�N)�deque�UserList)�cycle�count)�support)�assert_python_ok�assert_python_failure�run_python_until_end)�
import_helper)�	os_helper)�threading_helper)�warnings_helper)�skip_if_sanitizer)�FakePathc��t|i|��}t�}tj|t	|��|t|�j
d�dd|S)z?Create a bytes-like object having no string or sequence methods�BN)�bytes�EmptyStruct�ctypes�resize�len�
memoryview�cast)�pos�kw�data�objs    �3/opt/alt/python312/lib64/python3.12/test/test_io.py�	bytesliker;sH���c� �R� ���m���
�
�c�3�t�9�%�'+�
�3����S�!�!�$��
�c��eZdZy)rN��__name__�
__module__�__qualname__�r rrrBs��r rc�@�tjdt|i|���S)N�b)�arrayr)rrs  rrr8s���{�{�3��s� 1�b� 1�2�2r c�j�ttdd��5}|jcddd�S#1swYyxYw)z(Get the default TextIOWrapper chunk size�r�latin-1��encodingN)�open�__file__�_CHUNK_SIZE)�fs r�_default_chunk_sizer3Js,��	
�h��i�	0��A��}�}����s�)�2�alarmztest requires signal.alarm()c��eZdZd�Zy)�BadIndexc��ddzy�N�rr&��selfs r�	__index__zBadIndex.__index__U�	��	�!�r N)r#r$r%r<r&r rr6r6Ts��r r6c�P�eZdZdZd
d�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zdd�Z
y)�MockRawIOWithoutReadzmA RawIO implementation without read(), so as to exercise the default
    RawIO.read() which calls readinto().c�N�t|�|_g|_d|_d|_y�Nr)�list�_read_stack�_write_stack�_reads�_extraneous_reads)r;�
read_stacks  r�__init__zMockRawIOWithoutRead.__init__\s&���
�+���������!"��r c�`�|jjt|��t|�S�N)rD�appendrr�r;r(s  r�writezMockRawIOWithoutRead.writebs#����� � ��q��*��1�v�
r c��y�NTr&r:s r�writablezMockRawIOWithoutRead.writablef���r c��y�N�*r&r:s r�filenozMockRawIOWithoutRead.filenois��r c��yrOr&r:s r�readablezMockRawIOWithoutRead.readablelrQr c��yrOr&r:s r�seekablezMockRawIOWithoutRead.seekableorQr c��yrAr&�r;r�whences   r�seekzMockRawIOWithoutRead.seekr���r c��yrAr&r:s r�tellzMockRawIOWithoutRead.tellur^r c�\�|xjdz
c_t|�}	|jd}|�|jd=yt|�}t|�|kr|jd=||d||S|d||dd||d|jd<|S#t$r|xjdz
c_YywxYwr8)rErrC�
IndexErrorrF)r;�buf�max_lenr�ns     r�readintozMockRawIOWithoutRead.readintoxs������q����c�(��	��#�#�A�&�D��<�� � ��#����I���t�9���� � ��#��C���G��H��(�7�^�C��F�"&�w�x�.�D���Q���N���	��"�"�a�'�"��	�s�B
�
B+�*B+Nc��|SrJr&)r;rs  r�truncatezMockRawIOWithoutRead.truncate�s���
r )r&rJ)r#r$r%�__doc__rHrMrPrUrWrYr]r`rfrhr&r rr?r?Xs9��,�#���������*r r?c��eZdZy)�CMockRawIOWithoutReadNr"r&r rrkrk����r rkc��eZdZy)�PyMockRawIOWithoutReadNr"r&r rrnrn�rlr rnc��eZdZdd�Zy)�	MockRawIONc��|xjdz
c_	|jjd�S#|xjdz
c_YyxYw)Nr9rr )rErC�poprF�r;res  r�readzMockRawIO.read�sG�����q���	��#�#�'�'��*�*��	��"�"�a�'�"��s	�2�ArJ�r#r$r%rtr&r rrprp�s��r rpc��eZdZy)�
CMockRawIONr"r&r rrwrw�rlr rwc��eZdZy)�PyMockRawIONr"r&r rryry�rlr ryc�@��eZdZ�fd�Zd�fd�	Zd�Zd�Z�fd�Z�xZS)�MisbehavedRawIOc�(��t�|�|�dzS�N�)�superrM)r;r(�	__class__s  �rrMzMisbehavedRawIO.write�s����w�}�Q��!�#�#r c�(��t�|�|�dzSr})rrt)r;rer�s  �rrtzMisbehavedRawIO.read�s����w�|�A���"�"r c��y)Ni����r&r[s   rr]zMisbehavedRawIO.seek�rQr c��y)Ni8���r&r:s rr`zMisbehavedRawIO.tell�rQr c�>��t�|�|�t|�dzS)N�)rrfr)r;rcr�s  �rrfzMisbehavedRawIO.readinto�s���
������3�x�!�|�r rJ)	r#r$r%rMrtr]r`rf�
__classcell__�r�s@rr{r{�s!���$�#����r r{c��eZdZy)�CMisbehavedRawIONr"r&r rr�r��rlr r�c��eZdZy)�PyMisbehavedRawIONr"r&r rr�r��rlr r�c�$��eZdZ�fd�Zd�Z�xZS)�SlowFlushRawIOc�T��t�|��tj�|_yrJ)rrH�	threading�Event�in_flush)r;r�s �rrHzSlowFlushRawIO.__init__�s���
����!���)��
r c�b�|jj�tjd�y)Ng�?)r��set�time�sleepr:s r�flushzSlowFlushRawIO.flush�s���
�
�����
�
�4�r )r#r$r%rHr�r�r�s@rr�r��s
���*�r r�c��eZdZy)�CSlowFlushRawIONr"r&r rr�r��rlr r�c��eZdZy)�PySlowFlushRawIONr"r&r rr�r��rlr r�c��eZdZdZd�Zy)�CloseFailureIOrc�6�|js
d|_t�y�Nr9��closed�OSErrorr:s r�closezCloseFailureIO.close�s���{�{��D�K��M�r N)r#r$r%r�r�r&r rr�r��s��
�F�r r�c��eZdZy)�CCloseFailureIONr"r&r rr�r��rlr r�c��eZdZy)�PyCloseFailureIONr"r&r rr�r��rlr r�c�4��eZdZ�fd�Zd�fd�	Z�fd�Z�xZS)�
MockFileIOc�2��g|_t�|�	|�yrJ)�read_historyrrH)r;rr�s  �rrHzMockFileIO.__init__�s������
����r c���t�|�|�}|jj|�d�|St	|��|SrJ)rrtr�rKr)r;re�resr�s   �rrtzMockFileIO.read�s>����g�l�1�o����� � ����C��
�;>�c�(�C��
r c�\��t�|�|�}|jj|�|SrJ)rrfr�rK)r;r(r�r�s   �rrfzMockFileIO.readinto�s+����g��q�!����� � ��%��
r rJ)r#r$r%rHrtrfr�r�s@rr�r��s�����
�r r�c��eZdZy)�CMockFileIONr"r&r rr�r��rlr r�c��eZdZy)�PyMockFileIONr"r&r rr�r��rlr r�c�$�eZdZd�Zd�Zd�Zd�Zy)�MockUnseekableIOc��y�NFr&r:s rrYzMockUnseekableIO.seekable�s��r c�$�|jd���Nznot seekable��UnsupportedOperation�r;�argss  rr]zMockUnseekableIO.seek�����'�'��7�7r c�$�|jd��r�r�r�s  rr`zMockUnseekableIO.tell�r�r c�$�|jd��r�r�r�s  rrhzMockUnseekableIO.truncater�r N)r#r$r%rYr]r`rhr&r rr�r��s���8�8�8r r�c�$�eZdZejZy)�CMockUnseekableION)r#r$r%�ior�r&r rr�r�s���2�2�r r�c�$�eZdZejZy)�PyMockUnseekableION)r#r$r%�pyior�r&r rr�r�s���4�4�r r�c�>�eZdZd�Zd�Zd�Zd�Zd�Zd
d�Zd�Z	d�Z
y	)�MockNonBlockWriterIOc� �g|_d|_yrJ)rD�
_blocker_charr:s rrHzMockNonBlockWriterIO.__init__s�����!��r c�Z�dj|j�}g|jdd|S�Nr )�joinrD)r;�ss  r�pop_writtenz MockNonBlockWriterIO.pop_writtens+���H�H�T�&�&�'��!����!���r c��||_y)z'Block when a given char is encountered.N)r�)r;�chars  r�block_onzMockNonBlockWriterIO.block_ons
��!��r c��yrOr&r:s rrWzMockNonBlockWriterIO.readablerQr c��yrOr&r:s rrYzMockNonBlockWriterIO.seekablerQr c��yrAr&r[s   rr]zMockNonBlockWriterIO.seeks��r c��yrOr&r:s rrPzMockNonBlockWriterIO.writable#rQr c�0�t|�}d}|jrI	|j|j�}|dkDr |jj	|d|�|Sd|_y|jj	|�t
|�S#t
$rY�1wxYw)N���r)rr��indexrDrK�
ValueErrorr)r;r(res   rrMzMockNonBlockWriterIO.write&s����!�H�������
 ��G�G�D�.�.�/���q�5��%�%�,�,�Q�r��U�3��H�*.�D�&����� � ��#��1�v�
���
��
�s�B	�		B�BN�r)r#r$r%rHr�r�rWrYr]rPrMr&r rr�r�
s*��"��
"�����r r�c�$�eZdZejZy)�CMockNonBlockWriterION)r#r$r%r��BlockingIOErrorr&r rr�r�:s
���(�(�Or r�c�$�eZdZejZy)�PyMockNonBlockWriterION)r#r$r%r�r�r&r rr�r�=s
���*�*�Or r�c��eZdZd�Zd�Zd�Zd6d�ZdZd�Zd�Z	e
jejd�e
jeed	�d
�d���Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%d �Z&d!�Z'd"�Z(d#�Z)d$�Z*d%�Z+d&�Z,d'�Z-d(�Z.d)�Z/d*�Z0d+�Z1d,�Z2d-�Z3d.�Z4d/�Z5d0�Z6d1�Z7d2�Z8d3�Z9d4�Z:y5)7�IOTestc�J�tjtj�yrJ�r�unlink�TESTFNr:s r�setUpzIOTest.setUpC�������)�)�*r c�J�tjtj�yrJr�r:s r�tearDownzIOTest.tearDownFr�r c��|j|jd�d�|jd�|j|j�d�|j	d�|j|jd�d�|j|j	d�d�|j|jd�d�|j|j�d�|j|j	dd�d�|j|j�d�td�}|j|j|�d	�d
|dd|j|j	d�d�|j|jd�d�|j|j	dd�d
�|j|j�d
�|j|jd�d�|j|j�d
�|j
t|jd�y)Nsblah.r�rsHello.�r�r9s	 world


�	s	*********�hr~�
��)�assertEqualrMrhr`r]�	bytearray�assertRaises�	TypeError)r;r2�buffers   r�	write_opszIOTest.write_opsIs����������*�A�.�	�
�
�1�
��������1�%�	���q�	��������*�A�.���������A�&��������+�Q�/��������1�%��������A���*��������1�%��?�+����������!�,���q�	���������A�&����������*��������A���+��������2�&�������B���,��������2�&����)�Q�V�V�S�1r c��|jd�}|j|d�t|�}|j|j|�d�|jt	|�d�td�}|j|j|�d�|jt
|�d�|j|ddd�|j|jd�d�|j|jd�d�|j|jd	�d
�|j|jtd��d�|j|jdd�d
�|j|jd�d�|j|jd�d
�|j|jt��d�|j|jdd	�d�|j|jd�d�|j|j�d�|jt|jd�|r�|jd�|j|j�d�|jd
�|j|j�d�|j|j�d
�|jd�td�}|j|j|�d�|jt	|�d�yy)Nr�shellos worlr~�d
r��hello world
r9r �xi����r�sworld�
r�sworld
)rtr�rrfrr�rr]r`r�r��	readinto1)r;r2�bufferedrs    r�read_opszIOTest.read_opsasl���v�v�a�y������x�(�����������D�)�1�-�����t��h�/���|��������D�)�1�-�����T��A�&�����b�q��6�*���������A�&���������%5�6���������C�(�������I�d�O�4�a�8��������A���*���������H�-���������C�(�������I�K�0�!�4��������A���*���������H�-��������2�&����)�Q�V�V�S�1��
�F�F�1�I����Q�V�V�X�'7�8�
�F�F�1�I����Q�V�V�X�z�2����Q�V�V�X�s�+�
�F�F�1�I��Q�<�D����Q�[�[��.��2����U�4�[�(�3�r lc�.�|j�sJ�|j�sJ�	|j|j|j�|j�|j|j�|j�|j|jd�d�|j|j�|jdz�|j|jdd�|jdz�|j|j�|jdz�|j|j�|jdz�|j|jdd�|jdz�|j|j|jdz�|jdz�|j|j�|jdz�|j|jdd�|jdz�|j|jdd�|j�|j|jd�d�y#t
tf$r|jd�Y��8wxYw)	Nzno largefile support�xxx�r�r9r~rr�)rWrPr�r]�LARGE�
OverflowErrorr��skipTestr`rMrhrt�r;r2s  r�large_file_opszIOTest.large_file_ops�s����z�z�|���z�z�|��	2����Q�V�V�D�J�J�/����<�	
�������4�:�:�.���������!�,��������4�:�:��>�2��������A���
�
�Q��7��������t�z�z�A�~�6��������4�:�:��>�2��������1��t�z�z�A�~�6�������D�J�J��N�3�T�Z�Z�!�^�D��������4�:�:��>�2��������1��t�z�z�A�~�6��������A���
�
�3���������D�)���z�*�	2��M�M�0�1�	2�s�5I0�0 J�Jc��|j}|jtjdd��5}|j	||j
�|j	||j�ddd�|jtjd�5}|j	||j
�|j	||j�ddd�|jtjdd��5}|j	||j
�|j	||j�ddd�|jtjdd��5}|j	||jd�|j	||jd	g�ddd�|jtjd�5}|j	||jd�|j	||jd	g�ddd�|jtjd
d��5}|j	||jd�|j	||jdg�|j	||jd
|j�|j	||jd|j�ddd�y#1swY��OxYw#1swY���xYw#1swY���xYw#1swY��LxYw#1swY��xYw#1swYyxYw)N�w�utf-8r-�wbr��	buffering�rbsblahsblah
r+�blahzblah
r9r�)r�r/rr�r�rt�readlinerM�
writelinesr]�SEEK_CUR�SEEK_END)r;�exc�fps   r�test_invalid_operationszIOTest.test_invalid_operations�sh���'�'��
�Y�Y�y�'�'��w�Y�
?�	0�2����c�2�7�7�+����c�2�;�;�/�	0��Y�Y�y�'�'��
.�	0�"����c�2�7�7�+����c�2�;�;�/�	0��Y�Y�y�'�'���Y�
;�	0�r����c�2�7�7�+����c�2�;�;�/�	0��Y�Y�y�'�'���Y�
;�	?�r����c�2�8�8�W�5����c�2�=�=�9�+�>�	?��Y�Y�y�'�'��
.�	?�"����c�2�8�8�W�5����c�2�=�=�9�+�>�	?��Y�Y�y�'�'��w�Y�
?�	?�2����c�2�8�8�V�4����c�2�=�=�8�*�=����c�2�7�7�A�t�}�}�=����c�2�7�7�B��
�
�>�	?�	?�	0�	0��	0�	0��	0�	0��	?�	?��	?�	?��	?�	?�sH�9J5�9K�39K�<K�:<K)� BK5�5J?�K�K�K&�)K2�5K>�%fstat() of a pipe fd is not supported�pipe�requires os.pipe()c�x���fd�}�fd�}�fd�}�fd�}�fd�}�fd�}�fd�}�fd�}|d	f|d
f|df|df|d
f|df|df|df�jd
f�jd
ff
}	|	D�]�\}
}�j|
�5|
�5}d|v}
�j|j	�|
�d|v}�j|j�|�t
|�j�rd}n6t
|�j�jf�rd}n�jd�d|vr|j�n �jt|j�|
r"|jd�|j�nA�jt|jd��jt|j�|r|j�n!�jt|j�t j"j%d�r|
||fvr	ddd�ddd����d|v}�j|j'�|�|r"|j)�|j+d�nA�jt|j(��jt|j*d�|r$|r"|j-�|j-d�nA�jt|j,��jt|j,d�ddd�ddd����y#1swY�xYw#1swY���xYw)Nc���tj�\}}tj|��j|d�S)Nr+)�osrr��FileIO)r+rr;s  �r�pipe_readerz3IOTest.test_optional_abilities.<locals>.pipe_reader�s.����W�W�Y�F�Q���H�H�Q�K��;�;�q�#�&�&r c�:��tj�\}}�jtj|�t	j
tj|df��}|j��j|j��j|d�S)N�d��targetr�r)
rr�
addCleanupr�r��Threadrt�startr�r)r+r�threadr;s   �r�pipe_writerz3IOTest.test_optional_abilities.<locals>.pipe_writer�sh����W�W�Y�F�Q���O�O�B�H�H�a�(��%�%�R�W�W�A�s�8�D�F��L�L�N��O�O�F�K�K�(��;�;�q�#�&�&r c�B���j�j��SrJ)�BufferedReaderr�r:s�r�buffered_readerz7IOTest.test_optional_abilities.<locals>.buffered_reader������&�&�t�'<�'<�'>�?�?r c�B���j�j��SrJ)�BufferedWriterr�r:s�r�buffered_writerz7IOTest.test_optional_abilities.<locals>.buffered_writer�r*r c�B���j�j��SrJ)�BufferedRandom�BytesIOr:s�r�buffered_randomz7IOTest.test_optional_abilities.<locals>.buffered_random�s����&�&�t�|�|�~�6�6r c�`���j�j��j��SrJ)�BufferedRWPairr�r:s�r�buffered_rw_pairz8IOTest.test_optional_abilities.<locals>.buffered_rw_pair�s-����&�&�t�'<�'<�'>��%�%�'�)�
)r c�`��G�fd�d�j�}�j|�d�S)Nc�j��eZdZW�jjZW�jj
Zy)�MIOTest.test_optional_abilities.<locals>.text_reader.<locals>.UnseekableReaderN)r#r$r%�BufferedIOBaserPrMr:s�r�UnseekableReaderr7�s%����.�.�7�7���+�+�1�1�r r9�ascii�r��
TextIOWrapper)r9r;s �r�text_readerz3IOTest.test_optional_abilities.<locals>.text_reader�s.���
2�4�#8�#8�
2��%�%�&6�&8�'�B�Br c�`��G�fd�d�j�}�j|�d�S)Nc�j��eZdZW�jjZW�jj
Zy)�MIOTest.test_optional_abilities.<locals>.text_writer.<locals>.UnseekableWriterN)r#r$r%r8rWrtr:s�r�UnseekableWriterr@�s%����.�.�7�7���*�*�/�/�r rAr:r;)rAr;s �r�text_writerz3IOTest.test_optional_abilities.<locals>.text_writer�s.���
0�4�#8�#8�
0��%�%�&6�&8�'�B�Br �fr�fwr+r�rws�rw�3�3zUnknown base classr2r9�winr�r)r0�StringIO�subTestr�rWrP�
isinstance�
TextIOBaser8�	RawIOBase�failrUr�r�rtrM�sys�platform�
startswithrYr`r]rh)r;rr&r)r-r1r4r=rB�tests�test�	abilitiesrrWrPrrYs`                r�test_optional_abilitieszIOTest.test_optional_abilities�s����	'�
	'�	@�	@�	7�	)�	C�	C��$��+�t�!4�
�c�"�_�c�$:�
�e�$�'7��&>�
�#���c� 2�
�\�\�5�!�D�M�M�5�#9�
��"'�2	@��T�9����d�#�1
@�T�V�1
@�s��)�+��� � ������:��)�+��� � ������:��c�4�?�?�3��D���d�&9�&9�4�>�>�%J�K��D��I�I�2�3��)�#��J�J�L��%�%�g�s�z�z�:���H�H�Q�K��H�H�J��%�%�g�s�x�x��;��%�%�g�s�x�x�8���I�I�d�O��%�%�g�s�y�y�$�?��<�<�*�*�5�1�d�#�[�?2�72��C1
@�1
@�1
@�D�)�+��� � ������:���H�H�J��H�H�Q�K��%�%�g�s�x�x�8��%�%�g�s�x�x��;����L�L�N��L�L��O��%�%�g�s�|�|�<��%�%�g�s�|�|�Q�?�c1
@�1
@�1
@�2	@�1
@�1
@��1
@�1
@�s2�8L/�F
L#�
L/�C0L#�L/�#L,�(L/�/L9	c�6�d}|jt|j|dd��t|d�}t	j
�5t	jdt�|jt|j|dd��ddd�y#1swYyxYw)Nzfoobarrr	r-r:�ignore)r�r�r/r�warnings�catch_warnings�simplefilter�DeprecationWarning)r;�fn_with_NUL�bytes_fns   r�test_open_handles_NUL_charsz"IOTest.test_open_handles_NUL_charss��� �����*�d�i�i��c�G��T���g�.��
�
$�
$�
&�	V��!�!�(�,>�?����j�$�)�)�X�s�W��U�	V�	V�	V�s�?B�Bc��|jtjdd��5}|j|j	�d�|j|j�d�|j|j
�d�|j|�ddd�|jtjdd��5}|j|j	�d�|j|j�d�|j|j
�d�|j|�ddd�y#1swY��xYw#1swYyxYw)Nr
rrFTr
�	r/rr�r�rWrPrYr�r�rs  r�test_raw_file_iozIOTest.test_raw_file_io&s��
�Y�Y�y�'�'���Y�
;�	�q����Q�Z�Z�\�5�1����Q�Z�Z�\�4�0����Q�Z�Z�\�4�0��N�N�1��		�
�Y�Y�y�'�'���Y�
;�	�q����Q�Z�Z�\�4�0����Q�Z�Z�\�5�1����Q�Z�Z�\�4�0��M�M�!��		�	�	�	��
	�	�s�A2D:�?A2E�:E�Ec��|jtjd�5}|j|j	�d�|j|j�d�|j|j
�d�|j|�ddd�|jtjd�5}|j|j	�d�|j|j�d�|j|j
�d�|j|d�ddd�y#1swY��xYw#1swYyxYw)Nr
FTr
rars  r�test_buffered_file_iozIOTest.test_buffered_file_io2s���
�Y�Y�y�'�'��
.�	�!����Q�Z�Z�\�5�1����Q�Z�Z�\�4�0����Q�Z�Z�\�4�0��N�N�1��		�
�Y�Y�y�'�'��
.�	#�!����Q�Z�Z�\�4�0����Q�Z�Z�\�5�1����Q�Z�Z�\�4�0��M�M�!�T�"�		#�	#�	�	��
	#�	#�s�A2D7�;A3E�7E�Ec�v�|jtjd�5}|jd�ddd�|jtjd�5}|j	|j�d�|j	|jd�d�|j	|jd�d�|j	|jd	�d
�|j	|j�d�|j	|jd�d�|j
t|j
d
�ddd�|jtjdd��5}|j
t|j
d
�ddd�y#1swY��exYw#1swY�cxYw#1swYyxYw)Nr
s"abc
def
xyzzy
foobar
another liner
�abc
r��def
r~�xy�szzy
sfoobar
sanother lineg333333@r+r	r-)r/rr�rMr�rr�r�rs  r�
test_readlinezIOTest.test_readline>sX��
�Y�Y�y�'�'��
.�	B�!�
�G�G�@�A�	B�
�Y�Y�y�'�'��
.�	:�!����Q�Z�Z�\�8�4����Q�Z�Z��^�X�6����Q�Z�Z��]�E�2����Q�Z�Z��]�H�5����Q�Z�Z�\�?�;����Q�Z�Z��-��?����i����S�9�	:��Y�Y�y�'�'��w�Y�
?�	:�1����i����S�9�	:�	:�	B�	B��	:�	:��	:�	:�s$�F�C&F#�+"F/�F �#F,�/F8c�z�Gd�d|j�}|jttft|��y)Nc��eZdZd�Zy)�+IOTest.test_readline_nonsizeable.<locals>.Rc��yrJr&r:s rrz4IOTest.test_readline_nonsizeable.<locals>.R.readlineP���r N)r#r$r%rr&r r�RrmO���
r rp)�IOBaser�r��
StopIteration�next�r;rps  r�test_readline_nonsizeablez IOTest.test_readline_nonsizeableLs-��	����	�	
���9�m�4�d�A�C�@r c�z�Gd�d|j�}|jt|�jd�y)Nc��eZdZd�Zy)�'IOTest.test_next_nonsizeable.<locals>.Rc��yrJr&r:s r�__next__z0IOTest.test_next_nonsizeable.<locals>.R.__next__Xror N)r#r$r%r{r&r rrpryWrqr rpr9)rrr�r��	readlinesrus  r�test_next_nonsizeablezIOTest.test_next_nonsizeableTs,��	����	�	
���)�Q�S�]�]�A�6r c���|j�}|j|�|j�}|j|d�|j|�}|j	|d�y)Nr�T)r0r��getvaluer�r�)r;r2rs   r�test_raw_bytes_iozIOTest.test_raw_bytes_io\sQ���L�L�N�����q���z�z�|������/�0��L�L�����
�
�a��r c��tjdddk(stjdk(r#tjdd|jz�|jtjdd�5}|j|�ddd�|jtjd�5}|j|�ddd�y#1swY�DxYw#1swYyxYw)NrrI�darwin�	largefilez-test requires %s bytes and a long time to run�w+br)	rPrQr�requiresrr/rr�rrs  r�test_large_file_opszIOTest.test_large_file_opsds����<�<����u�$�����(@�����?�$�*�*�L�
N��Y�Y�y�'�'���
2�	#�a�����"�	#�
�Y�Y�y�'�'��
/�	#�1�����"�	#�	#�	#�	#��	#�	#�s�.C�(C�C�Cc���dD]�}d}|jtjd|�5}|jd�ddd�|j	|j
d�d}	|jtjd|�5}ddzddd�|j
d���y#1swY�kxYw#1swY�)xYw#t$r|j	|j
d�Y��wxYw)N)rrr
rTr9rz1/0 didn't raise an exception)r/rr�rMr�r�rO�ZeroDivisionError)r;�bufsizer2s   r�test_with_openzIOTest.test_with_openqs����	;�G��A����9�+�+�T�7�;�
 �q������
 ����Q�X�X�t�,��A�
;��Y�Y�y�/�/��w�?��1��a�C��
�	�	�9�:�	;�
 �
 ��
���$�
1�� � ����4�0�
1�s5�B%�"!B=�B1�	B=�%B.	�1B:	�6B=�=%C%�$C%c��|jtjd�5}|jd�ddd�|jtjdd��5}|j	|j�d�ddd�|jtjd�5}|j	|j�d�ddd�|jtjdd�	�5}|j
|j�d�ddd�y#1swY��xYw#1swY��xYw#1swY�mxYw#1swYyxYw)
Nr
r�abrrr�ar	r-)r/rr�rMr�r`�
assertGreaterrs  r�test_append_mode_tellzIOTest.test_append_mode_tell�s��
�Y�Y�y�'�'��
.�	�!�
�G�G�F�O�	�
�Y�Y�y�'�'���Y�
;�	*�q����Q�V�V�X�q�)�	*�
�Y�Y�y�'�'��
.�	*�!����Q�V�V�X�q�)�	*�
�Y�Y�y�'�'��w�Y�
?�	,�1����q�v�v�x��+�	,�	,�
	�	��	*�	*��	*�	*��	,�	,�s/�D�!D'�&!D3�1!D?�D$�'D0�3D<�?Ec����g�G�fd�d|j�}tjdtf�5|tj
d�}|j
d�~tj�|j�gd��|jtj
d�5}|j|j�d�ddd�ddd�y#1swY�xYw#1swYyxYw)Nc�:���eZdZ��fd�Z��fd�Z��fd�Z�xZS)�(IOTest.test_destructor.<locals>.MyFileIOc�j���jd�	t�|�}|�y#t$rYywxYwr��rKr�__del__�AttributeError�r;r2r��records  ��rr�z0IOTest.test_destructor.<locals>.MyFileIO.__del__��8����
�
�a� �����A��C��&������
&�	2�2c�D���jd�t�|�	�yr}�rKrr��r;r�r�s ��rr�z.IOTest.test_destructor.<locals>.MyFileIO.close������
�
�a� ���
�r c�D���jd�t�|�	�y�Nr�rKrr�r�s ��rr�z.IOTest.test_destructor.<locals>.MyFileIO.flush�r�r �r#r$r%r�r�r�r��r�r�s@�r�MyFileIOr������
�
 �
 �
 r r��r
r�r9r~rr
)rr�check_warnings�ResourceWarningrr�rMr�
gc_collectr�r/rt)r;r�r2r�s   @r�test_destructorzIOTest.test_destructor�s������	 �t�{�{�	 ��
+�
+�R��,A�
B�	3���)�)�4�0�A�
�G�G�F�O����� ����V�Y�/����9�+�+�T�2�
3�a�� � �����6�2�
3�
	3�	3�
3�
3��
	3�	3�s$�A2C&�(!C�	C&�C#	�C&�&C/c���g�G�fd�d|�}|�}~tj�|j�gd��y)Nc�@���eZdZd�Z��fd�Z��fd�Z��fd�Z�xZS)�+IOTest._check_base_destructor.<locals>.MyIOc�.�d|_d|_d|_y)Nr9r~r)�on_del�on_close�on_flushr:s rrHz4IOTest._check_base_destructor.<locals>.MyIO.__init__�s��
 ��� !��
� !��
r c�~���j|j�	t�|�}|�y#t$rYywxYwrJ)rKr�rr�r�r�s  ��rr�z3IOTest._check_base_destructor.<locals>.MyIO.__del__�s<����
�
�d�k�k�*�����A��C��&����s�
0�	<�<c�X���j|j�t�|�
�yrJ)rKr�rr�r�s ��rr�z1IOTest._check_base_destructor.<locals>.MyIO.close������
�
�d�m�m�,���
�r c�X���j|j�t�|�
�yrJ)rKr�rr�r�s ��rr�z1IOTest._check_base_destructor.<locals>.MyIO.flush�r�r )r#r$r%rHr�r�r�r�r�s@�r�MyIOr��s���
"�
�
 �
 �
 r r�r�)rr�r�)r;�baser�r2r�s    @r�_check_base_destructorzIOTest._check_base_destructor�s<�����	 �4�	 �.
�F��
����������+r c�:�|j|j�yrJ)r�rrr:s r�test_IOBase_destructorzIOTest.test_IOBase_destructor�s���#�#�D�K�K�0r c�:�|j|j�yrJ)r�rNr:s r�test_RawIOBase_destructorz IOTest.test_RawIOBase_destructor�s���#�#�D�N�N�3r c�:�|j|j�yrJ)r�r8r:s r�test_BufferedIOBase_destructorz%IOTest.test_BufferedIOBase_destructor�s���#�#�D�$7�$7�8r c�:�|j|j�yrJ)r�rMr:s r�test_TextIOBase_destructorz!IOTest.test_TextIOBase_destructor�s���#�#�D�O�O�4r c�:�|jtjd�5}|jd�ddd�|jtjd�5}|j	|j�d�ddd�y#1swY�SxYw#1swYyxYw)Nr
rr
�r/rr�rMr�rtrs  r�test_close_flusheszIOTest.test_close_flushes�s~��
�Y�Y�y�'�'��
.�	�!�
�G�G�F�O�	�
�Y�Y�y�'�'��
.�	/�!����Q�V�V�X�v�.�	/�	/�	�	��	/�	/���B�!B�B�Bc�����tjdtd���t�j������fd�}|�j	��|�jtjd��|�j�j���|�j�j���|�j�j��j���y)N�ir�c���|5�j|j����|j�f�ddd�y#1swYyxYwrJ)r�rMr)r2r�rer;s ���r�checkz'IOTest.test_array_writes.<locals>.check�sA����
#�� � ������Q�/����a�T�"�
#�
#�
#�s�4A�A
r)r)�ranger�tobytesr0rrr�r,rpr/r3)r;r�r�res` @@r�test_array_writeszIOTest.test_array_writes�s�����K�K��U�2�Y�'����	�	����	#�	�d�l�l�n��
�d�k�k�)�*�*�C�0�1�
�d�!�!�$�.�.�"2�3�4�
�d�!�!�$�.�.�"2�3�4�
�d�!�!�$�.�.�"2�D�N�N�4D�E�Fr c�j�|jt|jtjddd��y)Nrr	F�r.�closefd�r�r�r/rr�r:s r�test_closefdzIOTest.test_closefd�s,�����*�d�i�i��1A�1A�3�#*�E�	�	;r c�t�|jtjdd��5}|jd�ddd�|jtjdd��5}|j|j	�ddd��}|j|j
�d�|jd�|j�|jt|j�ddd�|jtjd	�5}|j|j	�d	d�
�}|j|j
�ddd�|j�|jt|jtd
��ddd�y#1swY��bxYw#1swY��xYw#1swYyxYw)Nrr	r-�egg
r+Fr�rr
�r�rseggr9)
r/rr�rMrUr�rtr]r�r�r�rfr��r;r2�files   r�test_read_closedzIOTest.test_read_closed�sV��
�Y�Y�y�'�'��w�Y�
?�	�1�
�G�G�G��	�
�Y�Y�y�'�'��w�Y�
?�	5�1��9�9�Q�X�X�Z��w��9�N�D����T�Y�Y�[�'�2��I�I�a�L��J�J�L����j�$�)�)�4�	5��Y�Y�y�'�'��
.�	G�!��9�9�Q�X�X�Z��u�9�=�D����T�Y�Y�[��!�_�f�5��J�J�L����j�$�-�-��1��F�		G�	G�	�	��	5�	5��	G�	G�s%�F�BF"�BF.�F�"F+�.F7c�j�|jt|jtjddd��y)Nr+r	Fr�r�r:s r�test_no_closefd_with_filenamez$IOTest.test_no_closefd_with_filename�s,�����*�d�i�i��1A�1A�3�#*�E�	�	;r c��|jtjd�5}|jd�ddd�|jtjdd��5}|j	|j
jjd�|j|j�ddd��}|j	|j
jjd�ddd�y#1swY��xYw#1swYyxYw)	Nr
segg
r+r	r-TFr�)	r/rr�rMr�r��rawr�rUr�s   r�test_closefd_attrzIOTest.test_closefd_attr�s���
�Y�Y�y�'�'��
.�	�!�
�G�G�H��	�
�Y�Y�y�'�'��w�Y�
?�	=�1����Q�X�X�\�\�1�1�4�8��9�9�Q�X�X�Z��w��9�N�D����T�[�[�_�_�4�4�e�<�	=�	=�	�	��	=�	=�s�C*�BC6�*C3�6C?c��tjdtf�5|jtj
d�}|j
d�||_tj|�}~tj�ddd�|j�|�|jtj
d�5}|j|j�d�ddd�y#1swY�jxYw#1swYyxYw)Nr�r
sabcxxxr
)rr�r�rrr�rMr2�weakref�refrr��assertIsNoner/r�rt)r;r2�wrs   r�test_garbage_collectionzIOTest.test_garbage_collections����
+�
+�R��,A�
B�	!����I�,�,�d�3�A�
�G�G�I���A�C����Q��B����� �
	!�	
���"�$��#�
�Y�Y�y�'�'��
.�	2�!����Q�V�V�X�y�1�	2�	2�	!�	!��	2�	2�s�A#C(�>!C4�(C1�4C=c���d}tjj|�s |jdj	|��t
jdkDr|jd�tjtjkr|jd�|j|dd��5}|jt|j�ddd�|j|d�5}|jt|j�ddd�|j|d	�5}|jt|j�ddd�y#1swY��xYw#1swY�QxYw#1swYyxYw)
Nz	/dev/zeroz{0} does not exist��z+test can only run in a 32-bit address spacez&test requires at least 2 GiB of memoryr
rrr+)r�path�existsr�formatrP�maxsizer�real_max_memuse�_2Gr/r�rrt)r;�zeror2s   r�test_unbounded_filezIOTest.test_unbounded_files�����w�w�~�~�d�#��M�M�.�5�5�d�;�<��;�;��#��M�M�G�H��"�"�W�[�[�0��M�M�B�C�
�Y�Y�t�T�Q�Y�
/�	5�1����m�Q�V�V�4�	5�
�Y�Y�t�T�
"�	5�a����m�Q�V�V�4�	5�
�Y�Y�t�S�
!�	5�Q����m�Q�V�V�4�	5�	5�		5�	5��	5�	5��	5�	5�s$�,!E�'!E�"!E$�E�E!�$E-c����|j|i|���g���fd�}|�_|jt�j�|j�j�|j��|j�d�d��_y)Nc�8���jg�ddt��rJr�)r�r2s��r�	bad_flushz4IOTest.check_flush_error_on_close.<locals>.bad_flush%s������
�F�1�I��)�Or rc��yrJr&r&r r�<lambda>z3IOTest.check_flush_error_on_close.<locals>.<lambda>-��r )r/r�r�r�r��
assertTruer��assertFalse)r;r��kwargsr�r�r2s    @@r�check_flush_error_on_closez!IOTest.check_flush_error_on_close sv���
�D�I�I�t�&�v�&����	�������'�1�7�7�+�������!������������#���r c�^�|jtjdd��tjtjtj
tjz�}|j|dd��tjtjtj
tjz�}|j|ddd��tj|�|jtjd�tjtjtj
tjz�}|j|d�tjtjtj
tjz�}|j|dd��tj|�|jtjdd�	�tjtjtj
tjz�}|j|dd�	�tjtjtj
tjz�}|j|ddd�
�tj|�y)Nr
rrF)rr�r�rr	r-r�)r�rr�rr/�O_WRONLY�O_CREATr�)r;�fds  r�test_flush_error_on_closez IOTest.test_flush_error_on_close/s���	
�'�'�	�(8�(8�$�!�'�L�
�W�W�Y�%�%�r�{�{�2�:�:�'=�
>���'�'��D�A�'�>�
�W�W�Y�%�%�r�{�{�2�:�:�'=�
>���'�'��D�A�u�'�M�
������'�'�	�(8�(8�$�?�
�W�W�Y�%�%�r�{�{�2�:�:�'=�
>���'�'��D�1�
�W�W�Y�%�%�r�{�{�2�:�:�'=�
>���'�'��D�%�'�@�
������'�'�	�(8�(8�#��'�P�
�W�W�Y�%�%�r�{�{�2�:�:�'=�
>���'�'��C�'�'�B�
�W�W�Y�%�%�r�{�{�2�:�:�'=�
>���'�'��C�'�5�'�Q�
����r c���|jtjdd��}|j�|j�|j�|j	t
|j�y)Nr
rr)r/rr�r�r�r�r�rs  r�test_multi_closezIOTest.test_multi_closeGsK���I�I�i�&�&���I�:��	���	�	���	�	���	����*�a�g�g�.r c�6�|jd�}|j|jd�d�|j|jd�d�|j|jd�d�|j|jd�d�|j|jd�d�|j|jd�d�|j|jd�d�|j|jd�d�y)	N)�abc�dN�efgNr~�ab�cr�ef�gr )r?r�rt�r;�rawios  r�test_RawIOBase_readzIOTest.test_RawIOBase_readNs����)�)�*L�M��������A���.�������A���-�������A���-�������A���-�������A���.�������A���-�������A���-�������A���,r c���|j�|j�|j�|j�|j	�f}|D]}|jt
|d���y)N�__dict__)rrrNrMrJr0r��hasattr)r;rTrs   r�test_types_have_dictzIOTest.test_types_have_dict[s\���K�K�M��N�N���O�O���M�M�O��L�L�N�
���	6�C��O�O�G�C��4�5�	6r c���|jtjdd��5}|jd�ddd�t	jtjtj
���fd�}|jddd|��5}|j
|j�d�ddd�y#1swY�xYw#1swYyxYw)	Nrr	r-r�c����SrJr&)r��flagsr�s  �r�openerz"IOTest.test_opener.<locals>.openerjs����Ir �non-existentr+)r.r)r/rr�rMr�O_RDONLYr�rt)r;r2rr�s   @r�test_openerzIOTest.test_openerfs����
�Y�Y�y�'�'��w�Y�
?�	�1�
�G�G�G��	�
�W�W�Y�%�%�r�{�{�
3��	�
�Y�Y�~�s�W�V�Y�
L�	0�PQ����Q�V�V�X�w�/�	0�	0�	�	��
	0�	0�s�B4�
!C�4B=�C	c���d�}|jt�5}tdd|��ddd�|jt	j
�d�y#1swY�/xYw)Nc��y�Nr�r&��fnamers  r�	badopenerz4IOTest.test_bad_opener_negative_1.<locals>.badopenerq���r rr+�rzopener returned -1�r�r�r/r��str�	exception�r;r�cms   r�test_bad_opener_negative_1z!IOTest.test_bad_opener_negative_1o�R��	�
�
�
�z�
*�	8�b����Y�7�	8�����R�\�\�*�,@�A�	8�	8���A�Ac���d�}|jt�5}tdd|��ddd�|jt	j
�d�y#1swY�/xYw)Nc��y)N���r&rs  rrz8IOTest.test_bad_opener_other_negative.<locals>.badopeneryrr rr+rzopener returned -2rrs   r�test_bad_opener_other_negativez%IOTest.test_bad_opener_other_negativewr"r#c���tj��|jt�5}|j	d�fd���ddd�|jjjtj�y#1swY�>xYw)N�fooc����SrJr&)�namerr�s  �rr�z/IOTest.test_opener_invalid_fd.<locals>.<lambda>�s����r r)	r�make_bad_fdr�r�r/r�r�errno�EBADF)r;r r�s  @r�test_opener_invalid_fdzIOTest.test_opener_invalid_fdsg����
"�
"�
$��
�
�
�w�
'�	<�2��I�I�e�$:�I�;�	<�������+�+�U�[�[�9�	<�	<�s�A?�?Bc��|jtd�5}|jtd�5}|j|j�d��}|j	|j�d��|j�|j
�|j�ddd�ddd�y#1swY�xYw#1swYyxYw)Nr
Fr�)r/r0rrUrHrr�)r;�f1�f2�fileios    r�test_fileio_closefdzIOTest.test_fileio_closefd�s���
�Y�Y�x��
&�	�"�
�Y�Y�x��
&�	�*,��[�[�����e�[�<�F��O�O�B�I�I�K��O�7��K�K�M��L�L�N��K�K�M�	�	�	�	��	�	�s#�B>�A3B2�!B>�2B;	�7B>�>Cc���tj|�5|jt�5|j	t
jddd��ddd�ddd�y#1swY�xYw#1swYyxYw)Nrr	r�r.r�r�check_no_resource_warningr�r�r/rr�r:s r�test_nonbuffered_textiozIOTest.test_nonbuffered_textio�sp��
�
6�
6�t�
<�	P��"�"�:�.�
P��	�	�)�*�*�C�'�Q�	�O�
P�	P�	P�
P�
P��	P�	P��"�A-�$A!�A-�!A*	�&A-�-A6c���tj|�5|jt�5|j	t
jddd��ddd�ddd�y#1swY�xYw#1swYyxYw)Nrr	�invalid�r.�newliner7r:s r�test_invalid_newlinezIOTest.test_invalid_newline�sp��
�
6�
6�t�
<�	V��"�"�:�.�
V��	�	�)�*�*�C�'�9�	�U�
V�	V�	V�
V�
V��	V�	V�r:c	�&�Gd�d|j�}|�}dD]d}|j|�5td�}|jt	||�|�d�|jt|�d�ddd��fy#1swY�qxYw)Nc��eZdZd�ZeZy)�3IOTest.test_buffered_readinto_mixin.<locals>.Streamc��y)N�12345r&�r;�sizes  rrtz8IOTest.test_buffered_readinto_mixin.<locals>.Stream.read�s��r N)r#r$r%rt�read1r&r r�StreamrB�s��
 ��Er rH�rfr�r�rD)r8rKrr��getattrr)r;rH�stream�methodr�s     r�test_buffered_readinto_mixinz#IOTest.test_buffered_readinto_mixin�s���	�T�(�(�	����/�	:�F����f�%�
:�"�1���� � �!8����!8��!@�!�D�� � ��v���9�
:�
:�	:�
:�
:�s�A	B�B	c����fd�}|ttj��|ttjtj����jtjdd��5}t|j
��}�jt�5�j|dd��ddd�ddd�td�}�jt�5�j|dd��ddd�tt�}�jt�5�j|dd��ddd��jtd�5�jttj�dd��ddd�y#1swY��xYw#1swY��xYw#1swY��xYw#1swY�xxYw#1swYyxYw)Nc����j|dd��5}|jd�ddd��j|dd��5}�j|j�d�ddd�y#1swY�GxYw#1swYyxYw)Nrr	r-r�r+)r/rMr�rt)r�r2r;s  �r�check_path_succeedsz7IOTest.test_fspath_support.<locals>.check_path_succeeds�s~������4��w��7�
!�1����� �
!����4��w��7�
4�1�� � �����7�3�
4�
4�
!�
!��
4�
4�s�A.�!A:�.A7�:Brr	r-zread/write/append mode�rwxa)rrr�r�fsencoder/rUr�r��FloatingPointError�assertRaisesRegexr�)r;rPr2�bad_paths`   r�test_fspath_supportzIOTest.test_fspath_support�s���	4�	�H�Y�%5�%5�6�7��H�R�[�[��1A�1A�%B�C�D�
�Y�Y�y�'�'��w�Y�
?�	;�1�����
�+�H��"�"�9�-�
;��	�	�(�C�'�	�:�
;�	;�
�D�>��
�
�
�y�
)�	7��I�I�h��g�I�6�	7��.�/��
�
�
�1�
2�	7��I�I�h��g�I�6�	7��
#�
#�J�0H�
I�	L��I�I�h�y�/�/�0�&�7�I�K�	L�	L�
;�
;��	;�	;��	7�	7��	7�	7��	L�	L�sH�:/F#�)F�>F#�.F/�/F;�",G�F 	�F#�#F,�/F8�;G�Gc���|jd�}|j|j�d�|jd�}|j|j�d�y�N�r�rr�abcdefg)r?r�rt�readallrs  r�test_RawIOBase_readallzIOTest.test_RawIOBase_readall�sR���)�)�*@�A���������z�2��)�)�*@�A���������*�5r c	�6�Gd�d|j�}d}d}|D]�}|j|�5|\}}}}|tt|���}	t	|f|z�}
t|	|�}|j
||
�|�|j
t|
�|�|j|
d|t|��|f||z
z}|j|
|d|�|j
t|	j�||z
�ddd���y#1swY��xYw)Nc��eZdZd�Zd�Zd�Zy)�3IOTest.test_BufferedIOBase_readinto.<locals>.Readerc��||_yrJ��avail)r;rbs  rrHz<IOTest.test_BufferedIOBase_readinto.<locals>.Reader.__init__�s	��"��
r c�L�|jd|}|j|d|_|SrJra)r;rF�results   rrtz8IOTest.test_BufferedIOBase_readinto.<locals>.Reader.read�s)�����E�T�*��!�Z�Z���.��
��
r c�8�|jt|d��S)z$Returns no more than 5 bytes at oncer�)rt�minrEs  rrGz9IOTest.test_BufferedIOBase_readinto.<locals>.Reader.read1�s���y�y��T�1��.�.r N)r#r$r%rHrtrGr&r r�Readerr_�s��
#�
�
/r rg)
)rfr�r�r�)rfr�r�r�)rfr�r�r�)rfr��r�)rfr�rr)r�r�r�r�)r�r�r�r�)r�r�r�r�)r�r�rhr�)r�r�rr�)
r8rKrr�r�rJr�r�assertSequenceEqualrb)r;rgrS�UNUSED_BYTErTrLrb�requestrd�readerr��unuseds            r�test_BufferedIOBase_readintoz#IOTest.test_BufferedIOBase_readinto�s"��		/�T�(�(�		/�

�����	D�D����d�#�

D�15�.���w����e�E�l� 3�4��"�K�>�G�#;�<�� ���0��� � �����8�� � ��V��g�6��(�(�����%��-�H�%��7�V�+;�<���(�(�����&�A�� � ��V�\�\�!2�E�F�N�C�

D�

D�	D�

D�

D�s�CD�D	c��Gd�d|j�}|�}|jt|j�d�|_y)Nc��eZdZd�Zd�Zy)�#IOTest.test_close_assert.<locals>.Rc��yrJr&)r;r+�values   r�__setattr__z/IOTest.test_close_assert.<locals>.R.__setattr__����r c��t��rJ�r�r:s rr�z)IOTest.test_close_assert.<locals>.R.flush�s	���i�r N)r#r$r%rur�r&r rrprr�s��
�
 r rpc��yrJr&r:s rr�z*IOTest.test_close_assert.<locals>.<lambda>r�r )rrr�r�r�r�)r;rpr2s   r�test_close_assertzIOTest.test_close_assert�s8��	 ����	 �

�C�����'�1�7�7�+�$��r N�F);r#r$r%r�r�r�r�rrr�unittest�skipIfr�
is_emscripten�
skipUnlessrrrVr_rbrdrjrvr}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr!r'r/r4r9r?rMrVr\rorzr&r rr�r�AsR��+�+�2�04�B
�E�*�(?�2�X�_�_����F���X�����V�,�.B�C�f@�D��f@�PV�
�
#�:�A�7��#�
;� ,�3�4,�<1�4�9�5�/�G�;�
G�;�
=�2�5� 
��0/�-�	6�0�B�B�:�
�P�
V�
:�L�86�'D�R$r r�c��eZdZd�Zy)�CIOTestc���Gd�d|j�}|�|�}||_tj|�}~~t	j
�|j
|�|�y)Nc��eZdZd�Zy)�*CIOTest.test_IOBase_finalize.<locals>.MyIOc��yrJr&r:s rr�z0CIOTest.test_IOBase_finalize.<locals>.MyIO.closervr N�r#r$r%r�r&r rr�r�s��
r r�)rrrr�r�rr�r�)r;r�rr�s    r�test_IOBase_finalizezCIOTest.test_IOBase_finalizesY��	�4�;�;�	�
	
���f�����
�[�[��
�����������"�$��#r N)r#r$r%r�r&r rr�r�s��$r r�c�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�TestIOCTypesc���tjd�}|j|j|j|j
|j|j|j|j|j|j|j|j|j|jg|_t"j$dk(r%|j j'|j(�||_y)N�_io�win32)r�
import_moduler3r/r(r,r0r�IncrementalNewlineDecoderrJr<�_BufferedIOBase�_BytesIOBuffer�_IOBase�
_RawIOBase�_TextIOBase�typesrPrQrK�_WindowsConsoleIOr��r;r�s  rr�zTestIOCTypes.setUps����)�)�%�0���������������K�K��J�J��)�)��L�L�����������K�K��N�N��O�O�
��
� �<�<�7�"��J�J���c�3�3�4���r c���|jD]C}|j|��5|jtd�5d|_ddd�ddd��Ey#1swY�xYw#1swY�\xYw)N)�tp�	immutable�bar)r�rKrTr�r))r;r�s  r�test_immutable_typesz!TestIOCTypes.test_immutable_types1si���*�*�	#�B������$�
#��+�+�I�{�C�#�"�B�F�#�
#�
#�	#�#�#��
#�
#�s"�A �A�A �A�A � A)	c�������fd�����fd���j}|j|j|j|j|j
|j|jh|j|jh|j|j|jhii}tjdk(r5||j|jj|j ��|�y)Nc���|D]9}�j||��5�jt||��ddd��;y#1swY�FxYw)N)r�r�)rKr��
issubclass)r�r�r�r;s   �r�
check_subsz5TestIOCTypes.test_class_hierarchy.<locals>.check_subs8sO����
:���\�\�R�d�\�3�:��O�O�J�r�4�$8�9�:�:�
:�:�:�s�A�A
	c���|j�D]I\}}t|t�r	�|��t|t�r
�||��9�j	d��Ky)Nzcorrupt test dataset)�itemsrL�dictr�rO)�d�k�vr��recursive_checkr;s   ���rr�z:TestIOCTypes.test_class_hierarchy.<locals>.recursive_check=sO������	�
6���1��a��&�#�A�&���3�'��q�!�$��I�I�4�5�

6r r�)r�r�r�r3r/r(r,r0r�rr�rJr<rPrQ�addr�)r;r��	hierarchyr�r�s`  @@r�test_class_hierarchyz!TestIOCTypes.test_class_hierarchy7s����	:�
	6��h�h���K�K��#�#��&�&��&�&��&�&��&�&��K�K�&�����J�J�!�����L�L��%�%�"��
�	�$�<�<�7�"��c�k�k�"�3�>�>�2�6�6�s�7L�7L�M��	�"r c��|j}|jD�cic]}|d��}}d||j<|j�D]q\}}|j	||��5|j
�d�}|f}|rt
||i�}n.d}	|jt|	�5t
||i�}ddd�ddd��sycc}w#1swY�xYw#1swY��xYw)NTF)r��is_basetype�	_subclassznot an acceptable base type)	r�r�r�r�rKr#�typerTr�)
r;r�r��datasetr�r�r+�bases�_�msgs
          r�test_subclassingzTestIOCTypes.test_subclassing^s����h�h��$(�J�J�/�q�1�d�7�/��/�&+���"�"�#�&�}�}��		2�O�B��������=�
2��+�+��i�0�������T�5�"�-�A�7�C��/�/�	�3�?�2� ��u�b�1��2�
2�
2�		2��0�2�2��
2�
2�s)�
B;�;C�C�(C�C	�C�C	c�\�|j}tj||j�yrJ)r�r�check_disallow_instantiationr�r�s  r�test_disallow_instantiationz(TestIOCTypes.test_disallow_instantiationns!���h�h���,�,�T�3�3E�3E�Fr N)r#r$r%r�r�r�r�r�r&r rr�r�s���,#�%#�N2� Gr r�c��eZdZy)�PyIOTestNr"r&r rr�r�rrlr r�c��eZdZd�Zd�Zy)�APIMismatchTestc��tjtjtjd��}|j|t
�d��y)z:Test that pyio RawIOBase class has all c RawIOBase methods)�__weakref__)rXz6Python RawIOBase does not have all C RawIOBase methods�r�N)r�detect_api_mismatchr�rNr�r�r��r;�mismatchs  r�test_RawIOBase_io_in_pyio_matchz/APIMismatchTest.test_RawIOBase_io_in_pyio_matchys:���.�.�t�~�~�r�|�|�6F�H������3�5�.f��gr c��tjtjtj�}|j|t
�d��y)z:Test that c RawIOBase class has all pyio RawIOBase methodsz6C RawIOBase does not have all Python RawIOBase methodsr�N)rr�r�rNr�r�r�r�s  r�test_RawIOBase_pyio_in_io_matchz/APIMismatchTest.test_RawIOBase_pyio_in_io_matchs4���.�.�r�|�|�T�^�^�L������3�5�.f��gr N)r#r$r%r�r�r&r rr�r�vs��h�hr r�c�`�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zy)�CommonBufferedTestsc���|j�}|j|�}|j|j�|�|j	t
|j�t
|�yrJ)rpr��assertIs�detachr�r��repr�r;r�rcs   r�test_detachzCommonBufferedTests.test_detach�sJ���n�n����g�g�c�l���
�
�c�j�j�l�C�(����*�c�j�j�1��S�	r c��|j�}|j|�}|jd|j��yrS)rpr�r�rU�r;r�bufios   r�test_filenozCommonBufferedTests.test_fileno�s1����� ������������U�\�\�^�,r c���|j�}|j|�}|jt|jdd�|jt|jdd�y)Nrr�r�)rpr�r�r�r]r�s   r�test_invalid_argsz%CommonBufferedTests.test_invalid_args�sK����� �����������*�e�j�j�!�R�8����*�e�j�j�!�Q�7r c���|j}g�G�fd�d|�}|j�}||�}~tj�|j	�gd��y)Nc�:���eZdZ��fd�Z��fd�Z��fd�Z�xZS)�BCommonBufferedTests.test_override_destructor.<locals>.MyBufferedIOc�j���jd�	t�|�}|�y#t$rYywxYwr�r�r�s  ��rr�zJCommonBufferedTests.test_override_destructor.<locals>.MyBufferedIO.__del__�r�r�c�D���jd�t�|�	�yr}r�r�s ��rr�zHCommonBufferedTests.test_override_destructor.<locals>.MyBufferedIO.close�r�r c�D���jd�t�|�	�yr�r�r�s ��rr�zHCommonBufferedTests.test_override_destructor.<locals>.MyBufferedIO.flush�r�r r�r�s@�r�MyBufferedIOr��r�r r�r�)r�rprr�r�)r;r�r�rr�r�s     @r�test_override_destructorz,CommonBufferedTests.test_override_destructor�sT���
�W�W����	 �2�	 ���� ���U�#������������+r c���|j�}|j|���fd�}|�|jt|�y)Nc�6���5	ddd�y#1swYyxYwrJr&�r�s�r�_withz7CommonBufferedTests.test_context_manager.<locals>._with�s����
��
�
�
�s��)rpr�r�r�)r;rr�r�s   @r�test_context_managerz(CommonBufferedTests.test_context_manager�s:������ ��������	�	��	
���*�e�,r c��|j�}tj�5}|jt�5|j|�jddd�ts|j|j�n6|j�*|j|jjt�ddd�y#1swY�jxYw#1swYyxYwrJ)
r�r�catch_unraisable_exceptionr�r�r��xyzzy�IOBASE_EMITS_UNRAISABLEr��
unraisabler��exc_typer��r;rr s   r�test_error_through_destructorz1CommonBufferedTests.test_error_through_destructor�s����#�#�%��
�
/�
/�
1�	B�R��"�"�>�2�
%������$�$�
%�+��!�!�"�-�-�0����*�� � ����!7�!7��A�	B�	B�
%�
%��	B�	B�s#�C�C�A C�C		�C�Cc�v�|j�}|j|�}d|jj�d|jj��}|j	t|�d|z�d|_|j	t|�d|z�d|_|j	t|�d|z�y)N�(z\.)?z<%s>�dummyz<%s name='dummy'>�dummyz<%s name=b'dummy'>)rpr�r$r%�assertRegexr�r+)r;r�r(�clsnames    r�	test_reprzCommonBufferedTests.test_repr�s����n�n����G�G�C�L��"&�'�'�"4�"4�d�g�g�6J�6J�K������a��&�7�"2�3��������a��"5��"?�@��������a��"6��"@�Ar c���|j�}|j|�}tj|d|�5	t	|�ddd�y#t
$rY�wxYw#1swYyxYw)Nr+)rpr�r�	swap_attrr��RuntimeError�r;r�r(s   r�test_recursive_reprz'CommonBufferedTests.test_recursive_repr�sg���n�n����G�G�C�L��
�
�
�s�F�A�
.�	�
��Q��	�	�� �
��
��	�	�s(�A�A�	A�A�A�A�A'c�����|j��g����fd�}|�_|j���|jt�j
�|j
�j�|j
�j�|j
��|j�d�|j�d�d��_y)Nc�N���j�jg�ddt��rJr�)r(r�r�s���rr�z@CommonBufferedTests.test_flush_error_on_close.<locals>.bad_flush�s ������3�:�:�.�F�1�I��)�Or rr9c��yrJr&r&r rr�z?CommonBufferedTests.test_flush_error_on_close.<locals>.<lambda>�r�r )	rpr�r�r�r�r�r�r�r�)r;r�r(r�r�s  @@@rr�z-CommonBufferedTests.test_flush_error_on_close�s�����n�n�����	���	��G�G�C�L�����'�1�7�7�+�������!�����
�
�#������������#�������#� ��	r c�8�|j�}d�}d�}||_|j|�}||_|j	t
�5}|j�ddd�|j
jjd�|j|jjt
�|j
|jjjd�|j|j�d�|_d�|_y#1swY��xYw)Nc��td���Nr�rxr&r rr�z@CommonBufferedTests.test_close_error_on_close.<locals>.bad_flush��
���'�"�"r c��td���Nr�rxr&r r�	bad_closez@CommonBufferedTests.test_close_error_on_close.<locals>.bad_close�r�r �r��r�c��yrJr&r&r rr�z?CommonBufferedTests.test_close_error_on_close.<locals>.<lambda>r�r c��yrJr&r&r rr�z?CommonBufferedTests.test_close_error_on_close.<locals>.<lambda>r�r )
rpr�r�r�r�r�r�rr��assertIsInstance�__context__r�r��r;r�r�r�r(�errs      r�test_close_error_on_closez-CommonBufferedTests.test_close_error_on_close�s����n�n���	#�	#���	��G�G�C�L�����
�
�
�w�
'�	�3�
�G�G�I�	�������+�+�Z�8����c�m�m�7�7��A�������2�2�7�7��D�������"�!��	����	�	�s�D�Dc�4�|j�}d�}d�}||_|j|�}||_|j	t
�5}|j�ddd�|j
dtj��|j|jjt
�|j
dt|jj��|j|j�d�|_d�|_y#1swY��xYw)Nc��t�rJ��non_existing_flushr&r rr�zNCommonBufferedTests.test_nonnormalized_close_error_on_close.<locals>.bad_flush���$�$r c��t�rJ��non_existing_closer&r rr�zNCommonBufferedTests.test_nonnormalized_close_error_on_close.<locals>.bad_close
r	r rrc��yrJr&r&r rr�zMCommonBufferedTests.test_nonnormalized_close_error_on_close.<locals>.<lambda>r�r c��yrJr&r&r rr�zMCommonBufferedTests.test_nonnormalized_close_error_on_close.<locals>.<lambda>r�r )
rpr�r�r�r��	NameError�assertInrrrrr�r�rs      r�'test_nonnormalized_close_error_on_closez;CommonBufferedTests.test_nonnormalized_close_error_on_closes����n�n���	%�	%���	��G�G�C�L�����
�
�
�y�
)�	�S�
�G�G�I�	��
�
�*�C��
�
�,>�?����c�m�m�7�7��C��
�
�*�C��
�
�0I�0I�,J�K�������"���� ��	�	�	�s�D�Dc���|j�}|j|�}|j�|j�|j�|jt|j
�yrJ)rpr�r�r�r�r�r�s   rr�z$CommonBufferedTests.test_multi_closesJ���n�n����G�G�C�L��	���	�	���	�	���	����*�a�g�g�.r c���|j|jd��}|j|j|j�|j|j|j
d�y)N�
AAAAAAAAAAr)r�r�r�r�r`r]�r;r�s  r�test_unseekablez#CommonBufferedTests.test_unseekable%sQ������-�-�i�8�9�����$�3�3�U�Z�Z�@����$�3�3�U�Z�Z��Cr c���|j�}|j|�}|j�}|jt�5||_ddd�y#1swYyxYwrJ)rpr�r�r�r�)r;r�rc�xs    r�test_readonly_attributesz,CommonBufferedTests.test_readonly_attributes*sQ���n�n����g�g�c�l���N�N���
�
�
�~�
.�	��C�G�	�	�	�s�A�A!N)r#r$r%r�r�r�r�r�r�r�r�r�rrr�rrr&r rr�r��sK���-�8�,�0
-�B�B��!�$�(!�*/�D�
r r�c�T�eZdZejd��Zejd��Zy)�
SizeofTestc��d}d}|j�}|j||��}tj|�|z
}|j�}|j||��}|j	tj|�||z�y)N�� ��buffer_size)rpr�rP�	getsizeofr�)r;�bufsize1�bufsize2rr�rFs      r�test_sizeofzSizeofTest.test_sizeof4sx��������� ������8��4���}�}�U�#�h�.����� ������8��4��������u�-�t�h��?r c���d}|j�}|j||��}tj|�|z
}|j	�|jtj|�|�y)Nrr)rpr�rPr!r�r�)r;r�rr�rFs     r�test_buffer_freeingzSizeofTest.test_buffer_freeing?sZ������� ������7��3���}�}�U�#�g�-��
���
�������u�-�t�4r N)r#r$r%r�cpython_onlyr$r&r&r rrr2s6�����@��@�
���5��5r rc���eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zej&�ej*d�d���Zd�Zd�Zd�Zd�Zd�Zy)�BufferedReaderTestr
c�P�|jdg�}|j|�}|j|�|j|d��|j|d��|jd|j	��|jt|j|d��|jt|j|d��|jt|j|d��|jdg�}|j|�|jd|j	��y)Nr��r�r��r�)rpr�rHr�rtr�r�r�s   r�test_constructorz#BufferedReaderTest.test_constructorKs�������x�(��������
���u��
���u�$��/�
���u�"��-���������.����*�e�n�n�e���K����*�e�n�n�e���M����*�e�n�n�e���L�����x�(��
���u����������.r c�j�|jj|j�}~|jj|j�}|jttfd|j
d�|j
|j��|j|jd�d�y�N�uninitialized|has no attributerr )	r��__new__rTr�r�rtrHrpr�rs  r�test_uninitializedz%BufferedReaderTest.test_uninitializedYs����������(�����������(�����
�N�;�?�$�z�z�1�	.�	���t�~�~�'�(�������A���,r c���dD]E}|jd�}|j|�}|jd|j|���G|j	t
jd�y)N)NrhrYrZr&)rpr�r�rtr�r�)r;�argrr�s    r�	test_readzBufferedReaderTest.test_readcs]���	:�C��N�N�#9�:�E��G�G�E�N�E����Z����C��9�	:�
	
���*�e�j�j�"�5r c�.�|jd�}|j|�}|jd|jd��|jd|j	d��|j|j
d�|jd|j	d��|jd|j	d��|j|j
d�|jd	|j	d��|j|j
d
�|jd|j	d��|j|j
d�|jd|j	d��|j|j
d
�y)NrY�ar9�br rrrrr~rrri�rpr�r�rtrGrEr�s   r�
test_read1zBufferedReaderTest.test_read1ks.�����5�6������������u�z�z�!�}�-�����u�{�{�1�~�.�������q�)�����e�k�k�!�n�-�����u�{�{�3�/�0�������q�)�����u�{�{�3�/�0�������q�)��������S�!1�2�������q�)�����e�k�k�#�.�/�������q�)r c��|jd�}|j|�}|jd|jd��|jd|j	��|jd|j	��|jd|j	d��|j|j
d�|jd	|j	��|j|j
d
�y)NrYr8r9sbcrrr�rr rir:r�s   r�test_read1_arbitraryz'BufferedReaderTest.test_read1_arbitrary{s������5�6������������u�z�z�!�}�-��������
�.�����u�{�{�}�-��������R��1�������q�)�����e�k�k�m�,�������q�)r c�l�|jd�}|j|�}td�}|j|j	|�d�|j|d�|j|j	|�d�|j|d�|j|j	|�d�|j|d�|j|j	|�d�|j|d�|j|j	|�d�|j|d�|jd	�}|j|�}|j|j	|�d�|j|d�|j|j	|�d�|j|d
�y)NrYr~r�cdrr9sgfr)r�Nscb)rpr�r�r�rf)r;rr�r(s    r�
test_readintoz BufferedReaderTest.test_readinto�sa�����5�6���������a�L���������*�A�.�����E�"��������*�A�.�����E�"��������*�A�.�����E�"��������*�A�.�����E�"��������*�A�.�����E�"����~�.���������������*�A�.�����E�"��������*�A�.�����E�"r c��d}|jd�}|j||��}td�}|j|j	d�d�|j|j
d�|j|j
|�d�|j|d�|j|j
d�|j|j
|�d�|j|ddd	�|j|j
d�|j|j
|�d�|j|d
�|j|j
d�td|z�}|j|j	d�d�|j|j
d�|j|j
|�d�|j|ddd
�|j|j
d�y)Nr�)r��de�fghsjklrr~rr�r9rrrBrCr�sfghjklri)rpr�r�r��peekrEr�)r;r rr�r(s     r�test_readinto1z!BufferedReaderTest.test_readinto1�s��������>�?������;��7���a�L��������A���/�������q�)��������+�Q�/�����E�"�������q�)��������+�Q�/�����2�A���%�������q�)��������+�Q�/�����E�"�������q�)��a��m�$��������A���/�������q�)��������+�Q�/�����2�A��	�*�������q�)r c	���d}d}|j|f�}|j||��}tjdd�}t|�dk7sJ�|j	|�}|j|t|��t
|�jd�}|j|t|��|j|d||d|�|j||ddt||d�z�y�	N�<saaaaaaaaaaaaaaaaaaaaaaaaaarr�s xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr,rr�)
rpr�r)rrfr�rr�
assertLessr��r;r rrr�r(re�bms        r�test_readinto_arrayz&BufferedReaderTest.test_readinto_array�s�����������w�'������;��7��
�K�K��Y�'���1�v��|��
�N�N�1������1�c�!�f�%���]�
�
��
$������3�r�7�#�����B�Q���b�q��*�����A�B����R���V��!5�6r c	���d}d}|j|f�}|j||��}tjdd�}t|�dk7sJ�|j	|�}|j|t|��t
|�jd�}|j|t|��|j|d||d|�|j||ddt||d�z�yrG)
rpr�r)rr�r�rrrIr�rJs        r�test_readinto1_arrayz'BufferedReaderTest.test_readinto1_array�s�����������w�'������;��7��
�K�K��Y�'���1�v��|��
�O�O�A������1�c�!�f�%���]�
�
��
$������3�r�7�#�����B�Q���b�q��*�����A�B����R���V��!5�6r c����fd�}�j|�j�gd���j|�jd�ddg��j|�jd�gd��y)Nc�H���jd�}�j|�S)N�rfr�r)rpr�)rr;s �rr�z0BufferedReaderTest.test_readlines.<locals>.bufio�s ����N�N�#<�=�E��7�7�5�>�!r rQr�rfr��r�r|rs` r�test_readlinesz!BufferedReaderTest.test_readlines�sf���	"�	
�����*�*�,�.G�H������*�*�1�-��&�/A�B������*�*�4�0�2K�Lr c	�P�d}t|�}dgd�|dggdgd�|ggdgd�gd�gg}|D]{\}}}|j|�}|j||�	�}d}	|D].}
|j|j	|
�||	|	|
z�|	|
z
}	�0|j|j
|��}y)
N�	abcdefghir)rr9ri�r)rrrri)r9r~rir~)ririr9r)rr�r�r�rtr�)r;r�dlenrSr��buf_read_sizes�raw_read_sizesrr�r�nbytess           r�test_bufferingz!BufferedReaderTest.test_buffering�s������4�y���>�T�1�;�0��:�T�8�0��>�;�0�
��8=�	A�3�G�^�^��O�O�D�)�E��G�G�E�w�G�7�E��C�(�
��� � ����F�!3�T�#�c�&�j�5I�J��v�
��
�
���U�/�/��@�	Ar c�l�|jd�}|j|�}|jd|jd��|jd|jd��|jd|j��|jd|j	d��|j|j��|jd|j��|jd�}|jd	|j
��|j|j
��y)
N)r�rNrNNN�abcdr��er9sfgr )r8NNr8)rpr�r�rtrDr�r[r�s   r�test_read_non_blockingz)BufferedReaderTest.test_read_non_blocking�s������M�N������������%�*�*�Q�-�0�����u�z�z�!�}�-������
�
��-�����e�j�j��m�,����%�*�*�,�'�����e�j�j�l�+����1�2������u�}�}��/����%�-�-�/�*r c��|jd�}|j|�}|jd|jd��y)NrYrZi(#�rpr�r�rtr�s   r�test_read_past_eofz%BufferedReaderTest.test_read_past_eofs7�����5�6������������U�Z�Z��%5�6r c��|jd�}|j|�}|jd|j��yrXrar�s   r�
test_read_allz BufferedReaderTest.test_read_all
s4�����5�6������������U�Z�Z�\�2r �cpuc�*�
���	d}ttd��|z}tj|�t	t|��}|j
tjd�5}|j|�ddd�|j
tj|jd��5}|j|d��
g�g��
��fd�}td�D�cgc]}tj|�	���}}tj|�5t!j"d
�ddd�|j%�d�z�dj'��}td�D]8}t	t|g��}	|j)|j+|	�|��:	ddd�tj,tj�y#1swY��LxYwcc}w#1swY��xYw#1swY�KxYw#tj,tj�wxYw)
N���r
rrrVc���	tddg�D](}�j|�}|sy�j|��*y#t$r}�j|��d}~wwxYw)Nr9�)rrtrK�	Exception)rer��er��errors�resultss   ���rr2z*BufferedReaderTest.test_threads.<locals>.f$s_���
�!&��2�w��.�A� %�
�
�1�
�A�#$� %�#�N�N�1�-�.��%���
�
�a�(����s�$<�<�	A�A�Ar��r!�{�G�z�?�(the following exceptions were caught: %rr )rBr��random�shufflerr�r/rr�rM�	read_moder�r�r#r
�
start_threadsr�r�r�r�r�rr�)
r;�N�lr�r2r�r�threadsr��cr�rmrns
          @@@r�test_threadszBufferedReaderTest.test_threadss����$	/��A��U�3�Z� �1�$�A��N�N�1���i��l�#�A����9�+�+�T�2�
�a�����
�
����9�+�+�T�^�^�q��I�
4�S�����Q��������@E�R�y�I�!�9�+�+�1�5�I��I�%�3�3�G�<�%��J�J�t�$�%�� � ��>��G�I��H�H�W�%���s��4�A��i���n�-�A��$�$�Q�W�W�Q�Z��3�4�-
4�4
���Y�-�-�.�9
�
��$J�%�%��#
4�
4��4
���Y�-�-�.�sg�A"G-�'G�94G-�-+G!�G�5G!�G�"A4G!�G-�G
�G-�G!�G	�G!�!G*�&G-�-%Hc��|j|jd��}|j|j|j�|j|j|j
d�|j
d�|j|j|j
d�|j|j|j�y)Nrrr9)r�r�r�r�r`r]rtrs  rrz"BufferedReaderTest.test_unseekable<s�������-�-�i�8�9�����$�3�3�U�Z�Z�@����$�3�3�U�Z�Z��C�
�
�
�1�
����$�3�3�U�Z�Z��C����$�3�3�U�Z�Z�@r c���|jd�}|j|�}|jt|jd�|jt|j
�d�|_y)NrYrc��yrJr&r&r rr�z7BufferedReaderTest.test_misbehaved_io.<locals>.<lambda>Kr�r )r{r�r�r�r]r`r�r�s   r�test_misbehaved_ioz%BufferedReaderTest.test_misbehaved_ioDsS���$�$�%;�<�����������'�5�:�:�q�1����'�5�:�:�.�#��r c	�F�d}d|dz
||dz|dzfD�]}|jd|zg�}|j||�}|j|j|�d|z�|j|jddj||j��|jd|dz
zdg�}|j||�}|j|j|�d|z�|j|jddj||j����y)Nr,r~r9r�rzfailed for {}: {} != 0)rpr�r�rtrFr�)r;r�rerr�s     r�test_no_extraneous_readz*BufferedReaderTest.test_no_extraneous_readMs�����W�q�[�'�7�Q�;��!��D�
	Z�A��N�N�D�1�H�:�.�E��G�G�E�7�+�E����U�Z�Z��]�D�1�H�5����U�4�4�a�5�<�<�Q��@W�@W�X�
Z��N�N�D�A��E�N�D�#9�:�E��G�G�E�7�+�E����U�Z�Z��]�D�1�H�5����U�4�4�a�5�<�<�Q��@W�@W�X�
Z�
	Zr c��|j|jd��}|jd�|j�|j	d�5|jt|j�ddd�|j	d�5|jt|jd�ddd�|j	d�5|jt|j�ddd�|j	d�5|jt|jt��ddd�|j	d�5|jt|jt��ddd�|j	d�5|jt|j�ddd�|j	d	�5|jt|j�ddd�|j	d
�5|jt|jd�ddd�y#1swY���xYw#1swY���xYw#1swY��ZxYw#1swY��$xYw#1swY��xYw#1swY��xYw#1swY��xYw#1swYyxYw)N�12r9rDrGrtrfr�r�rhr]r)r(r0rtr�rKr�r�rDrGrfr�r�r�rhr]rLs  r�test_read_on_closedz&BufferedReaderTest.test_read_on_closedas���������U� 3�4��	���q�	�	���	�
�\�\�&�
!�	2����j�!�&�&�1�	2�
�\�\�'�
"�	6����j�!�'�'�1�5�	6�
�\�\�&�
!�	2����j�!�&�&�1�	2�
�\�\�*�
%�	C����j�!�*�*�i�k�B�	C�
�\�\�+�
&�	D����j�!�+�+�y�{�C�	D�
�\�\�'�
"�	3����j�!�'�'�2�	3�
�\�\�*�
%�	6����j�!�*�*�5�	6�
�\�\�&�
!�	5����j�!�&�&�!�4�	5�	5�	2�	2��	6�	6��	2�	2��	C�	C��	D�	D��	3�	3��	6�	6��	5�	5�s`�!H'�
"H4�!I�*I�*I�!I'�!I3�<"I?�'H1�4H>�I�I�I$�'I0�3I<�?Jc� �|jd�}|j|�}|j|j��|j	|j
|j�|j	|j
|jd�y)Nr�r)r�r�r�rPr�r�rhr�s   r�test_truncate_on_read_onlyz-BufferedReaderTest.test_truncate_on_read_onlywsh������'��������������)�*����$�3�3�U�^�^�D����$�3�3�U�^�^�Q�Gr N)r#r$r%rtr.r3r6r;r=r@rErLrNrSr[r_rbrdr
�requires_working_threadingr�requires_resourcerzrr~r�r�r�r&r rr)r)Hs����I�/�-�6�*� 	*�#�**�.7�*7�*M�A�(
+�7�3�1��0�0�2��W���u�%�%/�&�3�%/�NA�#�Z�(5�,Hr r)c�j�eZdZejZeddd��d��Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
y)�CBufferedReaderTestT�Lsanitizer defaults to crashing instead of returning NULL for malloc failure.��memory�address�reasonc��tj|�tjdkDr]|j	�}|j|�}|j
tttf|j|tj�yy�Nr�)r)r.rPr�rpr�r�r�MemoryErrorr�rHr�s   rr.z$CBufferedReaderTest.test_constructor��d��	�+�+�D�1��;�;��#��N�N�$�E��G�G�E�N�E����}�k�:�F�����s�{�{�
4�$r c���|jdg�}|j|�}|jt|j|d��|jt|j
�|jt|j|d��|jt|j
�|jt|j|d��|jt|j
�y)Nr�rrr-r�)rpr�r�r�rHrtr�s   r�test_initializationz'CBufferedReaderTest.test_initialization�s�������x�(�����������*�e�n�n�e���K����*�e�j�j�1����*�e�n�n�e���M����*�e�j�j�1����*�e�n�n�e���L����*�e�j�j�1r c��|jd�}|j|�}|jt|jd�y)NrYr�)r{r�r�r�rtr�s   r�test_misbehaved_io_readz+CBufferedReaderTest.test_misbehaved_io_read�s8���$�$�%;�<��������	
���'�5�:�:�r�2r c��|jtjtj�t	j
dtf�5|jtjd�}|j|�}||_	tj|�}~tj�ddd�|j�|�y#1swY�!xYw)Nr�r�)r"rr�r�rr�r�rr�r2r�r�rr�r��r;rr2r�s    rr�z+CBufferedReaderTest.test_garbage_collection�s���	
���	�(�(�)�*:�*:�;�
�
+�
+�R��,A�
B�	!��K�K�	� 0� 0�%�8�E������A��A�C����Q��B����� �
	!�	
���"�$��#�	!�	!�s
�
A#C
�
Cc��|jtd�5|j|j�ddd�ddd�y#1swYyxYw)Nr(r+�rTr�r�r0r:s r�test_args_errorz#CBufferedReaderTest.test_args_error��@��
�
#�
#�I�/?�
@�	6��G�G�D�L�L�N�D�$��5�	6�	6�	6���#A�Ac�4�|j|jd��}d�|_|j|�}|jt�5}|j�ddd�|j
jj�y#1swY�/xYw)Nr�c��yrr&�rcs rr�z=CBufferedReaderTest.test_bad_readinto_value.<locals>.<lambda>�r�r )	r�r0rfr�r�rr�r�	__cause__�r;rr�r s    r�test_bad_readinto_valuez+CBufferedReaderTest.test_bad_readinto_value�st��������U�+�,��'���������
�
�
�w�
'�	�2��N�N��	����"�,�,�0�0�1�	�	�s�B�Bc�>�|j|jd��}d�|_|j|�}|jt�5}|j�ddd�|j
jjt�y#1swY�4xYw)Nr�c��yr�r&r�s rr�z<CBufferedReaderTest.test_bad_readinto_type.<locals>.<lambda>�r�r )
r�r0rfr�r�rrrr�r�r�s    r�test_bad_readinto_typez*CBufferedReaderTest.test_bad_readinto_type�sv��������U�+�,��(���������
�
�
�w�
'�	�2��N�N��	����b�l�l�4�4�i�@�	�	�s�B�BN)r#r$r%r�r(r�rr.r�r�r�r�r�r�r&r rr�r�sO��	�	�	�B��d�D�;G�H�4�H�4�2�3�$�6�
2�Ar r�c�$�eZdZejZy)�PyBufferedReaderTestN)r#r$r%r�r(r�r&r rr�r���
��	
�	�	�Br r�c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zej0�ej4d�d���Zd�Zd�Zd�Zej0�d��Zy)�BufferedWriterTestr
c���|j�}|j|�}|j|�|j|d��|j|d��|jd|j	d��|j�|j
t|j|d��|j
t|j|d��|j
t|j|d��|j|�|jd|j	d	��|j�|jd
j|j�d�y)Nr+rr,rr�rr-r��ghir sabcghi)
rpr�rHr�rMr�r�r�r�rDr�s   rr.z#BufferedWriterTest.test_constructor�s����� ��������
���u��
���u�$��/�
���u�"��-�����E�K�K��/�0�
���
����*�e�n�n�e���K����*�e�n�n�e���M����*�e�n�n�e���L�
���u������E�K�K��/�0�
���
�������%�"4�"4�5�y�Ar c�j�|jj|j�}~|jj|j�}|jttfd|j
d�|j
|j��|j|jd�d�y)Nr1r r)	r�r2rTr�r�rMrHrpr�rs  rr3z%BufferedWriterTest.test_uninitialized�s�����������(�����������(�����
�N�;�?�$�{�{�C�	1�	���t�~�~�'�(�������S�)�1�-r c��|j�}|j|�}|jd�|j|j�|j�|j
|jdg�y)Nshowdy!)rpr�rMr�rDr�r�r�s   r�test_detach_flushz$BufferedWriterTest.test_detach_flush�s\���n�n����g�g�c�l���	�	�)������)�)�*��
�
������)�)�I�;�7r c�X�|j�}|j|d�}|jd�|j|j�td�}|j|�d|dd|j
�|jdj|j�d�y)NrVr��def�***r �abcdef)	rpr�rMr�rDr�r�r�r�)r;�writerr�r�s    r�
test_writezBufferedWriterTest.test_write�s������!�������"��
���F������,�,�-��6�"��
���F����q�	�
���
�������&�"5�"5�6�	�Br c�.�|j�}|j|d�}d}tdt|�d�D]}|j	|||dz��dj|j�}|j|j|dd�|�y)NrVsabcdefghijklmnoprrr i����)	rpr�r�rrMr�rDr�rR)r;r�r��contentsre�flusheds      r�test_write_overflowz&BufferedWriterTest.test_write_overflow�s������!�������"��&���q�#�h�-��+�	)�A��K�K���1�Q�3��(�	)��(�(�6�.�.�/��	
����*�*�8�C�R�=�9�7�Cr c���ttd��dz}d}|j�}|j|d�}d�}|�}|t	|�krdtt
|�t	|�|z
�}|j|j||||z�|�||�||z
}|t	|�kr�d|j�|j|dj|j��y)Nrhrgrr�c3�TK�td�D]}td�D]}|����y�w)Nr9�)rr�)rFr�s  r�	gen_sizesz2BufferedWriterTest.check_writes.<locals>.gen_sizes	s1�����a��
���r���A��J��
�s�&(r )rr�rpr�rrfrtr�rMr�r�rD)	r;�intermediate_funcr�rer�r�r��sizesrFs	         r�check_writeszBufferedWriterTest.check_writess�����s��$�t�+��
�����!�������#��	�����#�h�-���t�E�{�C��M�A�$5�6�D����U�[�[��!�A�d�F�);�<�d�C��e�$�
��I�A�	�#�h�-��
	���
�����3�8�8�F�,?�,?�#@�Ar c�(�|jd��y)Nc��yrJr&r�s rr�z0BufferedWriterTest.test_writes.<locals>.<lambda>r�r �r�r:s r�test_writeszBufferedWriterTest.test_writess�����,�-r c�(�|jd��y)Nc�"�|j�SrJr�r�s rr�z<BufferedWriterTest.test_writes_and_flushes.<locals>.<lambda>s�����
�r r�r:s r�test_writes_and_flushesz*BufferedWriterTest.test_writes_and_flushess�����5�6r c�T�d�}|j|�d�}|j|�y)Nc��|j�}|j|dzd�|j|dz
d�|j|d�yr8)r`r]�r�rs  r�_seekabsz:BufferedWriterTest.test_writes_and_seeks.<locals>._seekabss?���*�*�,�C��J�J�s�Q�w��"��J�J�s�Q�w��"��J�J�s�A�r c��|jdd�}|jdd�|jdd�|j|d�y)Nrr9r�)r]r�s  r�_seekrelz:BufferedWriterTest.test_writes_and_seeks.<locals>._seekrel#s<���*�*�Q��"�C��J�J�r�1���J�J�r�1���J�J�s�A�r r�)r;r�r�s   r�test_writes_and_seeksz(BufferedWriterTest.test_writes_and_seekss,��	�
	
���(�#�	�
	
���(�#r c�(�|jd��y)Nc�@�|j|j��SrJ)rhr`r�s rr�z>BufferedWriterTest.test_writes_and_truncates.<locals>.<lambda>+s�����u�z�z�|�(D�r r�r:s r�test_writes_and_truncatesz,BufferedWriterTest.test_writes_and_truncates*s�����D�Er c���|j�}|j|d�}|j|jd�d�|j|jd�d�|j	d�|j|jd�d�|j	d�	|jd	�|jd
�|jd�|j|j�d�|j|jd
�d�|j�}|j|jd�|�y#|j$r}|j}Yd}~��d}~wwxYw)NrVr]risefghir��ksjklmn�0sopqrwxyz0123456789z'BlockingIOError should have been raisedr,sabcdefghijklmnopqrwxyzs	ABCDEFGHIr�s	01234567A)r�r�r�rMr�rOr��characters_writtenr�r�rR)r;r�r�rl�writtenr�s      r�test_write_non_blockingz*BufferedWriterTest.test_write_non_blocking-s1���'�'�)������Q���������W�-�q�1�������X�.��2����T��������X�.��2�	���T��	A��K�K�-�.�
�I�I�?�@�����"�%�������*�%�	'�	
������\�2�A�6��O�O���������\�2�A�6���#�#�	+��*�*�G��	+�s�)E�E5�E0�0E5c�6�|j�}|j|d�}|j|jd�d�|j|j	�d�|jdd�|j|jd�d�|jdd�|j|j
�d�|j|jd�d�|j�|j|j
�d	�y)
Nrir�r�rsXYr~sXYcdefs123456sXYcdef123456)r0r�r�rMr`r]rr��r;r�r�s   r�test_write_and_rewindz(BufferedWriterTest.test_write_and_rewindHs����l�l�n������Q���������Y�/��3��������q�)�
�
�
�1�a��������U�+�Q�/�
�
�
�1�a����������3�������Y�/��3�
���
���������9r c���|j�}|j|d�}|jd�|j�|j	d|j
d�y�NrVr�r)rpr�rMr�r�rD�r;r�r�s   r�
test_flushzBufferedWriterTest.test_flushUsN�����!�������"��
���F��
���
������!4�!4�Q�!7�8r c���gd�}|j�}|j|d�}|j|�|j�|j	dj|j�d�y�N)rr?rrVr r�)rpr�rr�r�r�rD�r;rwr�r�s    r�test_writelinesz"BufferedWriterTest.test_writelines\sY��!�����!�������"��
�����
���
�������&�"5�"5�6�	�Br c��tgd��}|j�}|j|d�}|j|�|j	�|jdj
|j�d�yr�)rrpr�rr�r�r�rDr�s    r�test_writelines_userlistz+BufferedWriterTest.test_writelines_userlistds_���*�+�����!�������"��
�����
���
�������&�"5�"5�6�	�Br c��|j�}|j|d�}|jt|jgd��|jt|jd�|jt|jd�y)NrVr��abc)rpr�r�r�rr�s   r�test_writelines_errorz(BufferedWriterTest.test_writelines_errorlsf�����!�������"�����)�U�%5�%5�y�A����)�U�%5�%5�t�<����)�U�%5�%5�u�=r c���|j�}|j|d�}|jd�~tj�|jd|jd�yr�)rpr�rMrr�r�rDr�s   rr�z"BufferedWriterTest.test_destructorssT�����!�������"��
���F������������!4�!4�Q�!7�8r c�X�|jtjtj�|j	tj|j
d��5}|j
|d�}|jd�|j|jd�d�|j|j�d�ddd�|j	tjdd��5}|j|j�d�ddd�y#1swY�UxYw#1swYyxYw)	NrrrVr�rr�r
r�)r"rr�r�r/�
write_moder�rMr�rhr`rt)r;r�r�r2s    r�
test_truncatez BufferedWriterTest.test_truncate{s������	�(�(�)�*:�*:�;�
�Y�Y�y�'�'����A�Y�
F�	.�#��G�G�C��O�E��K�K�	�"����U�^�^�A�.��2����U�Z�Z�\�1�-�		.�
�Y�Y�y�'�'���Y�
;�	/�q����Q�V�V�X�v�.�	/�	/�	.�	.��
	/�	/�s�A%D�*!D �D� D)c�,�|jtjtj�|j	tjd�5}|jddz�ddd�gd�}|D]�}|j	tjd|��5}|jd|dzz�|j
d�|j�|j|j�|dz�ddd���y#1swY��xYw#1swY��xYw)	Nr
�i')rr��zr+brr9r~)
r"rr�r�r/rMrtrhr�r`)r;r2�buffer_sizesr s    r�test_truncate_after_writez,BufferedWriterTest.test_truncate_after_write�s���	
���	�(�(�)�*:�*:�;�
�Y�Y�y�'�'��
.�	%�!�
�G�G�G�e�O�$�	%�)��'�	<�K����9�+�+�U�k��J�
<�a�����;��?�3�4����q�	��
�
��� � �����;��?�;�

<�
<�	<�		%�	%��

<�
<�s�C>�AD
�>D�
D	rec�t��
��	d}ttd��|z}tddg�}d}t��|t	|�kr6t|�}�j
||||z�||z
}|t	|�kr�6~|jtj|jd��5}|j|d��g�
��
�fd�}td	�D�cgc]}tj|�
���}	}tj|	�5t!j"d�ddd�|j%�
d�
z��j'�ddd�|jtjd
�5}|j)�}
ddd�td�D]-}|j+
j-t|g��|��/	tj.tj�ycc}w#1swY��xYw#1swY��xYw#1swY��xYw#tj.tj�wxYw)Nrgrhr9rjrrrVc���			�j�}�j|��##t$rYywxYw#t$r}�j	|��d}~wwxYwrJ)�popleftrbrMrkrK)r�rlr�rm�queues  ���rr2z*BufferedWriterTest.test_threads.<locals>.f�sa���	�"�'�$)�M�M�O��"�K�K��N�#��$.�'� &�'��%���
�
�a�(����s,�6�'�6�	3�6�3�6�	A�A�Ar�rorprqr
)rr�rrrrtrKr/rr�r�r�r�r#r
rur�r�r�r�rtr�rr�)r;rvr�r�rerFr�r2rrxr�r�r�rmr�s            @@@rrzzBufferedWriterTest.test_threads�s����+	/��A��U�3�Z�(�1�,�H��1�b�'�N�E��A��G�E��c�(�m�#��E�{�����X�a��$��/�0��T�	���c�(�m�#�����9�+�+�T�_�_���J�
�c�����Q�����
�@E�R�y�I�!�9�+�+�1�5�I��I�%�3�3�G�<�%��J�J�t�$�%�� � ��>��G�I����
�'
�(���9�+�+�T�2�
�a��F�F�H��
��3�Z�
9��� � ������s��!4�a�8�
9�
���Y�-�-�.��J�%�%��
�
��(
�
��

���Y�-�-�.�sm�A5H�;-H�()G:�G)�.G:�G.�-G:�(H�0H�AH�)G:�.G7	�3G:�:H�?H�H�H�%H7c��|j�}|j|d�}|jt|jd�|jt|j
�|jt|jd�d�|_y)Nr�rr�c��yrJr&r&r rr�z7BufferedWriterTest.test_misbehaved_io.<locals>.<lambda>�r�r )r{r�r�r�r]r`rMr�r�s   rr~z%BufferedWriterTest.test_misbehaved_io�si���$�$�&������q�!�����'�5�:�:�q�1����'�5�:�:�.����'�5�;�;�	�:�#��r c��|jt�5|j|j�dd�ddd�y#1swYyxYw�NrVr��r�r�r�rpr:s r�test_max_buffer_size_removalz/BufferedWriterTest.test_max_buffer_size_removal�s<��
�
�
�y�
)�	-��G�G�D�N�N�$�a��,�	-�	-�	-�s�"A�A
c���|j�}d�}||_|j|�}|jd�|jt|j
�|j
|j�y)Nc��t��rJrx)r(s r�	bad_writez?BufferedWriterTest.test_write_error_on_close.<locals>.bad_write�s	���)�Or �spam)rprMr�r�r�r�r�r�)r;r�r�r(s    r�test_write_error_on_closez,BufferedWriterTest.test_write_error_on_close�sW���n�n���	���	��G�G�C�L��	��������'�1�7�7�+�������!r c�t�|j�}|j|d�}tj|j��}|j�|jj�|jt|jd�|j|j�|j�y)NrVror�)r�r�r�r#r�r$r��waitr�r�rMr�r�r�)r;rr��ts    r�test_slow_close_from_threadz.BufferedWriterTest.test_slow_close_from_thread�s~���#�#�%������q�!�����E�K�K�0��	���	�
���������*�e�k�k�7�;�������%�	���r N) r#r$r%r�r.r3r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r
r�rr�rzr~r�rrr&r rr�r��s����J�B� .�8�
C�	D�B�(.�7�$�F�7�6:�9�C�C�>�9�	/�<�$1��0�0�2��W���u�%�,/�&�3�,/�\#�-�"�1��0�0�2�	�3�	r r�c�X�eZdZejZeddd��d��Zd�Zd�Z	d�Z
y)	�CBufferedWriterTestTr�r�c��tj|�tjdkDr]|j	�}|j|�}|j
tttf|j|tj�yyr�)r�r.rPr�rpr�r�rr�r�rHr�s   rr.z$CBufferedWriterTest.test_constructor�r�r c���|j�}|j|�}|jt|j|d��|jt|j
d�|jt|j|d��|jt|j
d�|jt|j|d��|jt|j
d�y)Nrrr�r-r�)rpr�r�r�rHrMr�s   rr�z'CBufferedWriterTest.test_initialization�s������ �����������*�e�n�n�e���K����*�e�k�k�6�:����*�e�n�n�e���M����*�e�k�k�6�:����*�e�n�n�e���L����*�e�k�k�6�:r c�~�|jtjtj�t	j
dtf�5|jtjd�}|j|�}|jd�||_
tj|�}~tj�ddd�|j�|�|j!tjd�5}|j#|j%�d�ddd�y#1swY�jxYw#1swYyxYw)Nr�r�s123xxxr
)r"rr�r�rr�r�rr�rMrr�r�rr�r�r/r�rtr�s    rr�z+CBufferedWriterTest.test_garbage_collections���	
���	�(�(�)�*:�*:�;�
�
+�
+�R��,A�
B�	!��K�K�	� 0� 0�%�8�E������A�
�G�G�I���A�C����Q��B����� �	!�	
���"�$��#�
�Y�Y�y�'�'��
.�	2�!����Q�V�V�X�y�1�	2�	2�	!�	!��	2�	2�s�
A4D'�=!D3�'D0�3D<c��|jtd�5|j|j�ddd�ddd�y#1swYyxYw)Nr,r+r�r:s rr�z#CBufferedWriterTest.test_args_errorr�r�N)r#r$r%r�r,r�rr.r�r�r�r&r rrr�s?��	�	�	�B��d�D�;G�H�4�H�4�;�2�"6r rc�$�eZdZejZy)�PyBufferedWriterTestN)r#r$r%r�r,r�r&r rrrr�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�Zy)�BufferedRWPairTestc��|j|j�|j��}|j|j�yrJ)r�rpr�r��r;�pairs  rr.z#BufferedRWPairTest.test_constructor#s2���w�w�t�~�~�'����)9�:��������%r c��|jj|j�}~|jj|j�}|jttfd|j
d�|jttfd|jd�|j|j�|j��|j|jd�d�|j|j
d�d�yr0)
r�r2rTr�r�rtrMrHrpr�rs  rr3z%BufferedRWPairTest.test_uninitialized's����w�w���t�w�w�'����w�w���t�w�w�'�����
�N�;�?�#�y�y�!�	-�	
���
�N�;�?�#�z�z�3�	0�	
�
�
�d�n�n�&����(8�9�������1��s�+�������C��!�,r c��|j|j�|j��}|j|j|j�yrJ)r�rpr�r�r�rs  rr�zBufferedRWPairTest.test_detach5s:���w�w�t�~�~�'����)9�:�����$�3�3�T�[�[�Ar c��|jt�5|j|j�|j�dd�ddd�y#1swYyxYwr�r�r:s r�(test_constructor_max_buffer_size_removalz;BufferedRWPairTest.test_constructor_max_buffer_size_removal9sE��
�
�
�y�
)�	?��G�G�D�N�N�$�d�n�n�&6��2�>�	?�	?�	?�s�1A�Ac��Gd�dt�}|jt|j|�|j��y)Nc��eZdZd�Zy)�JBufferedRWPairTest.test_constructor_with_not_readable.<locals>.NotReadablec��yr�r&r:s rrWzSBufferedRWPairTest.test_constructor_with_not_readable.<locals>.NotReadable.readable?���r N�r#r$r%rWr&r r�NotReadabler>���
r r�rpr�r�r�)r;rs  r�"test_constructor_with_not_readablez5BufferedRWPairTest.test_constructor_with_not_readable=s1��	�)�	�	
���'�4�7�7�K�M�4�>�>�;K�Lr c��Gd�dt�}|jt|j|j�|��y)Nc��eZdZd�Zy)�LBufferedRWPairTest.test_constructor_with_not_writeable.<locals>.NotWriteablec��yr�r&r:s rrPzUBufferedRWPairTest.test_constructor_with_not_writeable.<locals>.NotWriteable.writableFrr N)r#r$r%rPr&r r�NotWriteabler"Err r$r)r;r$s  r�#test_constructor_with_not_writeablez6BufferedRWPairTest.test_constructor_with_not_writeableDs1��	�9�	�	
���'�4�7�7�D�N�N�,<�l�n�Mr c���|j|jd�|j��}|j|j	d�d�|j|j	d�d�|j|j	�d�|j|jd�|j��}|j|j	d�d�y)Nr�rr�r9rr)r�r0rpr�rtrs  rr6zBufferedRWPairTest.test_readKs����w�w�t�|�|�I�.����0@�A��������1��v�.�������1��t�,��������e�,��w�w�t�|�|�F�+�T�^�^�-=�>��������4��&�1r c����fd�}�j|�j�gd���j|�j�gd���j|�jd�ddg�y)Nc�b���j�jd��j��S)Ns	abc
def
h)r�r0rpr:s�rr�z3BufferedRWPairTest.test_readlines.<locals>.<lambda>Us"���t�w�w�t�|�|�N�;�T�^�^�=M�N�r )rfrgr�r�rfrgrRrs` rrSz!BufferedRWPairTest.test_readlinesTsb���N�������)�)�+�-G�H������)�)�+�-G�H������)�)�!�,�x��.B�Cr c���|j|jd�|j��}|j|j	d�d�|j|j	�d�y)Nr�rr�r�)r�r0rpr�rGrs  rr;zBufferedRWPairTest.test_read1ZsR���w�w�t�|�|�I�.����0@�A��������A���/��������v�.r c	�L�dD]�}|j|�5|j|jd�|j��}t	d�}|jt
||�|�d�|jt|�d�ddd���y#1swY��xYw)NrIr�sr�sabcde)rKr�r0rprr�rJr)r;rLrrs    rr@z BufferedRWPairTest.test_readintobs���/�	8�F����f�%�
8��w�w�t�|�|�I�6����8H�I�� ��+��� � �!6���v�!6�t�!<�a�@�� � ��t��h�7�
8�
8�	8�
8�
8�s�A8B�B#	c�D�|j�}|j|j�|�}|jd�|j�t	d�}|j|�d|dd|j�|j|jddg�y)Nr�r�r�)rpr�rMr�r�r�rD)r;rrr�s    rr�zBufferedRWPairTest.test_writeks{���N�N����w�w�t�~�~�'��+���
�
�6���
�
���6�"���
�
�6����q�	��
�
��������&�&�)9�:r c��|j|jd�|j��}|j|j	d�jd��|j
|jd�d�y)Nr�rr�)r�r0rpr�rDrRr�rtrs  r�	test_peekzBufferedRWPairTest.test_peekwsY���w�w�t�|�|�I�.����0@�A������	�	�!��/�/��7�8�������1��v�.r c��|j|j�|j��}|j|j��yrJ)r�rpr�rWrs  r�
test_readablez BufferedRWPairTest.test_readable}�2���w�w�t�~�~�'����)9�:������
�
��(r c��|j|j�|j��}|j|j��yrJ)r�rpr�rPrs  r�test_writeablez!BufferedRWPairTest.test_writeable�r0r c��|j|j�|j��}|j|j��yrJ)r�rpr�rYrs  r�
test_seekablez BufferedRWPairTest.test_seekable�s6���w�w�t�~�~�'����)9�:���������)r c���|j|j�|j��}|j|j�|j	�|j|j�yrJ)r�rpr�r�r�r�rs  r�test_close_and_closedz(BufferedRWPairTest.test_close_and_closed�sK���w�w�t�~�~�'����)9�:��������%��
�
��������$r c���d�}|j�}||_|j�}|j||�}|jt�5}|j�ddd�|jdt
j��|j|j�|j|j�|j|j�d�|_y#1swY��xYw)Nc��tyrJ��reader_non_existingr&r r�reader_closezIBufferedRWPairTest.test_reader_close_error_on_close.<locals>.reader_close����r r:c��yrJr&r&r rr�zEBufferedRWPairTest.test_reader_close_error_on_close.<locals>.<lambda>�r�r )rpr�r�r�rrrrr�r�r�)r;r;rmr�rrs      r� test_reader_close_error_on_closez3BufferedRWPairTest.test_reader_close_error_on_close�s���	 ����!��#������!���w�w�v�v�&��
�
�
�y�
)�	�S��J�J�L�	��
�
�+�S����-?�@�������$�������'�����
�
�&�$���	�	�s�C*�*C3c���d�}|j�}|j�}||_|j||�}|jt�5}|j�ddd�|jdt
j��|j|j�|j|j�|j|j�d�|_d}tj�5tj�5d}tj�ddd�tj�ddd�y#1swY��xYw#1swY�2xYw#1swYyxYw)Nc��tyrJ��writer_non_existingr&r r�writer_closezIBufferedRWPairTest.test_writer_close_error_on_close.<locals>.writer_close�r<r rBc��yrJr&r&r rr�zEBufferedRWPairTest.test_writer_close_error_on_close.<locals>.<lambda>�r�r )rpr�r�r�rrrrr�r�r�rr�r�)r;rCrmr�rrs      r� test_writer_close_error_on_closez3BufferedRWPairTest.test_writer_close_error_on_close�s&��	 ����!�����!��#����w�w�v�v�&��
�
�
�y�
)�	�S��J�J�L�	��
�
�+�S����-?�@�������%�����
�
�&�������'�$������
/�
/�
1�	!��3�3�5�
%����"�"�$�
%�
��� �	!�	!�	�	��
%�
%��	!�	!�s0�E�?E(�E�+E(�E�E%	�!E(�(E1c���d�}d�}|j�}||_|j�}||_|j||�}|jt�5}|j�ddd�|jdt
j��|j|jjt�|jdt
|jj��|j|j�|j|j�|j|j�d�|_d�|_y#1swY��xYw)Nc��tyrJr9r&r rr;zPBufferedRWPairTest.test_reader_writer_close_error_on_close.<locals>.reader_close�r<r c��tyrJrAr&r rrCzPBufferedRWPairTest.test_reader_writer_close_error_on_close.<locals>.writer_close�r<r r:rBc��yrJr&r&r rr�zLBufferedRWPairTest.test_reader_writer_close_error_on_close.<locals>.<lambda>�r�r c��yrJr&r&r rr�zLBufferedRWPairTest.test_reader_writer_close_error_on_close.<locals>.<lambda>�r�r )rpr�r�r�rrrrrrr�r�)r;r;rCrmr�rrs       r�'test_reader_writer_close_error_on_closez:BufferedRWPairTest.test_reader_writer_close_error_on_close�s��	 �	 ����!��#������!��#����w�w�v�v�&��
�
�
�y�
)�	�S��J�J�L�	��
�
�+�S����-?�@����c�m�m�7�7��C��
�
�+�S����1J�1J�-K�L�������%�������'�������'�$���#���	�	�s�E�Ec�
�Gd�dt�}|j|d�|d��}|j|j��|j|d�|d��}|j	|j��|j|d�|d��}|j	|j��|j|d�|d��}|j	|j��y)Nc��eZdZd�Zd�Zy)�8BufferedRWPairTest.test_isatty.<locals>.SelectableIsAttyc�<�tj|�||_yrJ)rprH�_isatty)r;�isattys  rrHzABufferedRWPairTest.test_isatty.<locals>.SelectableIsAtty.__init__�s���"�"�4�(�%��r c��|jSrJ)rPr:s rrQz?BufferedRWPairTest.test_isatty.<locals>.SelectableIsAtty.isatty�s���|�|�#r N)r#r$r%rHrQr&r r�SelectableIsAttyrN�s��
&�
$r rSFT)rpr�r�rQr�)r;rSrs   r�test_isattyzBufferedRWPairTest.test_isatty�s���	$�y�	$��w�w�'��.�0@��0G�H���������'��w�w�'��-�/?��/F�G��������
�&��w�w�'��.�0@��0F�G��������
�&��w�w�'��-�/?��/E�F��������
�&r c��|j|j�|j��}tj|�}d}d}yrJ)r�rpr�r�)r;�brwr�s   r�test_weakref_clearingz(BufferedRWPairTest.test_weakref_clearing�s8���g�g�d�n�n�&����(8�9���k�k�#������r N)r#r$r%r.r3r�rrr%r6rSr;r@r�r-r/r2r4r6r>rErKrTrWr&r rrr!so��&�-�B�?�M�N�2�D�/�8�
;�/�)�)�*�%�$�"!�4$�.'�*r rc�$�eZdZejZy)�CBufferedRWPairTestN)r#r$r%r�r3r�r&r rrYrY�s
��	�	�	�Br rYc�$�eZdZejZy)�PyBufferedRWPairTestN)r#r$r%r�r3r�r&r rr[r[�r�r r[c��eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZdZdZy)�BufferedRandomTest�rb+zwb+c�X�tj|�tj|�yrJ)r)r.r�r:s rr.z#BufferedRandomTest.test_constructor�s���+�+�D�1��+�+�D�1r c�X�tj|�tj|�yrJ)r)r3r�r:s rr3z%BufferedRandomTest.test_uninitialized	����-�-�d�3��-�-�d�3r c��|jd�}|j|d�}|jd|jd��|j	d�|j	d�|j|j�|jd|j��|jd|jd	�y)
N)�asdf�ghjkrV�asr~sdddseeerdsdddeeer)rpr�r�rtrMr�rD�r;r�rFs   r�test_read_and_writez&BufferedRandomTest.test_read_and_write	s����n�n�/�0��
�W�W�S�!�_����������
�+�
�����
���������)�)�*�����"�'�'�)�,�����C�$4�$4�Q�$7�8r c��|jd�}|j|�}|jd|jd��|jd|j	��|jdd�|jd|jd��|j
d�|jdd�|jd|j��|jd	|j	��|jd
d�|jd|j	��|jdd�|jd
|j	��|jd|jd��|j�|jd|j��|jt|j
d�y)Ns	asdfghjklrer~rrcris123fs	asdf123flr����r�r9rhsfl�r�)r0r�r�rtr`r]rMr�rr�r�rfs   r�test_seek_and_tellz%BufferedRandomTest.test_seek_and_tell	sH���l�l�<�(��
�W�W�S�\����������
�+�����B�G�G�I�&�
����1�
�����"�'�'�!�*�-�
�����
����1�
�����r�w�w�y�1�����B�G�G�I�&�
����A������B�G�G�I�&�
����1�
�����B�G�G�I�&����������,�
���
�����s�|�|�~�6����)�R�W�W�c�2r c�Z�|jd�}|j|�}|jd||d��|jd�|jd||d��|jd|j	��|j�|jd|j	��|jd||��|j
dd�|jd	�|j�|j
dd�|jd	||d
��y)NrUrr~r�rr�r�rsXYZr)r0r�r�rMr`r�r])r;�	read_funcr�r�s    r�check_flush_and_readz'BufferedRandomTest.check_flush_and_read&	s����l�l�<�(������������	�%�� 3�4�
���E������	�%�� 3�4�����E�J�J�L�)�
���
�����E�J�J�L�)������5�!1�2�����A���	�	�&��
���
�
�
�
�1�a�������5�!�!4�5r c�(�|jd��y)Nc� �|j|�SrJ)rt)r�r�s  rr�z8BufferedRandomTest.test_flush_and_read.<locals>.<lambda>9	s��z�u�z�z�4�7H�r �rnr:s r�test_flush_and_readz&BufferedRandomTest.test_flush_and_read8	s���!�!�"H�Ir c�.�dd�}|j|�y)Nc�d�t|dk\r|nd�}|j|�}t|d|�S)Nr�')r�rfr�r�rer(s   r�	_readintoz=BufferedRandomTest.test_flush_and_readinto.<locals>._readinto<	s2���q�A�v�!�4�0�A����q�!�A���2�A��<�r �r�rq)r;rws  r�test_flush_and_readintoz*BufferedRandomTest.test_flush_and_readinto;	s��	 �	
�!�!�)�,r c�.�dd�}|j|�y)Nc�r�|j|�}|dk7r|d|}|jt|�d�|S�Nr�r9)rDr]rrvs   r�_peekz5BufferedRandomTest.test_flush_and_peek.<locals>._peekC	s:���
�
�1�
�A��B�w��b�q�E���J�J�s�1�v�q�!��Hr rxrq�r;r}s  r�test_flush_and_peekz&BufferedRandomTest.test_flush_and_peekB	s��	�	
�!�!�%�(r c�p�|jd�}|j|�}|jd�|j�|jd�|j�|j	dd�|jd|j
��|jd|j��y)NrU�123s45rs	12345fghi)r0r�rMr�r]r�rrtr�s   r�test_flush_and_writez'BufferedRandomTest.test_flush_and_writeM	s����l�l�<�(��������
���F��
���
�
���E��
���
�
�
�
�1�a������s�|�|�~�6�����u�z�z�|�4r c�X�tj|�tj|�yrJ)r)rzr�r:s rrzzBufferedRandomTest.test_threadsY	s���'�'��-��'�'��-r c�T�d�}|j|�d�}|j|�y)Nc�&�|jd�yr�)rDr�s rr}z6BufferedRandomTest.test_writes_and_peek.<locals>._peek^	s
���J�J�q�Mr c��|j�}|jdd�|jd�|j|d�y)Nr�r9r)r`r]rDr�s  rr}z6BufferedRandomTest.test_writes_and_peek.<locals>._peeka	s4���*�*�,�C��J�J�r�1���J�J�q�M��J�J�s�A�r r�r~s  r�test_writes_and_peekz'BufferedRandomTest.test_writes_and_peek]	s*��	����%� �	�
	
���%� r c�,�d�}|j|�y)Nc�J�|jdd�|jd�yr|)r]rtr�s r�_readz7BufferedRandomTest.test_writes_and_reads.<locals>._readi	s���J�J�r�1���J�J�q�Mr r��r;r�s  r�test_writes_and_readsz(BufferedRandomTest.test_writes_and_readsh	s��	�	
���%� r c�,�d�}|j|�y)Nc�J�|jdd�|jd�yr|)r]rGr�s r�_read1z9BufferedRandomTest.test_writes_and_read1s.<locals>._read1o	s���J�J�r�1���K�K��Nr r�)r;r�s  r�test_writes_and_read1sz)BufferedRandomTest.test_writes_and_read1sn	s��	�	
���&�!r c�,�d�}|j|�y)Nc�\�|jdd�|jtd��yr|)r]rfr�r�s rr�z;BufferedRandomTest.test_writes_and_readintos.<locals>._readu	s ���J�J�r�1���N�N�9�Q�<�(r r�r�s  r�test_writes_and_readintosz,BufferedRandomTest.test_writes_and_readintost	s��	)�	
���%� r c��dD�]}|jd�}|j|d�}|j|jd�d�|j|j	�d�|jd|z�|j|j	�|dz�|j
�|j|j	�|dz�|j�}|j|dd|zzdd|z
zz���y)N)r9r�rrir9�A�Br�)r0r�r�rtr`rMr�r)r;�overwrite_sizer�r�r�s     r�test_write_after_readaheadz-BufferedRandomTest.test_write_after_readaheadz	s���%�	L�N��,�,�y�)�C��G�G�C��O�E����U�Z�Z��]�D�1����U�Z�Z�\�1�-��K�K��~�-�.����U�Z�Z�\�>�A�+=�>�
�K�K�M����U�Z�Z�\�>�A�+=�>�����A����Q��t�n�,�,�t�q�>�7I�/J�J�
L�	Lr c	�f�d�}d}tdt|��D]�}t|t|��D]z}|j|�}|j|d�}||||�|j	�t|�}d||<d||<|j
|j�|d||fz��|��y)Nc���||k\sJ�|j|�|j||z
�|jd�|j|�|jd�y)N��)r]rtrM)r��pos1�pos2s   r�mutatez:BufferedRandomTest.test_write_rewind_write.<locals>.mutate�	sN���4�<���J�J�t���J�J�t�d�{�#��K�K�� �
�J�J�t���K�K�� r s�����rrr~r9zfailed result for i=%d, j=%d)r�rr0r�r�r�r�r)r;r�r(r��jr�r��expecteds        r�test_write_rewind_writez*BufferedRandomTest.test_write_rewind_write�	s���		!�
$���q�#�a�&�!�
	J�A��1�c�!�f�%�	
J���l�l�1�o������S�)���u�a��#����
�$�Q�<����������� � ������!?�1�a�&�!H�J�	
J�
	Jr c�N�|jd�}|j|d�}|j|jd�d�|j|j	�d�|j|jd�d�|j|j	�d�y)Nrrr~sAAsBBri)r0r�r�rtrhrMr�s   r�!test_truncate_after_read_or_writez4BufferedRandomTest.test_truncate_after_read_or_write�	s���l�l�9�%������S�!��������A���.�������)�1�-�������U�+�Q�/�������)�1�-r c�X�tj|�tj|�yrJ)r)r~r�r:s rr~z%BufferedRandomTest.test_misbehaved_io�	rar c�H�|jd�5}|j|d�5}|jd�|j|j	d�d�|jd�|j|jd�d�|jd�t
d�}|j|�|j|d	�|jd
�|j|jd�d�|j�|j|j�d�ddd�ddd�|jd
�5}|j|d�5}|j|j	d�d�|jd�|j|j	d�d�|j�|j|j�d�ddd�ddd�y#1swY��xYw#1swY��xYw#1swY�*xYw#1swYyxYw)Nsabcdefghr�1r9r9�2rrH�f�4r�s1b2d3f4hr�r8rsa2c)r0r�rMr�rtrGr�rfrDr�r)r;r�r2rcs    r�test_interleaved_read_writez.BufferedRandomTest.test_interleaved_read_write�	s���
�\�\�+�
&�
	>�#�����c�"�
>�a�����
�� � ������D�1�����
�� � ������T�2�����
���l���
�
�3��� � ��d�+�����
�� � ������D�1����	�� � ������=�
>�
	>��\�\�&�
!�	9�S�����c�"�
9�a�� � ������D�1�����
�� � ������D�1����	�� � ������8�
9�	9�	9�
>�
>��
	>�
	>�� 
9�
9��	9�	9�sH�H�DG4�+H�H�BH�#H�4G=	�9H�H	�H	�H�H!c�"�|jd�5}|j|�5}|jd�|j|j	�d�|jd�|j|j	�d�|jd�|j|j	�d�|j�|j|j
�d�ddd�ddd�y#1swY�xYw#1swYyxYw)	Ns
ab
cdef
g
r�sb
r�rgrH�
s
1b
2def
3
)r0r�rMr�rr�r)r;r�r2s   r�test_interleaved_readline_writez2BufferedRandomTest.test_interleaved_readline_write�	s���
�\�\�*�
+�		C�s������
C������
�� � �����v�6�����
�� � �����x�8�����
�� � �����u�5����	�� � �����1A�B�
C�		C�		C�
C�
C��		C�		C�s#�D�CC9�(D�9D	�>D�DN)r#r$r%rtr�r.r3rgrkrnrrryrr�rzr�r�r�r�r�r�r�r~r�r�rr�r&r rr]r]�s����I��J�2�4�	9�3�.6�$J�-�	)�
5�.�	!�!�"�!�L�(J�4.�4�9�2
C��O�"&�r r]c�R�eZdZejZeddd��d��Zd�Zd�Z	y)�CBufferedRandomTestTr�r�c��tj|�tjdkDr]|j	�}|j|�}|j
tttf|j|tj�yyr�)r]r.rPr�rpr�r�rr�r�rHr�s   rr.z$CBufferedRandomTest.test_constructor�	r�r c�X�tj|�tj|�yrJ)r�r�rr:s rr�z+CBufferedRandomTest.test_garbage_collection�	s���3�3�D�9��3�3�D�9r c��|jtd�5|j|j�ddd�ddd�y#1swYyxYw)Nr/r+r�r:s rr�z#CBufferedRandomTest.test_args_error�	r�r�N)
r#r$r%r�r/r�rr.r�r�r&r rr�r��	s:��	�	�	�B��d�D�;G�H�4�H�4�:�6r r�c�$�eZdZejZy)�PyBufferedRandomTestN)r#r$r%r�r/r�r&r rr�r��	r�r r�c�B�eZdZdZdd�Zd�Zd�Zd�Zd�Zdd�Z	d	�Z
dZy
)
�StatefulIncrementalDecodera�
    For testing seek/tell behavior with a stateful, buffering decoder.

    Input is a sequence of words.  Words may be fixed-length (length set
    by input) or variable-length (period-terminated).  In variable-length
    mode, extra periods are ignored.  Possible words are:
      - 'i' followed by a number sets the input length, I (maximum 99).
        When I is set to 0, words are space-terminated.
      - 'o' followed by a number sets the output length, O (maximum 99).
      - Any other word is converted into a word followed by a period on
        the output.  The output word consists of the input word truncated
        or padded out with hyphens to make its length equal to O.  If O
        is 0, the word is output verbatim without truncating or padding.
    I and O are initially set to 1.  When I changes, any buffered input is
    re-scanned according to the new I.  EOF also terminates the last word.
    c�d�tjj||�|j�yrJ)�codecs�IncrementalDecoderrH�reset)r;rms  rrHz#StatefulIncrementalDecoder.__init__
s!���!�!�*�*�4��8��
�
�r c��dt|�zS)Nz<SID %x>)�idr:s r�__repr__z#StatefulIncrementalDecoder.__repr__
s���B�t�H�$�$r c�>�d|_d|_t�|_yr�)r��or�r�r:s rr�z StatefulIncrementalDecoder.reset"
s���������k��r c�x�|jdz|jdz}}t|j�|dz|zfS)Nr9r)r�r�rr�)r;r�r�s   r�getstatez#StatefulIncrementalDecoder.getstate'
s7���v�v��z�4�6�6�A�:�1���T�[�[�!�1�S�5�1�9�,�,r c�v�|\}}t|�|_t|d�\}}|dz|dzc|_|_y)Nrr9)r�r��divmodr�r�)r;�stater�r�r�r�s      r�setstatez#StatefulIncrementalDecoder.setstate+
s=���
�����'����b�#����1��Q���A������r Fc��d}|D]�}|jdk(rK|td�k(r!|js�-||j�z
}�A|jj	|��]|jj	|�t|j�|jk(s��||j�z
}��|r|jr||j�z
}|S)Nr�r�.)r��ordr��process_wordrKr)r;�input�final�outputr(s     r�decodez!StatefulIncrementalDecoder.decode1
s������
	2�A��v�v��{���C��=��{�{��$�"3�"3�"5�5���K�K�&�&�q�)����"�"�1�%��t�{�{�#�t�v�v�-��d�/�/�1�1�F�
	2��T�[�[��d�'�'�)�)�F��
r c��d}|jdtd�k(r,tdt|jddxsd��|_n�|jdtd�k(r,tdt|jddxsd��|_ne|jj
d�}t|�|j
kr|d|j
zz
}|j
r|d|j
}|d	z
}t�|_|S)
Nr�rr��cr9r�r:�-r�)	r�r�rf�intr�r�r�rr�)r;r�s  rr�z'StatefulIncrementalDecoder.process_wordB
s������;�;�q�>�S��X�%���S����Q�R��!5�A�6�7�D�F�
�[�[��^�s�3�x�
'���S����Q�R��!5�A�6�7�D�F��[�[�'�'��0�F��6�{�T�V�V�#��#�d�f�f�*�$���v�v���������c�M�F��k����
r N)�strictr{)r#r$r%rirHr�r�r�r�r�r��codecEnabledr&r rr�r�	
s1���"�%�"�
-�&��"� �Lr r�c	��tjrE|dk(r?tjd�}tjd|j
ddddt��Syy)N�test_decoderr,)r+�encoder��incrementalencoder�streamreader�streamwriter�incrementaldecoder)r�r�r��lookup�	CodecInfor�)r+�latin1s  r�lookupTestDecoderr�W
sR��!�.�.�4�>�3I����y�)�������
�
�d�#��D�9�	;�	;�4J�.r c��eZdZdZgd�Zd�Zy)�StatefulIncrementalDecoderTestzB
    Make sure the StatefulIncrementalDecoder actually works.
    ))r]Fza.b.c.d.)�oiabcdT�abcd.)soi...abcd...Tr�)si.o6.x.xyz.toolongtofit.Fzx-----.xyz---.toolon.)s
i.i2.o6xyzTzxy----.z-----.)si.o3.i6.abcdefghijklmnopTzabc.ghi.mno.)s;i.o29.a.b.cde.o15.abcdefghijabcdefghij.i3.a.b.c.d.ei00k.l.mTz�a----------------------------.b----------------------------.cde--------------------------.abcdefghijabcde.a.b------------..c.------------.d.e------------.k--------------.l--------------.m--------------.c� �|jD]2\}}}t�}|j|j||�|��4t�}|j|jd�d�|j|jdd�d�y)Nr�r�r r9r�)�
test_casesr�r�r�)r;r��eofr�r�s     rr�z+StatefulIncrementalDecoderTest.test_decoder�
s}��"&�/�/�	;��E�3��*�,�A����Q�X�X�e�S�1�6�:�	;�

'�(��������)�,�b�1�������#�q�)�7�3r N)r#r$r%rir�r�r&r rr�r�a
s����J�6	4r r�c�h�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Ze
jej j"d�d��Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%d �Z&d!�Z'd"�Z(d#�Z)d$�Z*d%�Z+d&�Z,d'�Z-d(�Z.d)�Z/d*�Z0d+�Z1d,�Z2d-�Z3d.�Z4d/�Z5e6jne8jr�d0���Z:d1�Z;d2�Z<d3�Z=d4�Z>d5�Z?d6�Z@d7�ZAd8�ZBd9�ZCd:�ZDd;�ZEd<�ZFd=�ZGd>�ZHd?�ZId@�ZJdA�ZKdB�ZLdC�ZMdD�ZNdE�ZOdF�ZPdG�ZQdH�ZRdI�ZSdJ�ZTdK�ZUdL�ZVyM)N�TextIOWrapperTestc��d|_djd�|_tjtj
�t
jt�|jtjt�y)NsAAA
BBB
CCC
DDD
EEE
sAAA
BBB
CCC
DDD
EEE
r:)�testdatar��
normalizedrr�r�r��registerr�r"�
unregisterr:s rr�zTextIOWrapperTest.setUp�
sQ��:��
�6�=�=�g�F�������)�)�*����)�*�����)�)�+<�=r c�J�tjtj�yrJr�r:s rr�zTextIOWrapperTest.tearDown�
r�r c��|jd�}|j|d�}|j|d��}|j|dd��|j	|j
d�|j	|jd�|j|dd	�
�|j	|j
d�|j	|jd	�|j	d|j��|jrtnt}|j|�5|j|d��ddd�|jt�5|j|d
��ddd�|jt�5|j|d��ddd�|j|�5|j|dd��ddd�tjs&tj j"s|jr2|jt�5|j|dd
��ddd�tjs&tj j"s|jr2|jt�5|j|dd��ddd�|jt�5|j|dd��ddd�|jt�5|j|dd
��ddd�|jt�5|j|dd��ddd�|jt�5|j|dd��ddd�y#1swY��3xYw#1swY��xYw#1swY���xYw#1swY���xYw#1swY��oxYw#1swY��xYw#1swY��xYw#1swY��xYw#1swY��xYw#1swYyxYw)N�é

rgr	r-r,�
r=FT)r.�line_buffering�é
rT��zutf-8�r.rmzreplace�
r�)r0r(r<rHr�r.r�r�is_Cr�r�r��UnicodeEncodeErrorr�Py_DEBUGrPr�dev_mode)r;r+r(r�invalid_types     rr.z"TextIOWrapperTest.test_constructor�
s#���L�L��)������4�(�����q�7��3��	�
�
�1�y�&�
�9�������Y�/�����)�)�5�1�	�
�
�1�w�t�
�<�������W�-�����)�)�4�0�����1�:�:�<�0�$(�I�I�y�:��
�
�
�|�
,�	'�
�J�J�q�2�J�&�	'�
�
�
�1�
2�	-�
�J�J�q�8�J�,�	-�
�
�
�z�
*�	.�
�J�J�q�9�J�-�	.�
�
�
�|�
,�	7�
�J�J�q�7�2�J�6�	7����s�y�y�1�1�T�Y�Y��"�"�#5�6�
A��
�
�1�w�x�
�@�
A����s�y�y�1�1�T�Y�Y��"�"�:�.�
D��
�
�1�w�{�
�C�
D�
�
�
�y�
)�	8�
�J�J�q�7�B�J�7�	8�
�
�
�z�
*�	>�
�J�J�q�7�H�J�=�	>�
�
�
�z�
*�	<�
�J�J�q�7�F�J�;�	<�
�
�
�z�
*�	=�
�J�J�q�7�G�J�<�	=�	=�)	'�	'��	-�	-��	.�	.��	7�	7��
A�
A��
D�
D��	8�	8��	>�	>��	<�	<��	=�	=�sx�M�	M*�:M7�'N�N�7N�)N+�N7�
O�?O�M'�*M4�7N�N�N�N(�+N4�7O�O�Oc��|jj|j�}~|jj|j�}|jtt|�|jttfd|jd�|j|j�d��|j|jd�d�y)Nr1rr	r-r�)r<r2r�rkr�rTr�r�rtrHrpr��r;rs  rr3z$TextIOWrapperTest.test_uninitialized�
s������&�&�t�'9�'9�:��
����&�&�t�'9�'9�:�����)�T�1�-����
�N�;�?� �v�v�q�	*�	
�
�
�4�>�>�#�g�
�6���������B�'r c���|j�}|j|�}|jtd�5|j	|d��ddd�y#1swYyxYw)Nzis not a text encoding�hexr-)r0r,rT�LookupErrorr<)r;r+r(s   r�*test_non_text_encoding_codecs_are_rejectedz<TextIOWrapperTest.test_non_text_encoding_codecs_are_rejected�
sX��
�L�L�N������"��
�
#�
#�K�1I�
J�	2����q�5��1�	2�	2�	2�s�A�Ac���|j�}|j|�}|j|d��}|j|j	�|�|j|d��}|jd�|j
|j��|j	�|j|j�d�|jt|j�t|�|j|jd�|j|jd�|j
|j�|j
|j�y)Nr:r-�howdyshowdyr�)r0r,r<r�r�rMr�rr�r�r�r�r.rmr��
write_through�r;r+r(rs    rr�zTextIOWrapperTest.test_detach�
s���L�L�N������"�����q�7��3���
�
�a�h�h�j�!�$����q�7��3��	������������&�	���
��������x�0����*�a�h�h�/�	
�Q��������W�-�������8�,�����)�)�*�������)r c��|jdjd��}|j|�}|j|d��}|jj}|jt
|�d|z�d|_|jt
|�d|z�d|_|jt
|�d|z�d	|_|jt
|�d
|z�|jj�t
|�y)N�hellor	r-z'<(%s\.)?TextIOWrapper encoding='utf-8'>r�z4<(%s\.)?TextIOWrapper name='dummy' encoding='utf-8'>r+z=<(%s\.)?TextIOWrapper name='dummy' mode='r' encoding='utf-8'>r�z><(%s\.)?TextIOWrapper name=b'dummy' mode='r' encoding='utf-8'>)r0r�r(r<r$r�r�r+�moder�r�)r;r�r(r�modnames     rr�zTextIOWrapperTest.test_repr�
s����l�l�7�>�>�'�2�3������$�����q�7��3���$�$�/�/������a��C�g�M�	O��������a��P�SZ�Z�	\��������a��Y�\c�c�	e��������a��Z�]d�d�	f�	
�������Q�r c���|j�}|j|d��}tj|d|�5	t	|�ddd�y#t
$rY�wxYw#1swYyxYw)Nr	r-r+)r0r<rr�r�r��r;r�rs   rr�z%TextIOWrapperTest.test_recursive_repr�
sn���l�l�n�����s�W��5��
�
�
�s�F�A�
.�	�
��Q��	�	�� �
��
��	�	�s(�A �A�	A�A �A�A � A)c��|j�}|j|d�}|j|ddd��}|jd�|j	|j�d�|jd�|j	|j�d	�|jd
�|j	|j�d�y)Nrgr	�
T�r.r>r��Xr zY
ZsXY
ZzA
BsXY
ZA
B)r0r,r<rMr�rrs    r�test_line_bufferingz%TextIOWrapperTest.test_line_bufferings����L�L�N������4�(�����q�7�D�QU��V��	������������s�+�	������������x�0�	������������|�4r c���|j�}|j|d�}|j|ddd��}|jd�|j	|j�d�|j
d�	�|j	|j�d
�|jd�|j	|j�d�|jd
�|j	|j�d�|j
d�	�|j	|j�d�|jd�|j	|j�d�|j
�|j
d�	�|j	|jd�|j
d�	�|j
�|j
d�	�|j	|jd�y)Nrgr	r
FrzAB
Cr T�r�sAB
CzDEF
Gs	AB
CDEF
G�Hs
AB
CDEF
GH�IJ)r0r,r<rMr�r�reconfigurer�rs    r�test_reconfigure_line_bufferingz1TextIOWrapperTest.test_reconfigure_line_bufferingsq���L�L�N������4�(�����q�7�D�QV��W��	������������s�+�	�
�
�T�
�*��������x�0�	������������~�6�	������������~�6�	�
�
�U�
�+���������7�	����
���������7�	
�
�
��	�
�
�T�
�*�����)�)�5�1�	�
�
�T�
�*�	�
�
��	�
�
�T�
�*�����)�)�4�0r zutf-8 mode is enabledc��ttj�}	dD]&}|tjvs�tj|=�(tj�}|j�}t
j�5t
jdt�|j|�}ddd�|jj|�tjj�tjj|�y#1swY�cxYw#tjj�tjj|�wxYw)N)�LC_ALL�LANG�LC_CTYPErX)r�r�environ�locale�getencodingr0rYrZr[�EncodingWarningr<r�r.�clear�update)r;�old_environ�key�current_locale_encodingr(rs      r�test_default_encodingz'TextIOWrapperTest.test_default_encoding's����2�:�:�&��	+�6�
(���"�*�*�$��
�
�3��
(�'-�&8�&8�&:�#�����A��(�(�*�
*��%�%�h��@��&�&�q�)��
*�
���Q�Z�Z�)@�A��J�J�����J�J���k�*�

*�
*��

�J�J�����J�J���k�*�s)�D�AD�>,D�*$D�D�D�?Ec��|j�}|j|d��}|j|jd�t	j
�5t	jdt�|j|�}ddd�|j|j�tj|j�y#1swY�DxYw)Nr	r-rX)r0r<r�r.rYrZr[r�assertIsNotNoner�r��r;r(rs   r�
test_encodingzTextIOWrapperTest.test_encoding<s����L�L�N�����q�7��3��������W�-�
�
$�
$�
&�	&��!�!�(�O�<��"�"�1�%�A�	&�	
���Q�Z�Z�(��
�
�a�j�j�!�		&�	&�s�,C�Cc�*�|jd�}|j|d��}|jt|j�|jd�}|j|dd��}|jt|j�|jd�}|j|dd��}|j|j	�d�|jd�}|j|dd��}|j|j	�d	�y)
Nsabc
�
r:r-r�r�rXzabc

�replaceuabc
�
)r0r<r��UnicodeErrorrtr�r's   r�test_encoding_errors_readingz.TextIOWrapperTest.test_encoding_errors_readingGs����L�L��(�����q�7��3�����,����/��L�L��(�����q�7�8��D�����,����/��L�L��(�����q�7�8��D���������9�-��L�L��(�����q�7�9��E���������?�3r c��|j�}|j|d��}|jt|jd�|j�}|j|dd��}|jt|jd�|j�}|j|ddd��}|j	d	�|j�|j
|j�d
�|j�}|j|ddd��}|j	d	�|j�|j
|j�d�y)
Nr:r-�ÿr�r�rXr
)r.rmr>u	abcÿdef
sabcdef
r*sabc?def
)r0r<r�r+rMr�r�rr's   r�test_encoding_errors_writingz.TextIOWrapperTest.test_encoding_errors_writingYs���L�L�N�����q�7��3�����,�����8��L�L�N�����q�7�8��D�����,�����8��L�L�N�����q�7�8�%)�
�
+��	�����	���	��������{�3��L�L�N�����q�7�9�%)�
�
+��	�����	���	��������|�4r c
��gd�}dgd�gd|gdgd�gdddggd	gd
�gg}d}|D�]4}tdj|�j|��}dD�]}td
d�D]�}|D]�\}}	|j	|j|�|�}
|j
|
||��}|rXg}	|jd�}
|
dk(rnI|jt|
�d�|j|
|j�z��Ut|�}t||	�D]\}}|j||��|jt|�t|	����������7y)N)�unix
�	windows
zos9
�last
�nonl)r1zwindows
zos9
r3r4r�r
)r1r2z	os9
last
r4r�zunix
windows
z
os9
last
nonl�
)z
unix
windows
z
os9
z	last
nonl)r	r,�utf-16�	utf-16-le�	utf-16-be�utf-32�	utf-32-le�	utf-32-be)FTr9r��r>r.r~)rr�r�r�r(r0r<rtr�rrKrrB�zip)r;�input_linesrS�	encodingsr.r�do_readsr�r>�	exp_linesr��textio�	got_lines�c2�got_line�exp_lines                r�
test_newlineszTextIOWrapperTest.test_newlinesqs���L���H�J��+���F�H��+�->�@�B��B�D�
��
�	�"�	I�H������-�4�4�X�>�?�D�)�
I��$�Q��|�I�G�.3�I�*��� $� 3� 3�D�L�L��4F�� P��!%�!3�!3�E�7�;C�"4�"E��#�(*�I�"&�%+�[�[��^��#%��8�$)� $� 0� 0��R��!� <� )� 0� 0��f�o�o�6G�1G� H�#'�)-�V��I�25�i��2K�A�.�H�h� �,�,�X�x�@�A��(�(��Y���Y��H�#I�I�
I�	Ir c��d}|jdd�jdd�}d|jd�jd��fd|jd�jd��fd	gd
�fdgd�fd
gd�ffD]�\}}|j|�}|j	|d|��}|j|j
�|�|jd�|j|j�dj|����y)NsAAA
BBB
CCC
DDD
EEE
FFF
GGGs
r��
r:T)�keependsr�r
)zAAA
zBBB
z
CCC
DDD
EEE
�FFF
�GGGr�)zAAA
BBB
CCC
DDD
EEE
rKrLr5)z
AAA
BBB
CCC
zDDD
zEEE
z
FFF
z
GGGr=r)
r*r��
splitlinesr0r<r�r|r]rtr�)r;r�r�r>r�rc�txts       r�test_newlines_inputz%TextIOWrapperTest.test_newlines_input�s���?���%�%�g�u�5�=�=�e�U�K�
�
�:�$�$�W�-�8�8�$�8�G�H�
�����)�4�4�d�4�C�D�
�P�Q�
�J�K�
�Q�R�"�	<��G�X��,�,�x�(�C��$�$�S�7�G�$�L�C����S�]�]�_�h�7��H�H�Q�K����S�X�X�Z�����):�;�	<r c���ddddd�}d|tjfgt|j��z}|D]�\}}|j	�}|j|d|��}|j
d�|j
d�|j
d	�|j�|j|jd
�|j|j�|���y)NsAAA
BBB
CCC
X
Y
ZsAAA
BBB
CCC
X
Y

ZsAAA
BBB
CCC
X
Y

Z)r�r
r5r�r:r=zAAA
BzBB
CCC
zX
Y
ZF)r�linesep�sortedr�r0r<rMr�r�r�r)r;�testdictrSr>r�rcrNs       r�test_newlines_outputz&TextIOWrapperTest.test_newlines_output�s���+�-�-�7�	�������,�-�.�����8H�1I�I��!&�	7��G�X��,�,�.�C��$�$�S�7�G�$�L�C��I�I�h���I�I�k�"��I�I�k�"��I�I�K����S�Z�Z��/����S�\�\�^�X�6�	7r c�����g�|j�G��fd�d��}|�}|j|d��}|jd�~tj�|jdg��y)Nc���eZdZ��fd�Zy)�4TextIOWrapperTest.test_destructor.<locals>.MyBytesIOc�f���j|j���j|�yrJ)rKrr�)r;r�rws ��rr�z:TextIOWrapperTest.test_destructor.<locals>.MyBytesIO.close�s!����������)��
�
�4� r Nr�)r�rws��r�	MyBytesIOrW�s���
!r rYr:r-r�r�)r0r<rMrr�r�)r;rYr(rr�rws    @@rr�z!TextIOWrapperTest.test_destructor�sg������|�|��	!��	!�
�K�����q�7��3��	�����
��������&��1�%r c���g�G�fd�d|j�}|j�}||d��}~tj�|j	�gd��y)Nc�:���eZdZ��fd�Z��fd�Z��fd�Z�xZS)�<TextIOWrapperTest.test_override_destructor.<locals>.MyTextIOc�j���jd�	t�|�}|�y#t$rYywxYwr�r�r�s  ��rr�zDTextIOWrapperTest.test_override_destructor.<locals>.MyTextIO.__del__�r�r�c�D���jd�t�|�	�yr}r�r�s ��rr�zBTextIOWrapperTest.test_override_destructor.<locals>.MyTextIO.close�r�r c�D���jd�t�|�	�yr�r�r�s ��rr�zBTextIOWrapperTest.test_override_destructor.<locals>.MyTextIO.flush�r�r r�r�s@�r�MyTextIOr\�r�r r`r:r-r�)r<r0rr�r�)r;r`r(rr�s    @rr�z*TextIOWrapperTest.test_override_destructor�sR�����	 �t�)�)�	 �
�L�L�N���Q��)��
����������+r c��|j�}tj�5}|jt�5|j|d��jddd�ts|j|j�n6|j�*|j|jjt�ddd�y#1swY�jxYw#1swYyxYw)Nr	r-)
r�rr�r�r�r<r�r�r�r�r�r�r�r�s   rr�z/TextIOWrapperTest.test_error_through_destructor�s����#�#�%��
�
/�
/�
1�	B�R��"�"�>�2�
B��"�"�5�7�"�;�A�A�
B�+��!�!�"�-�-�0����*�� � ����!7�!7��A�	B�	B�
B�
B��	B�	B�s#�C�C�A C�C	�C�Cc�j�dD�]�}dD�]�}|jtjd|��}||_|j	|jd�d�|j
�|jtjd|��}||_|j	|j�d�|j	|j�d�|j�}|j	|jd�d�|j	|jd�d�|jd�|j	|jd	�d
�|j	|jd�d�|j	|jd�d
�|j	|j�d
�|j	|j�|�|j	|jd�d�|j	|jdd	�|�|j	|jd�d�|j	|j|�|�|j	|j�d�|jd�r|j||�|j
�������y)N)r9r~rrir�r�r,��� �!�?�@�A)r:r,r	�w+r-r�r�r+rr~r�r9ryr��def�utf)r/rr�r1r�rMr�r`rtr]rR�multi_line_test)r;�	chunksize�encr2�cookies     r�
test_basic_iozTextIOWrapperTest.test_basic_io�s��L�	�I�2�
���I�I�i�.�.��s�I�C�� )��
�� � �������3����	��I�I�i�.�.��s�I�C�� )��
�� � �����1�-�� � �����5�1������� � ������A�.�� � ������u�5����q�	�� � ������D�1�� � ������C�0�� � ������B�/�� � �����2�.�� � �����6�2�� � ������A�.�� � �����1��v�6�� � �������3�� � �������8�� � �����5�1��>�>�%�(��(�(��C�0����	�3
�	r c	��|jd�|j�d}g}dD]z}g}t|�D]"}|j||t	|�z��$dj|�dz}|j|j
�|f�|j|��||jd�g}		|j
�}
|j�}|sn|	j|
|f��7|j|	|�y)Nru	sÿ࿿￿)rr9r~rrir��rdrerf�>rgrhrirgr�r
)
r]rhr�rKrr�r`rMrr�)r;r2rp�sample�wlinesrF�charsr��line�rlinesrs           rrnz!TextIOWrapperTest.multi_line_tests���	���q�	�	�
�
��$����L�	�D��E��4�[�
6�����V�A��F��O�4�5�
6��7�7�5�>�D�(�D��M�M�1�6�6�8�T�*�+�
�G�G�D�M�
	�	
���q�	�����&�&�(�C��:�:�<�D����M�M�3��+�&��	
�����(r c�B�|jtjdd��}|j�}|j	d�|j�}|j	d�|j�}|jd�|j
|j�|�|j
|j�d�|j
|j�|�|j
|j�d�|j
|j�|�|jd�|D]4}|j
|d�|jt|j��6|j
|j�|�|j�y)Nrjr	r-uÿ
r)r/rr�r`rMr]r�rr�r�r�)r;r2�p0�p1�p2rys      r�test_tellingzTextIOWrapperTest.test_telling$s-���I�I�i�&�&��w�I�?��
�V�V�X��	�����
�V�V�X��	�����
�V�V�X��	���q�	��������2�&��������x�0��������2�&��������x�0��������2�&�	���q�	��	/�D����T�8�,����g�q�v�v�.�	/�	
�������2�&�	���	r c���t�}|dz
}d|z}t|jd��}|jt	|�t	|��d}t|jd��}||z}|jtjd�5}|j|dz�ddd�|jtjdd��5}|j|�}	|j|	t|d��|j|j�|�|j|j�|�ddd�y#1swY��xYw#1swYyxYw)	Nr~r�r	�袈
r
r+r-r:)
r3rr�r�rr/rr�rMrtrr`r)
r;�
chunk_size�prefix_size�u_prefix�prefix�u_suffix�suffixryr2r�s
          r�test_seekingzTextIOWrapperTest.test_seeking8s(��(�*�
� �1�n����$���x���w�/�0������X���F��4����x���w�/�0������
�Y�Y�y�'�'��
.�	�!�
�G�G�D��F�O�	�
�Y�Y�y�'�'��w�Y�
?�	5�1����{�#�A����Q��F�G� 4�5����Q�V�V�X�{�3����Q�Z�Z�\�8�4�		5�	5�	�	��	5�	5�s�E
�A.E�
E�Ec�h�d}|jtjd�5}|j|�ddd�|jtjdd��5}|jd|_|j�|j
�ddd�y#1swY�hxYw#1swYyxYw)Ns࿿
r
r+r	r-r~)r/rr�rMr1rr`)r;rr2s   r�test_seeking_tooz"TextIOWrapperTest.test_seeking_tooIs��� ��
�Y�Y�y�'�'��
.�	�!�
�G�G�D�M�	�
�Y�Y�y�'�'��w�Y�
?�	�1�
�M�M��A�M�
�J�J�L�
�F�F�H�		�	�	�	��	�	�s�B�4B(�B%�(B1c�,���d�d��fd�	}dt_	tjD]\}}}||��tjD]-\}}}�t	|�dzz
}d|z}|dz}|||z|��/	dt_y#dt_wxYw)N�rc	����jtjd�}|j|�|j	��jtjd��}�|_|j
�}|j	�t|t|�dz�D]�}ddt|�|z
fD]�}�jtjd��}�j|j
|�|d|�|j�}�j|j
|�||||z�|j|��j|j
�||d�|j	�����y)zTell/seek to various points within a data stream and ensure
            that the decoded data returned by read() is consistent.r
r�r-r9r�N)r/rr�rMr�r1rtr�rr�r`r])	r�min_posr2�decodedr�r�rq�
CHUNK_SIZEr;s	       ��r�test_seek_and_tell_with_datazJTextIOWrapperTest.test_seek_and_tell.<locals>.test_seek_and_tell_with_dataYs4����	�	�)�*�*�D�1�A�
�G�G�D�M�
�G�G�I��	�	�)�*�*�^�	�D�A�&�A�M��f�f�h�G�
�G�G�I��7�C��L�1�$4�5�
���Q��G��q� 0�1��A��	�	�)�"2�"2�^�	�L�A��$�$�Q�V�V�A�Y�����<��V�V�X�F��$�$�Q�V�V�A�Y���!�a�%�0@�A��F�F�6�N��$�$�Q�V�V�X�w�q�r�{�;��G�G�I��
r r9r~�.r�)r�r�r�r�r)r;r�r�r��offsetr�r�r�s`      @rrkz$TextIOWrapperTest.test_seek_and_tellTs�����
�	�,34�"�/�	8�=�H�H�
4���q�!�,�U�3�
4� >�H�H�
F���q�!�#�c�%�j�!�m�3���f��� ��(��,�V�e�^�W�E�
F�78�&�3��a�&�3�s�A!B�
Bc�P�|jtjdd��}|jd�|j	�|jtjdd��}|j|j
�d�|j�}|j|j
�d�|j�}|j|�|j|j
�d�|j|j�|�|j	�y)Nr�euc_jpr-u
AB
うえ
r+zAB
uうえ
)	r/rr�rMr�r�rr`r])r;r2r|r}s    r�test_multibyte_seek_and_tellz.TextIOWrapperTest.test_multibyte_seek_and_tell�s����I�I�i�&�&��h�I�?��	���$�%�	���	��I�I�i�&�&��h�I�?���������v�.�
�V�V�X���������'7�8�
�V�V�X��	���r�
��������'7�8��������2�&�	���	r c��|jtjdd��}|jd�|j	�}|jd�|j|�|jd�|j
�|jtjdd��}|j|j�d�|j
�y)	Nr�euc_jis_2004r-uæ̀�æùr+uæ̀̀)	r/rr�rMr`r]r�r�r)r;r2r|s   r�test_seek_with_encoder_statez.TextIOWrapperTest.test_seek_with_encoder_state�s����I�I�i�&�&��n�I�E��	�����
�V�V�X��	�����	���r�
�	�����	���	��I�I�i�&�&��n�I�E���������';�<�	���	r c���d}d}|D]�}|j�}|j||��}|j|�|j|�|jd�|j	|j�|dz�|jd�|j	|j�|dz�|j	|j
�|dzj|����y)N�
1234567890)r6r7r8r9r:r;r-rr~)r0r<rMr]r�rtrr�)r;rrSr.rcr2s      r�test_encoded_writesz%TextIOWrapperTest.test_encoded_writes�s��������
	J�H��,�,�.�C��"�"�3��"�:�A�
�G�G�D�M�
�G�G�D�M�
�F�F�1�I����Q�V�V�X�t�a�x�0�
�F�F�1�I����Q�V�V�X�t�a�x�0����S�\�\�^�d�Q�h�->�->�x�-H�I�
	Jr c��Gd�d|j�}|j|�d��}|jt|j�y)Nc��eZdZd�Zy)�5TextIOWrapperTest.test_unreadable.<locals>.UnReadablec��yr�r&r:s rrWz>TextIOWrapperTest.test_unreadable.<locals>.UnReadable.readable�rr Nrr&r r�
UnReadabler��rr r�r	r-)r0r<r�r�rt)r;r�rNs   r�test_unreadablez!TextIOWrapperTest.test_unreadable�s?��	����	�� � ���� �@�����'�3�8�8�,r c��|j|jd�d��}d}	|jd�}|sn||z
}�|j|d�y)NsAA
BBr	r-r�r9zAA
BB�r<r0rtr��r;rN�readsrys    r�test_read_one_by_onez&TextIOWrapperTest.test_read_one_by_one�s[��� � ����k�!:�W� �M����������A����Q�J�E�	�
	
�����)r c�\�|j|jd�d��}|j|j�gd��|j	d�|j|jd�gd��|j	d�|j|jd�ddg�y)	NsAA
BB
CCr	r-)�AA
�BB
�CCrr�r�r�)r<r0r�r|r]�r;rNs  rrSz TextIOWrapperTest.test_readlines�s���� � ����m�!<�w� �O���������*@�A������������t�,�.D�E������������q�)�F�F�+;�<r c��|j|jd�d��}d}	|jd�}|sn||z
}�|j|d�y)Ns�AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Br	r-r�r�z�AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Br�r�s    r�test_read_by_chunkz$TextIOWrapperTest.test_read_by_chunk�s\��� � ����.C�!D�w� �W���������
�A����Q�J�E�	�
	
����
�.r c���gd�}|j�}|j|d��}|j|�|j�|j	|j�d�y�N)r��cd�efr	r-r�)r0r<rr�r�r�r;rwrcrNs    rr�z!TextIOWrapperTest.test_writelines�sR�����l�l�n��� � ��w� �7�����q���	�	����������3r c���tgd��}|j�}|j|d��}|j|�|j	�|j|j
�d�yr�)rr0r<rr�r�rr�s    rr�z*TextIOWrapperTest.test_writelines_userlist�sX���'�(���l�l�n��� � ��w� �7�����q���	�	����������3r c��|j|j�d��}|jt|jgd��|jt|jd�|jt|jd�y)Nr	r-r�r�)r<r0r�r�rr�s  rr�z'TextIOWrapperTest.test_writelines_error�s_��� � �����'� �B�����)�S�^�^�Y�?����)�S�^�^�T�:����)�S�^�^�V�<r c���|j|j|j�d��}d}	|jd�}|sn||z
}�|j	||j
�y)Nr:r-r�r9)r<r0r�rtr�r�r�s    r�test_issue1395_1z"TextIOWrapperTest.test_issue1395_1�se��� � ����d�m�m�!<�w� �O����������A����Q�J�E�	�
	
�������0r c���|j|j|j�d��}d|_d}	|j	d�}|sn||z
}�|j||j�y)Nr:r-rir��r<r0r�r1rtr�r�r�s    r�test_issue1395_2z"TextIOWrapperTest.test_issue1395_2�sj��� � ����d�m�m�!<�w� �O�������������A����Q�J�E�	�
	
�������0r c�^�|j|j|j�d��}d|_|j	d�}||j	d�z
}||j�z
}||j�z
}||j�z
}|j
||j�y�Nr:r-ri)r<r0r�r1rtrr�r��r;rNr�s   r�test_issue1395_3z"TextIOWrapperTest.test_issue1395_3
s���� � ����d�m�m�!<�w� �O�����������
����!����
�������
�������
��������������0r c���|j|j|j�d��}d|_|j	d�}||j	�z
}|j||j�yr�r�r�s   r�test_issue1395_4z"TextIOWrapperTest.test_issue1395_4
s\��� � ����d�m�m�!<�w� �O�����������
��������������0r c�2�|j|j|j�d��}d|_|j	d�}|j�}|j
d�|j
|�|j|j	d�d�y)Nr:r-rirzBBB
)r<r0r�r1rtr`r]r�)r;rNr�rs    r�test_issue1395_5z"TextIOWrapperTest.test_issue1395_5
sq��� � ����d�m�m�!<�w� �O������������h�h�j�����������
�������!��g�.r c��|j|j�}|j|d��}|j|j	�|j	��y�Nr:r-)r0r�r<r�rY)r;r�rNs   r�test_issue2282z TextIOWrapperTest.test_issue2282#
sF�����d�m�m�,��� � ��'� �:��������*�C�L�L�N�;r c��tj}dD�]}|j|d|��5}|jd�|j	�}ddd�|j|d�5}|j|j
�dj|��ddd�|j|d|��5}|jd�ddd�|j|d�5}|j|j
�dj|��ddd���y#1swY��xYw#1swY��xYw#1swY�oxYw#1swY��6xYw)	N��	utf-8-sigr6r9rr-�aaar
r��xxx�aaaxxx)rr�r/rMr`r�rtr��r;�filename�charsetr2rs     r�test_append_bomz!TextIOWrapperTest.test_append_bom)
s+���#�#��8�
	E�G����8�S�7��;�
�q�������f�f�h��
����8�T�*�
B�a�� � �����5�<�<��+@�A�
B����8�S�7��;�
�q������
����8�T�*�
E�a�� � �����8�?�?�7�+C�D�
E�
E�
	E�
�
��
B�
B��
�
��
E�
E�s/�"D�'0D'�3D3�0D?�D$	�'D0	�3D<	�?E		c�N�tj}dD]�}|j|d|��5}|jd�|j	�}ddd�|j|d|��5}|j�|jd�|jd�|jd�ddd�|j|d	�5}|j
|j�d
j|��ddd���y#1swY��xYw#1swY�bxYw#1swY��xYw)Nr�rr-r�rk�zzzr�bbbr
�bbbzzz)	rr�r/rMr`r]r�rtr�r�s     r�
test_seek_bomzTextIOWrapperTest.test_seek_bom8
s���#�#��8�
	E�G����8�S�7��;�
�q�������f�f�h��
����8�T�G��<�
�����s����������q�	������	
�
���8�T�*�
E�a�� � �����8�?�?�7�+C�D�
E�
E�
	E�
�
��
�
��

E�
E�s$�"D�(AD�0D�D	�D	�D$	c� �tj}dD]�}|j|d|��5}|jd�ddd�|j|d|��5}|j	d�|j	d|j
�|jd�ddd�|j|d�5}|j
|j�d	j|��ddd���y#1swY��xYw#1swY�bxYw#1swY��xYw)
Nr�rr-r�r�rr�r
r�)	rr�r/rMr]rr�rtr�)r;r�r�r2s    r�test_seek_append_bomz&TextIOWrapperTest.test_seek_append_bomG
s����#�#��8�	E�G����8�S�7��;�
�q������
����8�S�7��;�
�q����q�	����q�$�-�-�(������
����8�T�*�
E�a�� � �����8�?�?�7�+C�D�
E�
E�	E�
�
��
�
��
E�
E�s#�C,�?C8�10D�,C5	�8D	�D
	c�R�|jtjdd��5}|j|jd�ddd�|jtjddd��5}|j|jd�ddd�y#1swY�RxYw#1swYyxYw)Nrr	r-r�r*r�)r/rr�r�rmrs  r�test_errors_propertyz&TextIOWrapperTest.test_errors_propertyT
s���
�Y�Y�y�'�'��w�Y�
?�	1�1����Q�X�X�x�0�	1�
�Y�Y�y�'�'��w�y�Y�
Q�	2�UV����Q�X�X�y�1�	2�	2�	1�	1��	2�	2�s�B�+B�B�B&c����tj��|jtjddd��5���fd�}td�D�cgc]}tj||f����}}tj|�j�5tjd�ddd�ddd�|jtjd�	�5��j�}td�D]&}|j|jd
|z�d��(	ddd�ycc}w#1swY��xYw#1swY��xYw#1swYyxYw)Nrr	r9r6c�R��d|z}�j��j|�y)N�Thread%03d
)rrM)re�text�eventr2s  ��r�runz1TextIOWrapperTest.test_threads_write.<locals>.run`
s!���%��)���
�
������
r r�r rpr-r�)r�r�r/rr�r�r#r
rur�r�r�rtr�r)r;r�rrx�contentrer�r2s      @@r�test_threads_writez$TextIOWrapperTest.test_threads_writeZ
s+������!��
�Y�Y�y�'�'��w�!�Y�
L�	!�PQ�
�
!&�b�	�+��!�'�'�s�!��>�+�G�+�!�/�/�����C�
!��
�
�4� �
!�	!��Y�Y�y�'�'�'�Y�
:�	G�a��f�f�h�G��2�Y�
G��� � ����~��/A�!B�A�F�
G�	G�	G��	+�
!�
!��	!�	!��	G�	G�sB�D6�D%�-"D6�D*�%D6�AE�%D6�*D3	�/D6�6D?�Ec����|j|j|j�d���g���fd�}|�_|j	t
�j�|j�j�|j�jj�|j��|j�d�|j�d�d��_y)Nr:r-c�b���j�jjg�ddt��rJ)r�r�r�)r�rNs��rr�z>TextIOWrapperTest.test_flush_error_on_close.<locals>.bad_flushr
s&������S�Z�Z�%6�%6�7�F�1�I��)�Or rr9c��yrJr&r&r rr�z=TextIOWrapperTest.test_flush_error_on_close.<locals>.<lambda>|
r�r )r<r0r�r�r�r�r�r�r�r�r�)r;r�r�rNs  @@rr�z+TextIOWrapperTest.test_flush_error_on_closem
s����� � ����d�m�m�!<�w� �O����	���	����'�3�9�9�-�����
�
�#�����
�
�)�)�*������������#�������#� ��	r c�R�|j|j�}d�}d�}||_|j|d��}||_|jt�5}|j�ddd�|jjjd�|j|jjt�|j|jjjd�|j|j�d�|_d�|_y#1swY��xYw)	Nc��td��r�rxr&r rr�z>TextIOWrapperTest.test_close_error_on_close.<locals>.bad_flush�
r�r c��td��r�rxr&r rr�z>TextIOWrapperTest.test_close_error_on_close.<locals>.bad_close�
r�r r:r-r�r�c��yrJr&r&r rr�z=TextIOWrapperTest.test_close_error_on_close.<locals>.<lambda>�
r�r c��yrJr&r&r rr�z=TextIOWrapperTest.test_close_error_on_close.<locals>.<lambda>�
r�r )r0r�r�r<r�r�r�r�rr�rrr�r��r;r�r�r�rNrs      rrz+TextIOWrapperTest.test_close_error_on_close~
s������d�m�m�,��	#�	#� ���� � ��'� �:����	�
�
�
�w�
'�	�3��I�I�K�	�������+�+�Z�8����c�m�m�7�7��A�������2�2�7�7��D�������$�$��� ��	�	�	�s�D�D&c�N�|j|j�}d�}d�}||_|j|d��}||_|jt�5}|j�ddd�|jdtj��|j|jjt�|jdt|jj��|j|j�d�|_d�|_y#1swY��xYw)	Nc��t�rJrr&r rr�zLTextIOWrapperTest.test_nonnormalized_close_error_on_close.<locals>.bad_flush�
r	r c��t�rJrr&r rr�zLTextIOWrapperTest.test_nonnormalized_close_error_on_close.<locals>.bad_close�
r	r r:r-rrc��yrJr&r&r rr�zKTextIOWrapperTest.test_nonnormalized_close_error_on_close.<locals>.<lambda>�
r�r c��yrJr&r&r rr�zKTextIOWrapperTest.test_nonnormalized_close_error_on_close.<locals>.<lambda>�
r�r )r0r�r�r<r�r�rrrrrrr�r�r�s      rrz9TextIOWrapperTest.test_nonnormalized_close_error_on_close�
s������d�m�m�,��	%�	%� ���� � ��'� �:����	�
�
�
�y�
)�	�S��I�I�K�	��
�
�*�C��
�
�,>�?����c�m�m�7�7��C��
�
�*�C��
�
�0I�0I�,J�K�������$�$��� ��	�	�	�s�D�D$c��|j|j|j�d��}|j�|j�|j�|j	t
|j�yr�)r<r0r�r�r�r�r�r�s  rr�z"TextIOWrapperTest.test_multi_close�
sS��� � ����d�m�m�!<�w� �O���	�	���	�	���	�	�����*�c�i�i�0r c��|j|j|j�d��}|j|j|j
�|j|j|jd�y)Nr	r-r)r<r�r�r�r�r`r]r�s  rrz!TextIOWrapperTest.test_unseekable�
s]��� � ��!6�!6�t�}�}�!E�PW� �X�����$�3�3�S�X�X�>����$�3�3�S�X�X�q�Ar c���|j|j|j�d��}|j|j�}|jt�5||_ddd�y#1swYyxYwr�)r<r0r�r�r�r�)r;rNrcs   rrz*TextIOWrapperTest.test_readonly_attributes�
s`��� � ����d�m�m�!<�w� �O���l�l�4�=�=�)��
�
�
�~�
.�	��C�J�	�	�	�s�A.�.A7c��|jgd��}|j|dd��}|j|jd�d�|j|j	�d�|jt|�dd	g�y)
N�r�r�sghi
jkl
opq
r:r
r=ri�abcdzefghi
zjkl
zopq
)rpr<r�rtrrB�r;r�rNs   r�
test_rawiozTextIOWrapperTest.test_rawio�
sq���n�n�A�B��� � ��w�� �E��������!��f�-���������3�����c��W�g�$6�7r c��|jgd��}|j|ddd��}|jd�|jd�|jd�|jd	j	|j
�d
�y)Nr�r:r
T)r.r>r�1z23
4�5r s123
45)rpr<rMr�r�rDr�s   r�test_rawio_write_throughz*TextIOWrapperTest.test_rawio_write_through�
sp���n�n�A�B��� � ��w��/3�!�5���	�	�#���	�	�'���	�	�#��������#�"2�"2�3�Z�@r c����ggc��G��fd�d|j�}|j�}d}||t|�dz�}|j|dd��}|j	d�}|j|�|j
��|j��|j|j�d�g�|j|d	z�|j��|j|j�|d
z�y)Nc�.���eZdZ��fd�Z��fd�Z�xZS)�BTextIOWrapperTest.test_bufio_write_through.<locals>.BufferedWriterc�D���jd�t�|�|i|��SrOr�)r;r�r�r��flush_calleds   ��rr�zHTextIOWrapperTest.test_bufio_write_through.<locals>.BufferedWriter.flush�
�%����#�#�D�)��w�}�d�5�f�5�5r c�D���jd�t�|�|i|��SrO)rKrrM)r;r�r�r��write_calleds   ��rrMzHTextIOWrapperTest.test_bufio_write_through.<locals>.BufferedWriter.write�
rr )r#r$r%r�rMr�)r�rrs@��rr,r��
s���
6�
6�
6r r,r8r~r:T)r.rr r�rj)
r,r0rr<r�rMr�r�r�r)	r;r,rrr�rBr�rrs	       @@r�test_bufio_write_throughz*TextIOWrapperTest.test_bufio_write_through�
s����&(��"��l�	6�T�0�0�	6���������u�c�$�i��k�2���#�#�E�G�26�$�8���{�{�7�#�����T��	
����&�����%�������)�3�/������T�B�Y������%�������)�4�"�9�5r c��|jg�}|j|dd��}|jd�|jd��|j	|j
d�|j	dj
|j�d�|jd	�|j	dj
|j�d
�|jd��|j	|j
d�|jd�|j�|j	dj
|j�d
�|j�|jd��|j	|j
d�|jd��|j�|jd��|j	|j
d�y)Nr:r
r=r�T�rr r��23r�F�45rD)	rpr<rMrr�rr�rDr�rs   r�test_reconfigure_write_throughz0TextIOWrapperTest.test_reconfigure_write_through�
sV���n�n�R� �����s�W�d��C��	�����	�
�
�D�
�)�������$�/�������#�"2�"2�3�T�:�	����
�������#�"2�"2�3�V�<�	�
�
�E�
�*�������%�0�	����
�	���	�������#�"2�"2�3�X�>�	�
�
��	�
�
�D�
�)�������%�0�	�
�
�D�
�)�	�
�
��	�
�
�D�
�)�������$�/r c��|j|jd�d��}|jt|jd�|j|jd�d��}|jt|j
�|j|jd�d��}|jt|j�y)Nr�r	r-r9)r<rJr�r�rtrr�s  r�test_read_nonbytesz$TextIOWrapperTest.test_read_nonbytess���
���t�}�}�S�1�G��D�����)�Q�V�V�Q�/����t�}�}�S�1�G��D�����)�Q�Z�Z�0����t�}�}�S�1�G��D�����)�Q�V�V�,r c��tjd�}tj|dd�5|j	|jd�d��}ddd�|j
tjd�y#1swY�+xYw)N�rot13�_is_text_encodingT�foor-r�)	r�r�rr�r<r0r�r�rM)r;r
rs   r�test_illegal_encoderz&TextIOWrapperTest.test_illegal_encodersr���
�
�g�&��
�
�
�u�&9�4�
@�	K��"�"�4�<�<��#7�'�"�J�A�	K����)�Q�W�W�e�4�	K�	K�s�#A:�:Bc�����fd����}�jt|jd���}�jt|j���}�jt|j��fd�}|d�}�jt|jd�|d�}�jt|jd�|d�}�jt|jd�y)Nc���tjd�}d|_	�j�j	d�dd��}d|_|S#d|_wxYw)N�quopriTsaaaaaar
r<F)r�r�rr<r0)rrr;s  �r�_make_illegal_wrapperzETextIOWrapperTest.test_illegal_decoder.<locals>._make_illegal_wrappers_����]�]�8�,�F�'+�F�$�
1��&�&�t�|�|�I�'>�/3�h�'�H��,1��(��H��,1��(�s�#A�	Ar9c�����G�fd�d���fd�}tjd�}tj|d|�5��cddd�S#1swYyxYw)Nc���eZdZ�fd�Zy)�^TextIOWrapperTest.test_illegal_decoder.<locals>._make_very_illegal_wrapper.<locals>.BadDecoderc����SrJr&)r;�getstate_ret_vals �rr�zgTextIOWrapperTest.test_illegal_decoder.<locals>._make_very_illegal_wrapper.<locals>.BadDecoder.getstate0s	���+�+r N)r#r$r%r�)rs�r�
BadDecoderr/s���,r rc�����SrJr&)r�rs �r�_get_bad_decoderzdTextIOWrapperTest.test_illegal_decoder.<locals>._make_very_illegal_wrapper.<locals>._get_bad_decoder2s���!�|�#r rr�)r�r�rr�)rrrrrs`  @�r�_make_very_illegal_wrapperzJTextIOWrapperTest.test_illegal_decoder.<locals>._make_very_illegal_wrapper.sQ���
,�
,�
$��]�]�8�,�F��"�"�6�+?�#3�5�
/�,�.�
/�
/�
/�s�A�ArTr&)r9r~)r�r�rtr)r;rrrs`  @r�test_illegal_decoderz&TextIOWrapperTest.test_illegal_decoders����	�
"�#�����)�Q�V�V�Q�/�!�#�����)�Q�Z�Z�0�!�#�����)�Q�V�V�,�
		/�
'�r�*�����)�Q�V�V�R�0�&�r�*�����)�Q�V�V�R�0�&�v�.�����)�Q�V�V�R�0r c�l�|jj}dj||��}td|�S)Na�if 1:
            import codecs
            import {iomod} as io

            # Avoid looking up codecs at shutdown
            codecs.lookup('utf-8')

            class C:
                def __init__(self):
                    self.buf = io.BytesIO()
                def __del__(self):
                    io.TextIOWrapper(self.buf, **{kwargs})
                    print("ok")
            c = C()
            )�iomodr��-c)r�r#r�r)r;r�r �codes    r�_check_create_at_shutdownz+TextIOWrapperTest._check_create_at_shutdown?s<����� � �����U�6��2�	
� ��d�+�+r c���|j�\}}}|r+|j|j|j��y|j	d|j�j��y)N�ok)r#r�shutdown_errorr�r��strip�r;�rc�outrs    r�(test_create_at_shutdown_without_encodingz:TextIOWrapperTest.test_create_at_shutdown_without_encodingTsT���5�5�7���C���
�M�M�$�-�-�s�z�z�|�<����T�3�:�:�<�#5�#5�#7�8r c��|jdd��\}}}|j|�|jd|j�j	��y)Nr	r�r�r%)r#r�r�r�r'r(s    r�%test_create_at_shutdown_with_encodingz7TextIOWrapperTest.test_create_at_shutdown_with_encoding]sP���5�5�w�=E�6�G���C�����������s�z�z�|�1�1�3�4r c���td�}|j|d�}t|j��j	�}|j|j
d�|jd��y)NsJust some random string
r	r�)�MemviewBytesIOr<�_to_memoryviewrr�r�rtr�)r;r+r�	bytes_vals    r�test_read_byteslikez%TextIOWrapperTest.test_read_byteslikecs]���7�8�����q�'�*��
$�A�J�J�L�1�9�9�;�	���������i�&6�&6�w�&?�@r c���Gd�dt�}td�D]}	|j|�d���d�|_|j|�d��}y#t$rY�JwxYw)Nc��eZdZd�Zd�Zd�Zy)�,TextIOWrapperTest.test_issue22849.<locals>.Fc��yrOr&r:s rrWz5TextIOWrapperTest.test_issue22849.<locals>.F.readablep���tr c��yrOr&r:s rrPz5TextIOWrapperTest.test_issue22849.<locals>.F.writableqr7r c��yrOr&r:s rrYz5TextIOWrapperTest.test_issue22849.<locals>.F.seekablerr7r N)r#r$r%rWrPrYr&r r�Fr5os��+�+�+r r:r�r	r-c��yrAr&�rs rr�z3TextIOWrapperTest.test_issue22849.<locals>.<lambda>zr�r )�objectr�r<rkr`)r;r:r�rs    r�test_issue22849z!TextIOWrapperTest.test_issue22849nsq��	,��	,�
�r��	�A�
��"�"�1�3��"�9�	�������q�s�W��5���	�
��
�s�A�	A&�%A&c�h�|j|jd��}|jd��y)N�testrr-)r<r0r)r;�wrappers  r�test_reconfigure_localez)TextIOWrapperTest.test_reconfigure_locale}s,���$�$�T�\�\�'�%:�;�����X��.r c���djd�djd�z}|j|�}|j|dd��}|j|j	�d�|j|j�5|jd��ddd�|j|j�5|jd�	�ddd�y#1swY�@xYw#1swYyxYw)
N�abcé
r��déf
�utf8r
r=r	r-�r>)r�r0r<r�rr�r�r)r;rr�rNs    r�test_reconfigure_encoding_readz0TextIOWrapperTest.test_reconfigure_encoding_read�s����!�!�(�+�j�.?�.?��.G�G���l�l�4� ��� � ��x�� �F����������5�
�
�
�t�8�8�
9�	.��O�O�W�O�-�	.�
�
�
�t�8�8�
9�	*��O�O�D�O�)�	*�	*�	.�	.��	*�	*�s�C�:C"�C�"C+c��|j�}|j|dd��}|jd�|jd��|jd�|j	�|j|j
�d�y)	Nr:r
r=�foo
r�r-r�sfoo
é
)r0r<rMrr�r�rr�s   r� test_reconfigure_write_fromasciiz2TextIOWrapperTest.test_reconfigure_write_fromascii�sl���l�l�n��� � ��w�� �E���	�	�'�������-��	�	�(���	�	���������);�<r c�d�|j�}|j|dd��}|jd�|jd��|j	|j�d�|jd�|j
�|j	|j�d	�|j�}|j|d
d��}|jd�|jd��|jd�|j
�|j	|j�d
�y)Nr�r
r=rDr	r-sabc�
rEs
abc�
déf
r:�abc
r�s	abc
déf
)r0r<rMrr�rr�r�s   r�test_reconfigure_writez(TextIOWrapperTest.test_reconfigure_write�s����l�l�n��� � ��x�� �F���	�	�+�������)���������6��	�	�*���	�	���������)A�B��l�l�n��� � ��w�� �E���	�	�'�������-��	�	�*���	�	���������)=�>r c�2�|j�}d�|_d|_|j|dd��}|j	d�|jd��|j	d�|j
�|j|j�d	�y)
Nc��yr�r&r&r rr�zGTextIOWrapperTest.test_reconfigure_write_non_seekable.<locals>.<lambda>�r�r r:r
r=rMr�r-rEsabc
déf
)	r0rYr]r<rMrr�r�rr�s   r�#test_reconfigure_write_non_seekablez5TextIOWrapperTest.test_reconfigure_write_non_seekable�sz���l�l�n��$������� � ��w�� �E���	�	�'�������-��	�	�*���	�	��	
�������*J�Kr c�d�|j|j�ddd�}|jd��|j|jd�|j|j
d�|j
d�|jd��|j|jd�|j|j
d�|jd�	�|j|jd�|j|j
d�|j
d
�|jdd��|j|j
d
�|jd�|j|j�d�|j|j�j�d�y)Nr:r*r
r-�LF
r�rGrX�rm�CRLF
r	r=r�rzLF
CRLF
s	LF
CRLF
)r<r0rr�r.rmrMr]rtr�rr�s  r�test_reconfigure_defaultsz+TextIOWrapperTest.test_reconfigure_defaults�s<��� � ������)�T�J�������&�������w�/�������Y�/��	�	�&�������'�������w�/�������Y�/����x��(�������w�/�������X�.��	�	�(������$��7�������X�.�������������\�2��������.�.�0�/�Br c�	�|j|j�ddd�}|jt�5|j	d��ddd�|j
r`|jt�5|j	d��ddd�|jt�5|j	d��ddd�|jt�5|j	d��ddd�|j
r0|jt�5|j	d��ddd�|jt�5|j	d�	�ddd�|jt�5|j	d�	�ddd�|jt�5|j	d
�	�ddd�|j
s0|jt�5|j	d�	�ddd�|j
�r|jt�5|j	t���ddd�|jt�5|j	d
dz��ddd�|jt�5|j	t���ddd�|jt�5|j	d
dz��ddd�|jt�5|j	t�t���ddd�|j|jd�|j|jd�|j|j d�|j|j"d�|j	ddddd��|j|jd�|j|jd�|j|j d�|j|j"d�y#1swY���xYw#1swY���xYw#1swY��wxYw#1swY��TxYw#1swY��%xYw#1swY��xYw#1swY���xYw#1swY���xYw#1swY���xYw#1swY��UxYw#1swY��/xYw#1swY��xYw#1swY���xYw#1swY���xYw)Nr:r*r5rTr-r�zlocalerTrG�xyzr�rr~rgr)r�rFr�rXr�T)r.rmr>r�r)r<r0r�r�rr�r�rr�r�r6rr�r.rmr�r�rr�s  r�test_reconfigure_errorsz)TextIOWrapperTest.test_reconfigure_errors�s���� � ������)�T�J��
�
�
�y�
)�	)��O�O�R�O�(�	)��9�9��"�"�#5�6�
3������2�
3��"�"�;�/�
5������4�
5��
�
�y�
)�	'��O�O�2�O�&�	'��9�9��"�"�#5�6�
1����x��0�
1��
�
�y�
)�	(��O�O�B�O�'�	(�
�
�
�z�
*�	.��O�O�H�O�-�	.�
�
�
�z�
*�	+��O�O�E�O�*�	+��y�y��"�"�:�.�
0������/�
0��9�9��"�"�#4�5�
;����x�z��:�
;��"�"�=�1�
8����q�$�w��7�
8��"�"�#4�5�
:����h�j��9�
:��"�"�=�1�
7����a��g��6�
7��"�"�#4�5�
:����x�z�.6�j� �:�
:�	
������w�/�������Y�/��
�
�c�(�(�%�0��
�
�c�'�'��/�����(�F�'+�4�	�	A�������x�0�������X�.��
�
�c�(�(�$�/��
�
�c�'�'��.�c	)�	)��
3�
3��
5�
5��	'�	'��
1�
1��	(�	(��	.�	.��	+�	+��
0�
0��
;�
;��
8�
8��
:�
:��
7�
7��
:�
:�s��P�4P�$P,�P9�Q�Q�0Q � Q-�Q:�R�R�R!�<R.�/$R;�P�P)�,P6�9Q�Q�Q� Q*�-Q7�:R�R�R�!R+�.R8�;Sc��|jd�}|j|dd��}|jd��|j|j	�d�|jd�}|j|dd��}|jd��|j|j	�d�|jd�}|j|dd	��}|jd��|j|j	�d
�|jd�}|j|dd��}|jd	��|j|j	�d�|jd
�}|j|dd	��}|jd��|j|j	�d�|j|j�dd	��}|jd��|jd�|jd��|jd�|jd��|jd�|jd	��|jd�|jd��|jd�dtjzdz}|j|j�j�jd�|�y)NsCR
EOFr:r
rGzCR
r�zCR
s	CR
LF
EOFr5zCR
LF
s	LF
CR
EOFzLF
CR
sCR
CRLF
EOFr�z	CR
CRLF
zlinesep
rSrUrQzLF
LF
CR
CRLF
)r0r<rr�rrMrrQr�rr�)r;r�rNr�s    r�test_reconfigure_newlinez*TextIOWrapperTest.test_reconfigure_newlinesM���l�l�:�&��� � ��g�t� �<�������%���������0��l�l�:�&��� � ��g�t� �<�������#���������0��l�l�>�*��� � ��g�t� �<�������%���������4��l�l�>�*��� � ��g�t� �<�������%���������4��l�l�-�.��� � ��g�t� �<�������'���������8�� � ������$� �G�������%��	�	�+�������#��	�	�&�������%��	�	�&�������%��	�	�&�������'��	�	�(���r�z�z�)�,B�B���������.�.�0�7�7��@�(�Kr c�R�|j|jd�d��}|jd�|j�|j�|j|jd�d��}|jd�|j	d�|j�y)Nr@r:r-r9r)r<r0rtr`rMr�s  r�test_issue25862z!TextIOWrapperTest.test_issue25862+sz�����t�|�|�G�4�w��G��	���q�	�	����	�������t�|�|�G�4�w��G��	���q�	�	�����	���r c�0�|j|jd�|j��}|j|�}|j�}|j	|d�|j|�|j	||j�zd�y)Nsfoo
bar
rJzfoo
bar
)r3r0r<rr�rM)r;�pr2r�s    r�test_issue35928z!TextIOWrapperTest.test_issue359286st��������]� ;�T�\�\�^�L�����q�!���j�j�l������g�&�	���������q�z�z�|�+�\�:r N)Wr#r$r%r�r�r.r3rr�r�r�rrr|r}rPr�	utf8_moder$r(r,r/rGrOrTr�r�r�rrrnrr�r�rkr�r�r�r�r�rSr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�
no_tracingr
r�r�r�rrr�rrr�r�rr	rrrr#r+r-r2r>rBrHrKrNrQrVrYr[r]r`r&r rr�r��
s���>�+�!=�F	(�2�*�(�(�	5�1�6�X�_�_�S�Y�Y�(�(�*A�B�+�C�+�(	"�4�$5�0(I�T<� 7�$&�,�.B��:)�,�(5�"	�-8�^
��J�(-�*�=�	/�4�4�=�
1�
1�	1�1�/�<�
E�
E�E�2�
���0��0�0�2�G�3��G�"!�"!�(!�*1�B�
�	8�A�6�@0�.-�5�&1�P,�*9�5�	A�
6�/�
*�
=�?�*L�C�.3/�j"L�H	�;r r�c�,��eZdZdZ�fd�Z�fd�Z�xZS)r/zOA BytesIO object whose read method returns memoryviews
       rather than bytesc�4��tt�|�	|��SrJ)r0rrG�r;�len_r�s  �rrGzMemviewBytesIO.read1Cs����e�g�m�D�1�2�2r c�4��tt�|�	|��SrJ)r0rrtres  �rrtzMemviewBytesIO.readFs����e�g�l�4�0�1�1r )r#r$r%rirGrtr�r�s@rr/r/?s����3�2�2r r/c��tjd�}t|�t|�|jzz
}|j|d|�t	|�S)z6Convert bytes-object *buf* to a non-trivial memoryviewr�N)r)r�itemsize�	frombytesr)rc�arr�idxs   rr0r0IsI���+�+�c�
�C�

�c�(�S��X����,�
,�C��M�M�#�d�s�)���c�?�r c�2�eZdZeZdZd�Zd�Zd�Zd�Zd�Z	y)�CTextIOWrapperTest�$LookupError: unknown encoding: asciic�x�|jd�}|j|d�}|j|d��}|jt|j
|dd��|jt|j�|jj|j�}|jtt|�y)Nr�rgr	r-r�r=)
r0r(r<r�r�rHrtr2rkr�rs    rr�z&CTextIOWrapperTest.test_initializationVs����L�L��)������4�(�����q�7��3�����*�a�j�j�!�g�w��W����*�a�f�f�-����&�&�t�'9�'9�:�����)�T�1�-r c�H�tjdtf�5|jtj
d�}|j
|�}|j|d��}|jd�||_	tj|�}~tj�ddd�|j�|�|jtj
d�5}|j!|j#�d�ddd�y#1swY�jxYw#1swYyxYw)Nr�r
r:r-�456defr
s456def)rr�r�rrr�r,r<rMrr�r�rr�r�r/r�rt)r;rr(rr�r2s      rr�z*CTextIOWrapperTest.test_garbage_collection`s����
+�
+�R��,A�
B�	!��K�K�	� 0� 0�$�7�E��#�#�E�*�A��"�"�1�w�"�7�A�
�G�G�H���A�C����Q��B����� �	!�	
���"�$��#�
�Y�Y�y�'�'��
.�	2�!����Q�V�V�X�y�1�	2�	2�	!�	!��	2�	2�s�BD�"!D�D�D!c�l�td�D]�}|j|j�|j��}|j|d��}|j|j�|j��}|j|d��}||_||_��tj�y)Nrgr:r-)r�r3rpr<�buddyrr�)r;r��b1�t1�b2�t2s      r�!test_rwpair_cleared_before_textioz4CTextIOWrapperTest.test_rwpair_cleared_before_textioqs����t��	�A��$�$�T�^�^�%5�t�~�~�7G�H�B��#�#�B��#�9�B��$�$�T�^�^�%5�t�~�~�7G�H�B��#�#�B��#�9�B��B�H��B�H�	�	���r c��|j|j�d��}|jt�5|`ddd�y#1swYyxYwr�)r<r0r�r�r1r�s  r� test_del__CHUNK_SIZE_SystemErrorz3CTextIOWrapperTest.test_del__CHUNK_SIZE_SystemErrorsE�����t�|�|�~���@��
�
�
�~�
.�	��
�	�	�	�s�A�Ac�J��d�G�fd�d|j�}|�}|j|d��}|j�|jd�|jd�|j	g|j
�|j
t�5|jd�d	zz�ddd�|j	d
g|j
�|jd�|jd�z�|j	d
dd
�zg|j
�y#1swY�nxYw)Nrc�"���eZdZ��fd�Z�xZS)�<CTextIOWrapperTest.test_internal_buffer_size.<locals>.MockIOc�J��t|��kDrt�t�|�
|�SrJ)rr�rrM)r;rr�r�s  ��rrMzBCTextIOWrapperTest.test_internal_buffer_size.<locals>.MockIO.write�s$����t�9�z�)�&�&��w�}�T�*�*r )r#r$r%rMr�)r�r�s@�r�MockIOr~�s
���
+�
+r r�r:r-r�rlrr9r��ghir�r�)rpr<r1rMr�rDr�r�)r;r�rcrr�s    @r�test_internal_buffer_sizez,CTextIOWrapperTest.test_internal_buffer_size�s�����
�	+�T�^�^�	+��h�����s�W��5���]�]�
�	�����	���������S�-�-�.�
�
�
�|�
,�	(�
�G�G�C��A��&�'�	(�	
���)��c�&6�&6�7�	�����	����J������)�V�T�*�_�=�s�?O�?O�P�
	(�	(�s�D�D"N)
r#r$r%r�r&r�r�ryr{r�r&r rrnrnRs&��	�B�;�N�.�2�"��
Qr rnc��eZdZeZdZy)�PyTextIOWrapperTestroN)r#r$r%r�r�r&r&r rr�r��s��	
�B�;�Nr r�c�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�IncrementalNewlineDecoderTestc� �����fd�}|dd�|dd�|dd�|dd�|dd�|dd�|dd�|dd��jt�jdd	�
��j�|dd�|d
d�|ddd	�
�|d
dd	�
�|d
d�|dd�|dd�|d
d�|d
d�|dd�|dd�|dd�|dd�|dd�|dd�y)Nc�����j�}�j�j|fi|��|��j|��j�j|fi|��|�yrJ)r�r�r�r�)r(r�r�r��decoderr;s    ��r�
_check_decodezPIncrementalNewlineDecoderTest.check_newline_decoding_utf8.<locals>._check_decode�s_����$�$�&�E����^�W�^�^�A�8��8�!�<����U�#����^�W�^�^�A�8��8�!�<r s袈u袈��r�����r T)r�r�r
rIr8z
a�

z

s
as袈
r�s袈
)r��UnicodeDecodeErrorr�r�)r;r�r�s`` r�check_newline_decoding_utf8z9IncrementalNewlineDecoderTest.check_newline_decoding_utf8�s���	=�	�o�x�0��g�r�"��g�r�"��g�x�(��g�r�"��g�r�"��g�x�(��g�r�"����,�g�n�n�c���N��
�
���e�T�"��e�R� ��c�4�t�,��e�T��.��e�R� ��d�E�"��i��(��e�R� ��e�T�"��f�e�$��)�:�6��o�x�0��e�T�"��'��2��e�T�"r c������g�|�"tj|������fd�}nd���fd�}|j�jd�|d�|j�jd�|d�|j�jd�|d�|j�jd�|d�|j�jd	�|d�|jd
j	��d��j�d}��!�j��j
|�}|j�j|�d�|j�jd�y)Nc����j|�D],}�j�jt|g����.yrJ)r�rKr�r)r�r(r��encoderrds  ���r�_decode_bytewisezNIncrementalNewlineDecoderTest.check_newline_decoding.<locals>._decode_bytewise�s6��� ����*�>�A��M�M�'�.�.���s��"<�=�>r c�T��|D]"}�j�j|���$yrJ)rKr�)r�ryr�rds  ��rr�zNIncrementalNewlineDecoderTest.check_newline_decoding.<locals>._decode_bytewise�s'����5�A��M�M�'�.�.��"3�4�5r zabc

r
z
abc)r
r�zabc
r�)r5r
r�r�zabc

abcabc
abcabc)r��getincrementalencoderr��newlinesr�r�r�r�)r;r�r.r�r�r�rds `   @@r�check_newline_decodingz4IncrementalNewlineDecoderTest.check_newline_decoding�s@�������<�f�2�2�8�<�>�G�
>�
�G�
5�	
����)�)�4�0���#�����)�)�4�0���!�����)�)�>�:���!�����)�)�>�:��������)�)�+?�@���!���������*A�B��
�
�������M�M�O��N�N�5�)�E��������.��6�����)�)�4�0r c�Z�d}|D]E}|xrtj|��}|j|d��}|j||��Gtjd��}|j|d��}|j	|�|jt|jd�y)N)	Nr	r,r6r7r8r9r:r;T��	translater	rT)r��getincrementaldecoderr�r�r�r�r�r�)r;r?rpr�s    r�test_newline_decoderz2IncrementalNewlineDecoderTest.test_newline_decoder�s���
�	��	6�C��A�?�f�:�:�3�?�A�G��4�4�W��4�M�G��'�'���5�	6�8�&�.�.�w�7�9���0�0��D�0�I���(�(��1����)�W�%5�%5�r�:r c�|���fd�}�jdd��}||��jdd��}||�y)Nc�2���j|jd��j|jd�d��j|jd��j|jd�d��j|jd�y)Nuഀu਀)r�r�r�)�decr;s �r�_checkz@IncrementalNewlineDecoderTest.test_newline_bytes.<locals>._checksq������S�\�\�4�0����S�Z�Z��1�8�<����S�\�\�4�0����S�Z�Z��1�8�<����S�\�\�4�0r Fr�T)r�)r;r�r�s`  r�test_newline_bytesz0IncrementalNewlineDecoderTest.test_newline_bytessB���	1��,�,�T�U�,�C���s���,�,�T�T�,�B���s�r c�(�dD]?}tjd��}|j||�}|j|��Atjd��}|j|d��}|j	|jd�d�y)N)r&r�r9r~r	rr�r�z

)r�r�r�r�r�r�)r;r�r�s   r�test_translatez,IncrementalNewlineDecoderTest.test_translates���'�	6�I�;�f�2�2�7�;�=�G��4�4�W�i�H�G��,�,�W�5�	6�8�&�.�.�w�7�9���0�0��A�0�F��������	�2�H�=r N)r#r$r%r�r�r�r�r�r&r rr�r��s��(#�T1�B;�"�>r r�c�0�eZdZejd��Zy)�CIncrementalNewlineDecoderTestc�R�|jj|j�}|jt|jd�|jt|j
�|jt|jd�|jt|j�y)N�bar)rr)r�r2r�r�r�r�r�r�)r;�
uninitializeds  rr3z1CIncrementalNewlineDecoderTest.test_uninitializeds}���6�6�>�>��*�*�,�
����*�m�&:�&:�F�C����*�m�&<�&<�=����*�m�&<�&<�k�J����*�m�&9�&9�:r N)r#r$r%rr'r3r&r rr�r�s�����;��;r r�c��eZdZy)�PyIncrementalNewlineDecoderTestNr"r&r rr�r�%rlr r�c�V�eZdZdZdZdZd�Zd�Zd�Zd�Z	e
jejd�e
jeed�d	�d
���Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Ze
jeed�d	�d��Zd�Ze
jejd�d��Ze
jejd�d��Ze
jeed�d�e
jeed�d	�d���Zd�Z d�Z!d�Z"d�Z#d�Z$d �Z%y)!�
MiscIOTestNr&c�J�tjtj�yrJr�r:s rr�zMiscIOTest.tearDown2r�r c��tj||j|j|j|j
��y)N)�extra�not_exported)r�check__all__r��name_of_module�extra_exportedr�r:s r�test___all__zMiscIOTest.test___all__5s2�����T�4�7�7�D�,?�,?�#'�#6�#6�*.�*;�*;�	=r c��|jtjdd��}|j|jd�|j�|jtjdd��}|j|jd�|j|jjd�|j|jjjd�|j|j�dd�	�}|j|jd�|j|jjd�|j|j|j��|j|jj|j��|j�|j�y)
Nr
rrrjr	r-r^Fr�)
r/rr�r�rr�r�r�rUr+)r;r2�gs   r�test_attributeszMiscIOTest.test_attributes:s-���I�I�i�&�&���I�:���������&�	���	��I�I�i�&�&��w�I�?��������D�1���������E�2���������*�*�E�2��I�I�a�h�h�j�$��I�6��������T�*���������T�*�������Q�X�X�Z�0���������Q�X�X�Z�0�	���	�	���	r c���dD]e}|jt�5}|jtj|�ddd�|jdt
j���gy#1swY�1xYw)N)�U�rUzr+Uzinvalid mode)r�r�r/rr�rrr)r;rr s   r�test_removed_u_modezMiscIOTest.test_removed_u_modeLsa��&�	=�D��"�"�:�.�
2�"��	�	�)�*�*�D�1�
2��M�M�.�#�b�l�l�*;�<�	=�
2�
2�s�!A,�,A5	rrrc�6�tj�\}}|jtj|�|j	|dd��}|j|j�t
jdk7r |j|j��yy)Nr�r	r-r�)	rrr"r�r/rPrQr�rY)r;r+rr2s    r�test_open_pipe_with_appendz%MiscIOTest.test_open_pipe_with_appendSsp���w�w�y���1�������!�$��I�I�a��w�I�/�������� ��<�<�7�"����Q�Z�Z�\�*�#r c��ddiddiddd�ddd�ddd�ddidd	iddd�ddd�d	dd�dd
iddid
dd�d
dd�ddd�fD�]}d|dvrd
|d<|jtjfi|��}|j�|j	t
|j�|j	t
|j�|j	t
|j�|j	t
|j�t|d�r!|j	t
|jd�|j	t
|j�t|d�rA|j	t
|jd�|j	t
|j�t|d�r |j	t
|j�t|d�r*|j	t
|jt!d��t|d�r*|j	t
|j"t!d��|j	t
|j$�|j	t
|j&�|j	t
|j&d�|j	t
|j(d�|j	t
|j*�|j	t
|j,�|j	t
|j.d|dvrdnd�|j	t
|j0g�|j	t
t2|���y)Nrrr
r9�rrr~rr+r
rjr�r(r	r.rDrGr+r[rfr�r r�)r/rr�r�r�r�r�rUrQ�__iter__rrDrtrGr[rfr�r�rr|r]r`rhrMrrt)r;r�r2s   r�test_io_after_closezMiscIOTest.test_io_after_closebs�����
�����1�-��1�-��A�.���
�����1�-��1�-��A�.��������A�.��A�.��Q�/��.	3�F�"�&��.�(�%,��z�"���	�	�)�*�*�5�f�5�A�
�G�G�I����j�!�'�'�2����j�!�(�(�3����j�!�(�(�3����j�!�*�*�5��q�&�!��!�!�*�a�f�f�a�8����j�!�&�&�1��q�'�"��!�!�*�a�g�g�t�<��!�!�*�a�g�g�6��q�)�$��!�!�*�a�i�i�8��q�*�%��!�!�*�a�j�j�)�D�/�J��q�+�&��!�!�*�a�k�k�9�T�?�K����j�!�*�*�5����j�!�+�+�6����j�!�+�+�q�9����j�!�&�&�!�4����j�!�&�&�1����j�!�*�*�5����j�!�'�'�%(�F�6�N�%:�c��
D����j�!�,�,��;����j�$��2�].	3r c��Gd�dt�}|d�}|jd|�}||_||_t	j
|�}~~t
j�|j|�|�y)Nc��eZdZy)�*MiscIOTest.test_blockingioerror.<locals>.CNr"r&r r�Cr��s��r r�r�r9)	rr�r(ryr�r�rr�r�)r;r�ryr(r�s     r�test_blockingioerrorzMiscIOTest.test_blockingioerror�sg��	��	�
�b�E��� � ��A�&��������
�[�[��^��
�q��������"�$��#r c�T�|j|jtj�|j|jtj�|j|j
tj�|j|jtj�yrJ)rrrr��ABCMetarNr8rMr:s r�	test_abcszMiscIOTest.test_abcs�sd�����d�k�k�3�;�;�7����d�n�n�c�k�k�:����d�1�1�3�;�;�?����d�o�o�s�{�{�;r c���|jtjdd��5}|j||j�|j||j
�|j
||j�|j
||j�ddd�|jtjd�5}|j||j�|j
||j
�|j||j�|j
||j�ddd�|jtjdd��5}|j||j�|j
||j
�|j
||j�|j||j�ddd�y#1swY��?xYw#1swY��xYw#1swYyxYw�Nr
rrrr	r-)	r/rr�rrrrN�assertNotIsInstancer8rM)r;�	abcmoduler2s   r�_check_abc_inheritancez!MiscIOTest._check_abc_inheritance�s���
�Y�Y�y�'�'���Y�
;�	>�q��!�!�!�Y�%5�%5�6��!�!�!�Y�%8�%8�9��$�$�Q�	�(@�(@�A��$�$�Q�	�(<�(<�=�		>�
�Y�Y�y�'�'��
.�	>�!��!�!�!�Y�%5�%5�6��$�$�Q�	�(;�(;�<��!�!�!�Y�%=�%=�>��$�$�Q�	�(<�(<�=�		>�
�Y�Y�y�'�'��w�Y�
?�	;�1��!�!�!�Y�%5�%5�6��$�$�Q�	�(;�(;�<��$�$�Q�	�(@�(@�A��!�!�!�Y�%9�%9�:�		;�	;�	>�	>��
	>�	>��
	;�	;�s&�A1G�<A1G�A1G*�G�G'�*G3c�&�|j|�yrJ)r�r:s r�test_abc_inheritancezMiscIOTest.test_abc_inheritance�s���#�#�D�)r c�.�|jt�yrJ)r�r�r:s r�test_abc_inheritance_officialz(MiscIOTest.test_abc_inheritance_official�s��	
�#�#�B�'r c��t|i|��}t|�}|jt�5}d}t	j
�ddd�|j
|tjjd��y#1swY�<xYwrA)
r/r��assertWarnsr�rr�rr�warningr�)r;r�r�r2r+r s      r�_check_warn_on_deallocz!MiscIOTest._check_warn_on_dealloc�sr���$�!�&�!����G��
�
�
�o�
.�	!�"��A���� �	!�	
�
�
�a��R�Z�Z�_�_�Q�/�0�1�	!�	!�s�A>�>Bc���|jtjdd��|jtjd�|jtjdd��yr�)r�rr�r:s r�test_warn_on_dealloczMiscIOTest.test_warn_on_dealloc�sN���#�#�I�$4�$4�d�a�#�H��#�#�I�$4�$4�d�;��#�#�I�$4�$4�c�G�#�Lr c�P��g��fd�}|j|�tj�\}}�||fz
�|j|g|��i|��tj�\}}�||fz
�t	j
|�5t
|g|��ddi|��ddd�y#1swYyxYw)Nc����D]}	tj|��y#t$r(}|jtjk7r�Yd}~�Hd}~wwxYwrJ)rr�r�r-r.)r�rl�fdss  �r�cleanup_fdsz9MiscIOTest._check_warn_on_dealloc_fd.<locals>.cleanup_fds�sL����
����H�H�R�L�
�����w�w�%�+�+�-��.���s� �	A�A�Ar�F)r"rrr�rr8r/)r;r�r�r�r+rr�s      @r�_check_warn_on_dealloc_fdz$MiscIOTest._check_warn_on_dealloc_fd�s������	�	
����$��w�w�y���1��q�!�t���#��#�#�A�7��7��7��w�w�y���1��q�!�t���
�
6�
6�t�
<�	4���3�T�3�5�3�F�3�	4�	4�	4�s�B�B%c�r�|jdd��|jd�|jdd��y)Nr
rrr+r	r-)r�r:s r�test_warn_on_dealloc_fdz"MiscIOTest.test_warn_on_dealloc_fd�s6���&�&�t�q�&�9��&�&�t�,��&�&�s�W�&�=r c���d}ddiddiddd�ddiddiddd�dd	idd
id
dd�f	D]�}d|dvrd|d
<ttjdz�D]}}|j||��5|jt
jfi|��5}|jt|�5tj||�ddd�ddd�ddd����y#1swY�xYw#1swY�"xYw#1swY��xYw)Nz
cannot picklerrr
rr�r+r
rjr�r(r	r.r9)�protocolr�)
r��pickle�HIGHEST_PROTOCOLrKr/rr�rTr��dumps)r;r�r�r�r2s     r�
test_picklingzMiscIOTest.test_pickling�s������
�����A�.���
�����A�.��������Q�/�
�	6�F��&��.�(�%,��z�"�!�&�"9�"9�A�"=�>�
6���\�\�8�F�\�C�6�"����9�#3�#3�>�v�>�6�!�!�3�3�I�s�C�6�"�L�L��H�5�6�6�6�6�
6�	6� 6�6��6�6��6�6�s<�$"C)�C	�C�4C	�<C)�C�C	�C&
�"C)�)C2c�&�|jd�y)Ni@��_test_nonblock_pipe_writer:s r�test_nonblock_pipe_write_bigbufz*MiscIOTest.test_nonblock_pipe_write_bigbuf�s��	
�&�&�w�/r c�&�|jd�y)Nr+r�r:s r�!test_nonblock_pipe_write_smallbufz,MiscIOTest.test_nonblock_pipe_write_smallbufs��	
�&�&�t�,r �set_blockingz(os.set_blocking() required for this testc���g}g}tj�\}}tj|d�tj|d�|j|dd|��}|j|dd|��}|5|5dD]B}	d}		t	|	dzd	zg�|z}
|j|
�|j
|
�|	d
z
}	�=		|j�	|t|jd�z
}ddd�ddd�dj!|�dj!|�}}|j||�|j#|j$�|j#|j$�y#|j$r�}|j|jdtj�|j|jd|j�|dd|j|d<|j|j��d
}
|j
|
�|j|
�Yd}~���d}~wwxYw#|j$r�}|j|jdtj�|j|jd|j�|j|jd�|j|j��Yd}~nd}~wwxYw�� #1swY���xYw#1swY���xYw)NFr
T)rr�rr
)ru�Ii�r��ar9r~r�sBLOCKEDr )rrr�r/rrKrMr�r�r�r-�EAGAINr�rtr��iterr�r�r�)r;r��sent�receivedr+r�rf�wfrvr�r�rls            rr�z$MiscIOTest._test_nonblock_pipe_write
s��������w�w�y���1�
����5�!�
����5�!��Y�Y�q�t�T�W�Y�
E��
�Y�Y�q�t�T�W�Y�
E��
�	,��	,�#�
%��%��A��#�Q��V�b�[�M�2�Q�6�����C�(�����
��Q���	�
%�$�/��H�H�J��
��R�W�W�d�+�+�H�;	,�	,�>���$�����(�);�h������x�(�����	�	�"�����	�	�"��1�+�+�%��$�$�Q�V�V�A�Y����=��$�$�Q�V�V�A�Y��0D�0D�E�#�B�x�(=��)=�)=�>�D��H��O�O�B�G�G�I�.�$�C��H�H�S�M��K�K��$�$��%���+�+�/��$�$�Q�V�V�A�Y����=��$�$�Q�V�V�A�Y��0D�0D�E��$�$�Q�%9�%9�1�=��O�O�B�G�G�I�.�.��	/��	�'	,�	,��	,�	,�s{�4K-�7K �>AE&�>K �H1�K �+K-�&H.	�5B.H)	�#K �)H.	�.K �1K�BK�K �K�K � K*	�%K-�-K7c���|jtjdd��5	ddd�|jt|jtjdd��y#1swY�<xYw)Nrr	r-r)r/rr�r��FileExistsErrorr:s r�test_create_failzMiscIOTest.test_create_fail?sV��
�Y�Y�y�'�'��w�Y�
?�	��	����/�4�9�9�i�6F�6F��V]��^�	�	�s�A � A)c�:�|jtjd�5}|jd�ddd�|jtjd�5}|j	d|j��ddd�y#1swY�SxYw#1swYyxYw)N�xbr�r
r�rs  r�test_create_writeszMiscIOTest.test_create_writesEs��
�Y�Y�y�'�'��
.�	�!�
�G�G�G��	�
�Y�Y�y�'�'��
.�	0�!����W�a�f�f�h�/�	0�	0�	�	��	0�	0�r�c�h�|jt|jtjdd��y)Nzrwax+r	r-r�r:s r�test_open_allargszMiscIOTest.test_open_allargsLs&�����*�d�i�i��1A�1A�7�U\��]r c���|jj}t}d}tjd|�d|�d|�d|�d|�d|�d|�d	|�d
��}tddd
|�}|j
|jd|�y)NzBoom, Shaka Laka, Boom!z)
            import sys
            from zC import open, TextIOWrapper

            try:
                open(z, encoding=z�)
            except LookupError:
                pass
            else:
                sys.exit(21)

            try:
                open(z	, errors=z})
            except LookupError:
                pass
            else:
                sys.exit(22)

            fp = open(za, "rb")
            with fp:
                try:
                    TextIOWrapper(fp, encoding=z�)
                except LookupError:
                    pass
                else:
                    sys.exit(23)

                try:
                    TextIOWrapper(fp, errors=z�)
                except LookupError:
                    pass
                else:
                    sys.exit(24)

            sys.exit(10)
        �-X�devr!r�)r�r#r0�textwrap�dedentr	r�r))r;�modr�r<r"�procs      r�test_check_encoding_errorsz%MiscIOTest.test_check_encoding_errorsPs����g�g������+�����$�����\��W�K�8��\��7�+�6� �l�#0�18�{�;.�/6�[�9	�9# �#
��H%�T�5�$��=��������"�d�+r c	��|jj}t}tjd|�d|�d|�d��}tddd|�}|jj�}|jt|�d�|j|d	jd
��|j|djd��y)
Nz(            import sys
            from zN import open, TextIOWrapper
            import pathlib

            with open(zJ) as f:           # line 5
                pass

            pathlib.Path(z ).read_text()  # line 8
        r�warn_default_encodingr!r~rs<string>:5: EncodingWarning: r9s<string>:8: EncodingWarning: )r�r#r0rrrrrMr�rr�rR)r;rr�r"rrYs      r�test_check_encoding_warningz&MiscIOTest.test_check_encoding_warning}s����g�g���������$���� �l�#�#��&	�	 �	
�� ��&=�t�T�J���8�8�&�&�(������X���*�����Q�K�"�"�#C�D�	F�����Q�K�"�"�#C�D�	Fr c���d}tddd|�}|jd|jj��tddd|�}|jd|jj��y)Nz(import io; print(io.text_encoding(None))rzutf8=0r!slocalezutf8=1sutf-8)rr�r*r')r;r"rs   r�test_text_encodingzMiscIOTest.test_text_encoding�s_��:����h��d�;������D�H�H�N�N�$4�5���h��d�;������4�8�8�>�>�#3�4r )&r#r$r%r�r�r�r�r�r�r�r|r}rr~rrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr
rr&r rr�r�+s����N��N��L�+�=�
�$=��X�_�_����F���X�����V�,�.B�C�	+�D��	+�/3�b$�<�;�"*�(�
2�M�
4�&�X�����V�,�.B�C�>�D�>�6�,�X�_�_����F��0��0��X�_�_����F��-��-��X�����^�4�C�E��X�����V�,�.B�C�0#�D�E�0#�d_�0�^�+,�ZF�.	5r r�c���eZdZeZdZdZd�Zd�Zej�e
jd�d���Zej�e
jd�d���Z
y)	�CMiscIOTest)r�r�)r�c��Gd�d|jj�}|�}td�}|jt|j
|�y)Nc��eZdZdd�Zy)�<CMiscIOTest.test_readinto_buffer_overflow.<locals>.BadReaderc��ddzS)Nr�i@Br&rss  rrtzACMiscIOTest.test_readinto_buffer_overflow.<locals>.BadReader.read�s���e�|�#r Nrxrur&r r�	BadReaderr�s��
$r rr~)r�r8r�r�r�rf)r;rr�r(s    r�test_readinto_buffer_overflowz)CMiscIOTest.test_readinto_buffer_overflow�s@��	$����.�.�	$�����a�L�����*�e�n�n�a�8r c�>�djt��}td|�\}}|jj	�}|j
dk7r,djt��}|j
||�y|j|jd��y)Na�if 1:
            import sys
            import time
            import threading
            from test.support import SuppressCrashReport

            file = sys.{stream_name}

            def run():
                while True:
                    file.write('.')
                    file.flush()

            crash = SuppressCrashReport()
            crash.__enter__()
            # don't call __exit__(): the crash occurs at Python shutdown

            thread = threading.Thread(target=run)
            thread.daemon = True
            thread.start()

            time.sleep(0.5)
            file.write('!')
            file.flush()
            r!rz�Fatal Python error: _enter_buffered_busy: could not acquire lock for <(_io\.)?BufferedWriter name='<{stream_name}>'> at interpreter shutdown, possibly due to daemon threadsz.!)	�
format_map�localsr
rr�r)r�r�r')r;�stream_namer"r�r�r�patterns       r�&check_daemon_threads_shutdown_deadlockz2CMiscIOTest.check_daemon_threads_shutdown_deadlock�s����0�
�6�8�$�1	
�2&�d�D�1���Q��g�g�n�n����6�6�Q�;�)�*4��F�H�)=�	
�

���S�'�*����S�Y�Y�t�_�-r �walltimec�&�|jd�y)N�stdout�rr:s r�,test_daemon_threads_shutdown_stdout_deadlockz8CMiscIOTest.test_daemon_threads_shutdown_stdout_deadlock����	
�3�3�H�=r c�&�|jd�y)N�stderrrr:s r�,test_daemon_threads_shutdown_stderr_deadlockz8CMiscIOTest.test_daemon_threads_shutdown_stderr_deadlock�r r N)r#r$r%r�r�r�rrr
r�rr�rr#r&r rrr�s���	�B� �N�'�N�9�'.�R1��0�0�2��W���z�*�>�+�3�>�1��0�0�2��W���z�*�>�+�3�>r rc��eZdZeZdZdZdZy)�PyMiscIOTest)�_pyior�)r��	open_code)�valid_seek_flagsN)r#r$r%r�r�r�r�r�r&r rr%r%�s��	
�B�"�N�4�N�&�Lr r%�ntz%POSIX signals required for this test.c�:�eZdZd�Zd�Zd�Zd�Zeeje
ed�d�d���Zeeje
ed�d�d���Z
eeje
ed�d�d	���Zej d
��Zed��Zed��Zd
�Zeej*d�d���Zeej*d�d���Zd�Zeej*d�d���Zeej*d�d���Zy)�SignalsTestc�j�tjtj|j�|_yrJ)�signal�SIGALRM�alarm_interrupt�oldalrmr:s rr�zSignalsTest.setUp�s���}�}�V�^�^�T�5I�5I�J��r c�`�tjtj|j�yrJ)r-r.r0r:s rr�zSignalsTest.tearDown�s���
�
�f�n�n�d�l�l�3r c��ddzyr8r&)r;�sig�frames   rr/zSignalsTest.alarm_interrupt�r=r c��
��tj�g��
�fd�}tj|��}d|_tj�\�
}d|d<|tjt|�zdzz}	|jj|fi|��}ttd�rwtjtjtjg�|j!�tjtj"tjg�n|j!�tj$d�	|j't(|j*|�tj$d�|j-��j/tj0�
d��|j3�|dd|dd	g�tj4|�tj4�
�	|j5�y
#tj$d�|j-�wxYw#t6$r(}	|	j8t8j:k7r�Yd
}	~	y
d
}	~	wwxYw#tj4|�tj4�
�	j5�w#t6$r(}	|	j8t8j:k7r�Yd
}	~	wd
}	~	wwxYwxYw)z�Check that a partial write, when it gets interrupted, properly
        invokes the signal handler, and bubbles up the exception raised
        in the latter.c�T��tj�d�}�j|�yr�)rrtrK)r�r+�read_resultss ��rr�z2SignalsTest.check_interrupted_write.<locals>._reads �������1�
�A�����"r roTFr�r9�pthread_sigmaskrr~N)rr�r�r#�daemonrr�
PIPE_MAX_SIZErr�r/rr-r8�	SIG_BLOCKr.r$�SIG_UNBLOCKr4r�r�rMr�rKrtr�r�r�r-r.)r;�itemr�
fdopen_kwargsr�rr�
large_data�wiorlr+r7s          @@r�check_interrupted_writez#SignalsTest.check_interrupted_write�s���6	������	#�
���E�*������w�w�y���1�#(�
�i� ��W�2�2�c�$�i�?�!�C�D�
�$	��$�'�'�,�,�q�2�M�2�C��v�0�1��&�&�v�'7�'7�&�.�.�9I�J����	��&�&�v�'9�'9�F�N�N�;K�L����	�
�L�L��O�
��!�!�"3�S�Y�Y�
�K����Q������
�������1�
�.����\�E�!�A�J��a��
�+C�D��H�H�Q�K��H�H�Q�K�
��	�	������Q��������
��7�7�e�k�k�)��*��
��
�H�H�Q�K��H�H�Q�K�
��	�	����
��7�7�e�k�k�)��*��
�sh�;C	I$�!H�&A$I$�5H0�'H-�-I$�0	I!�9I�I!�$+K�J!� K�!	K�*K
�K�
K�Krrc�.�|jdddd��y)Nrhr
rr��rAr:s r�!test_interrupted_write_unbufferedz-SignalsTest.test_interrupted_write_unbufferedBs��	
�$�$�U�E���$�Jr c�,�|jddd��y�Nrhr
�rrCr:s r�test_interrupted_write_bufferedz+SignalsTest.test_interrupted_write_bufferedGs��	
�$�$�U�E��$�=r c�.�|jdddd��y)N�xyrhrr:�rr.rCr:s r�test_interrupted_write_textz'SignalsTest.test_interrupted_write_textLs��	
�$�$�T�5�s�W�$�Mr c�z��	���	fd�}tjtj|�tj�\}}|jj
|fi|���		tjd�|jttf�5}	td�D]#}�	j���	j��%tj|t��dz��T#1swYnxYwj}t!|t�r3|j#t%|�j'd�t%|��tjd��	j)�tj(|�y#tjd��	j)�tj(|�wxYw)Nc�2���j��ddzyr8)rM)r�rr@s ��r�on_alarmz3SignalsTest.check_reentrant_write.<locals>.on_alarmSs����I�I�d�O�
�a�Cr r9rzreentrant callr)r-r.rrr�r/r4r�r�r�r�rMr�rtrrrLr�rrRr�)
r;rr>rOr+rr r�rr@s
 `       @r�check_reentrant_writez!SignalsTest.check_reentrant_writeQs<���	�	�
�
�f�n�n�h�/��w�w�y���1��d�g�g�l�l�1�.�
�.��	��L�L��O��"�"�$5�|�#D�E�
0���"�3�Z�$���	�	�$���	�	��$��G�G�A�s�4�y�3��/��
0�
0���,�,�C��#�|�,�����C�� 3� 3�4D� E�s�3�x�P��L�L��O��I�I�K��H�H�Q�K��
�L�L��O��I�I�K��H�H�Q�K�s �"0E>�AC(�(C1�-AE>�><F:c�*�|jdd��yrF�rPr:s r�test_reentrant_write_bufferedz)SignalsTest.test_reentrant_write_bufferedms���"�"�5�t�"�4r c�,�|jddd��y)NrJrr:rKrRr:s r�test_reentrant_write_textz%SignalsTest.test_reentrant_write_textqs���"�"�4�c�G�"�Dr c���tj�\}�d|d<�fd�}tjtj|�	|jj
|fi|��}tj�d�tjd�|j||jd��d�tjd�|j�tj��tj|�y	#tjd�j�tj��tj|�wxYw)
z�Check that a buffered read, when it gets interrupted (either
        returning a partial result or EINTR), properly invokes the signal
        handler and retries if the latter returned successfully.Fr�c�2��tj�d�y)Nr�)rrM)r3r4rs  �r�
alarm_handlerz?SignalsTest.check_interrupted_read_retry.<locals>.alarm_handler{s����H�H�Q��r rr9r��foobarrN)rrr-r.r�r/rMr4r�rtr�)r;r�r>r+rX�riors      @r�check_interrupted_read_retryz(SignalsTest.check_interrupted_read_retryus�����w�w�y���1�#(�
�i� �	 ��
�
�f�n�n�m�4�
	��$�'�'�,�,�q�2�M�2�C��H�H�Q����L�L��O�

���V�C�H�H�Q�K�0�(�;��L�L��O��I�I�K��H�H�Q�K��H�H�Q�K��
�L�L��O��I�I�K��H�H�Q�K��H�H�Q�K�s�A/D�AErc�,�|jd�d��y)Nc�$�|jd�S)Nr�)r�r<s rr�zBSignalsTest.test_interrupted_read_retry_buffered.<locals>.<lambda>�s��A�H�H�X�4F�r r
rG�r[r:s r�$test_interrupted_read_retry_bufferedz0SignalsTest.test_interrupted_read_retry_buffered�s��	
�)�)�*F�/3�	*�	5r c�.�|jd�dd��y)Nc��|SrJr&r<s rr�z>SignalsTest.test_interrupted_read_retry_text.<locals>.<lambda>�s��A�r r+r�rKr^r:s r� test_interrupted_read_retry_textz,SignalsTest.test_interrupted_read_retry_text�s��	
�)�)�+�/2�X�	*�	Gr c�����
�����tjd��tj}t	j
�\�
}d|d<g�d�d���
���fd�}t
j|���d�_�fd�}�fd	��||z}tjtj|�	|jj|fi|��}tjd
�|j|�}	|j||	�|j!�d��j#�|j%��|j|t'd��D���tjd�d�t	j(|�t	j(�
�	|j)�y#t*$r(}
|
j,t,j.k7r�Yd}
~
yd}
~
wwxYw#tjd�d�t	j(|�t	j(�
�	j)�w#t*$r(}
|
j,t,j.k7r�Yd}
~
wd}
~
wwxYwxYw)
z�Check that a buffered write, when it gets interrupted (either
        returning a partial result or EINTR), properly invokes the signal
        handler and retries if the latter returned successfully.�selectFr�Nc���	�s`��j�gggd�dvrBtj�d�}�j|���j�gggd�dvr�B�s�_yy#t$r}|�Yd}~yd}~wwxYw)Ng�?rr+)rdrrtrK�
BaseException)r�r�errorr+r7rd�write_finisheds  �����rr�z8SignalsTest.check_interrupted_write_retry.<locals>._read�s����
�(��v�}�}�a�S�"�b�#�>�q�A�A��G�G�A�t�,��$�+�+�A�.��v�}�}�a�S�"�b�#�>�q�A�A�)��!�
����
�s�AA&�!A&�&	A;�/A6�6A;roTc�x��tjtj��tjd�yr�)r-r.r4)r3r4�alarm2s  �r�alarm1z9SignalsTest.check_interrupted_write_retry.<locals>.alarm1�s ����M�M�&�.�.�&�1��L�L��Or c�&���j�yrJ)r$)r3r4rs  �rrjz9SignalsTest.check_interrupted_write_retry.<locals>.alarm2�s���
�G�G�Ir r9c3�2K�|]}t|����y�wrJ)r)�.0rs  r�	<genexpr>z<SignalsTest.check_interrupted_write_retry.<locals>.<genexpr>�s����#A�q�C��F�#A�s�r)rr�rr:rrr�r#r9r-r.r�r/r4rMr�r�r�r��sumr�r�r-r.)r;r=r>rvrr�rkr?r@r�rlrjrgr+r7rdrrhs           @@@@@@@r�check_interrupted_write_retryz)SignalsTest.check_interrupted_write_retry�s�����,�,�X�6��
�!�!���w�w�y���1�#(�
�i� �
������	�	�
���E�*�����	�	��A�X�
��
�
�f�n�n�f�-�	��$�'�'�,�,�q�2�M�2�C��L�L��O��i�i�
�+�G����Q��(��I�I�K�!�N�
�F�F�H����e�$����Q��#A�L�#A� A�B��L�L��O�!�N��H�H�Q�K��H�H�Q�K�
��	�	����
��7�7�e�k�k�)��*��
��
�L�L��O�!�N��H�H�Q�K��H�H�Q�K�
��	�	����
��7�7�e�k�k�)��*��
�sP�)B*G�F&�&	G�/G�G�AI"�H.�-I"�.	I�7I�I"�I�I"c�*�|jdd��y)Nr�r
rG�rqr:s r�%test_interrupted_write_retry_bufferedz1SignalsTest.test_interrupted_write_retry_buffered�s��	
�*�*�4�d�*�;r c�,�|jddd��y)Nrrr�rKrsr:s r�!test_interrupted_write_retry_textz-SignalsTest.test_interrupted_write_retry_text�s��	
�*�*�3�S�8�*�Lr N)r#r$r%r�r�r/rA�requires_alarmr|rrrrDrHrLrrbrPrSrUr[r�r_rbrqrtrvr&r rr+r+�s���K�4��K�Z��X�����V�,�.B�C�K�D��K���X�����V�,�.B�C�>�D��>���X�����V�,�.B�C�N�D��N�
������6�5��5��E��E��0��W���z�*�5�+��5���W���z�*�G�+��G�B�H��W���z�*�<�+��<���W���z�*�M�+��Mr r+c��eZdZeZy)�CSignalsTestN)r#r$r%r�r&r rryry�s��	�Br ryc��eZdZeZdZdZy)�
PySignalsTestN)r#r$r%r�r�rSrUr&r rr{r{�s��	
�B�%)�!� $�r r{c���tttttt
ttttttttttt t"t$t&t(f}t*t,t.t0t2t4t6t8f}t:j<}|D�cic]}|t?t:|���}}|D�cic]}|t?t@|���}}tC��|jE�fd�|D��|jE�fd�|D��|D]�}|jFjId�r-|jK�D]\}}	tM|||	��d|_'�K|jFjId�s�g|jK�D]\}}	tM|||	��d|_'��|jQ�}
|D]"}|
jS|jU|���$|
Scc}wcc}w)Nc3�Z�K�|]"}|j�d|jzf���$y�w)r�N�r#�rnr�globss  �rrozload_tests.<locals>.<genexpr>
s(�����H�Q�A�J�J��c�A�J�J�&6� 7�8�H���(+c3�Z�K�|]"}|j�d|jzf���$y�w)�PyNr~rs  �rrozload_tests.<locals>.<genexpr>s(�����J�q�Q�Z�Z��t�a�j�j�'8�!9�:�J�r�r�Tr�F)+r�r�r�r�r�rrrYr[r�r�r�r�r�rnr�rr%ryr{r�rpr{r�r�r�r�r?r�r��__all__rJr��globalsr r#rRr��setattrr��
suiteClass�addTest�loadTestsFromTestCase)�loaderrSr�mocks�all_membersr+�c_io_ns�py_io_nsrTr�suiter�s           @r�
load_testsr��s����
�h��
 �"6�
 �"6�
 �"6�
 �"6�
+�
+�-L�
�!4�
�,�
�=�,�

�E����^�
!�#3�5I�
�
�E��*�*�K�4?�@�D�t�g�b�$�'�'�@�G�@�7B�C�t��w�t�T�*�*�C�H�C��I�E��N�N�H�%�H�H��O�O�J�E�J�J�����=�=�#�#�C�(�$�]�]�_�
)�	��c���d�C�(�
)��D�I�
�]�]�
%�
%�d�
+�%�^�^�-�
)�	��c���d�C�(�
)��D�I��
����E��:��
�
�
�f�2�2�4�8�9�:��L��%A��Cs�+G1�	G6�__main__)|rir�r)r-rrr�rrr-rPrr�r�r|rYr��collectionsrr�	itertoolsrrrTr�test.support.script_helperrr	r
�test.supportrrr
rr�test.support.os_helperrr�r�r&r�rr�	Structurer�ImportErrorr�rr�r�r3rrrwr6r?rNrkrnrprwryr{r�r�r�r�r�r�r�r�r�r0r�r�r�r�r�r�r�r��TestCaser�r�r'r�r�r�r�rr)r�r�r�rrrrYr[r]r�r�r�r�r�r�r�r/r0rnr�r�r�r�r�rr%r}r+r+ryr{r�r#�mainr&r r�<module>r�s ��#�*���
�	�
�
�
�
�������'�"��C�C�&�"�)�(�*�+�
�	��
��
�
�f�&�&�
�
#�+�+�A�s�y�y�/A�/A���
%��$�$��F�G��<���
��6�6�p	�0�"�,�,�	�	�1�4�>�>�	��$��	��B�L�L�	�	�)�T�^�^�	��i��"	�����	�	�����	��Y��	�n�b�l�l�	�	�~�t�~�~�	��Y��	�n�b�l�l�	�	�~�t�~�~�	��� 	�*�b�j�j�	�	�:�t�|�|�	�8�8�3�(�"�*�*�3�5�)�4�<�<�5�.�.�`)�0�"�,�,�)�+�1�4�>�>�+�A$�X�
�
�A$�H$�f�$�(	���VG�8�$�$�VG��VG�p	�v�	�	���h�h�'�'�h��h�j�j�Z5�5�,tH��*�*�,?�tH�n	@A�,�j�@A�F�-��d��*�*�,?�d�P	-6�,�j�-6�`�-��N��*�*�N�`�,���-��f&�+�-?�f&�R6�,�j�6�2�-��I��!:�!:�I�\;�)4�X�%6�%6�)4�Vp;��)�)�p;�f%2�R�Z�Z�2��KQ�*�KQ�\<�+�<�
s>�H�$5�$5�s>�j;�%B�;�	�&C�	�r5��"�"�r5�j?>�*�?>�D'�:�'��������D��"I�J�{M�(�#�#�{M�K�{M�|�;��%�K�%�%�N�z���H�M�M�O���IW�3�3�3�s�T	�	T�T