
    <e}                        d Z ddlZddlmZ ddlZddlZddlZddlZ G d d          Z	 G d d          Z
 G d d	          Z G d
 dee
ej                  Z G d d          Z G d dee
eej                  Z G d deej                  Z G d de          Z G d de          Z G d de          Zedk    r ej                     dS dS )zdUnit tests for memory-based file-like objects.
StringIO -- for unicode strings
BytesIO -- for bytes
    N)supportc                       e Zd Zd Zd ZeZdS )IntLikec                     || _         d S N_num)selfnums     )/usr/lib/python3.11/test/test_memoryio.py__init__zIntLike.__init__   s    			    c                     | j         S r   r   r
   s    r   	__index__zIntLike.__index__   s
    yr   N)__name__
__module____qualname__r   r   __int__ r   r   r   r      s1            GGGr   r   c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )MemorySeekTestMixinc                 Z    |                      d          }|                     |          }d S N
1234567890)buftypeioclassr
   bufbytesIos      r   testInitzMemorySeekTestMixin.testInit   s(    ll<((,,s##r   c                    |                      d          }|                     |          }|                     |d d         |                    d                     |                     |dd         |                    d                     |                     |dd          |                    d                     |                     | j        |                                           d S )Nr              r   r   assertEqualreadEOFr   s      r   testReadzMemorySeekTestMixin.testRead   s    ll<((,,s##RaR',,q//222QqS7<<??333QRR',,s"3"34447<<>>22222r   c                    |                      d          }|                     |          }|                     ||                                           |                     | j        |                                           d S r   r'   r   s      r   testReadNoArgsz"MemorySeekTestMixin.testReadNoArgs$   sh    ll<((,,s##gllnn---7<<>>22222r   c                    |                      d          }|                     |          }|                    d           |                    d           |                     ||                                           |                    d           |                     |dd          |                                           |                     t          |j        d           d S )Nr   r$   r              )r   r   r)   seekr(   assertRaises	TypeErrorr   s      r   testSeekzMemorySeekTestMixin.testSeek+   s    ll<((,,s##QQgllnn---QQRR',,..111)W\377777r   c                    |                      d          }|                     |          }|                     d|                                           |                    d           |                     d|                                           |                    d           |                     d|                                           d S Nr   r   r$   i'  )r   r   r(   tellr1   r   s      r   testTellzMemorySeekTestMixin.testTell7   s    ll<((,,s##GLLNN+++QGLLNN+++U/////r   N)r   r   r   r!   r+   r-   r4   r8   r   r   r   r   r      s_        $ $ $3 3 33 3 3
8 
8 
80 0 0 0 0r   r   c                       e 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 Zd Zd Zd Zd Zd ZdS )MemoryTestMixinc                 n    |                                  }|                     | j        |j                   d S r   )r   r2   UnsupportedOperationdetachr
   r   s     r   test_detachzMemoryTestMixin.test_detachD   s0    llnn$3SZ@@@@@r   c                    |                      |                     |d                    d           |                      |                    d          d           |                      |                     |d                    d           |                      |                                d           |                      |                    d          d           |                      |                                d           |                      |                     |d                    d           |                      |                    d          d           |                      |                     |d                    d	           |                      |                    d
          d
           |                      |                                d	           d S )Nzblah.r$   r   zHello.   z	 world


	   hr#      )r(   writer1   r7   truncate)r
   fts      r   	write_opszMemoryTestMixin.write_opsH   s   7,,a000A&&&8--q1111%%%A&&&1%%%>!2!233Q777A&&&3!,,,B,,,1%%%%%r   c                 `   |                      d          }|                     |          }|                     || j                    |                     |                                |           |                                 }|                     || j                    |                     |                                |           |                     t          |j        d            |                                 |                     t          |j        |                      d                     d S )Nzhello world
 )
r   r   rI   r(   getvaluer2   r3   rE   close
ValueErrorr
   r   memios      r   
test_writezMemoryTestMixin.test_writeU   s    ll?++S!!udl+++))3///udl+++))3///)U[$777*ek4<<3C3CDDDDDr   c                    |                      d          }|                                 }|                     |                    |gdz            d            |                     |                                |dz             |                    g            |                     |                                |dz             |                                 }|                     t          |j        |gdgz              |                     |                                |           |                     t          |j        d            |                                 |                     t          |j        g            d S )Nr   d   r#   )	r   r   r(   
writelinesrL   r2   r3   rM   rN   rO   s      r   test_writelineszMemoryTestMixin.test_writelinesb   s?   ll<(())3%#+66===))39555))39555)U%5us{CCC))3///)U%5t<<<*e&6;;;;;r   c                                                        } fd}                     t          |j         |                       d S )Nc               3   D   K                         d          V  t          )Nspam)r   KeyboardInterruptr   s   r   	error_genz8MemoryTestMixin.test_writelines_error.<locals>.error_gens   s%      ,,v&&&&&##r   )r   r2   rY   rT   )r
   rP   rZ   s   `  r   test_writelines_errorz%MemoryTestMixin.test_writelines_errorq   sS    	$ 	$ 	$ 	$ 	$ 	+U-=yy{{KKKKKr   c                 .   |                      d          }|                     |          }|                     t          |j        d           |                     t          |j        t          d                     |                    d           |                     |                    t          d                    d           |                     |                                |d d                    |                     |                                d           |                     |                                |d d                    |                     |                    d          d           |                     |                                |d d                    |                     |	                                d           |                    dd           |
                    |           |                     |                                |d d         |z              |	                                }|                     |                    d           |           |                     |	                                |           |                     t          |j        d           |                                 |                     t          |j        d           |                     t          |j        t          d                     d S )	Nr   rA      r%   r      0)r   r   r2   rN   rF   r   r1   r(   rL   r7   rE   r3   rM   )r
   r   rP   poss       r   test_truncatezMemoryTestMixin.test_truncatey   ss   ll<((S!!*enb999*engbkkBBB

1

33Q777))3rr7333))1---))3rr7333**A...))3rr7333q)))

1aC))3rr7S=999jjll--s333s+++)U^S999*ena888*engajjAAAAAr   c                 p   |                      d          }|                     |          }|                     |                                |           |                     d           }|                     |                                | j                   |                    |dz             |                     |                                |dz             |                    |           |                     |                                |           |                     t          |j        g            d S )Nr   r_   )r   r   r(   rL   r*   r   r2   r3   rO   s      r   	test_initzMemoryTestMixin.test_init   s   ll<((S!!))3///T""))48444sQw))37333s))3///)U^R88888r   c                    |                      d          }|                     |          }|                     |                    d          | j                   |                     |                    d          |d d                    |                     |                    d          |dd                    |                     |                    d          |dd                     |                     |                                | j                   |                    d           |                     |                    t          d                    | j                   |                     |                    t          d                    |d d                    |                     |                    t          d                    |dd                    |                     |                    t          d                    |dd                     |                    d           |                     |                                |           |                     |                                | j                   |                     |                                d           |                    d           |                     |                    d          |           |                    d           |                     |                    t          d                    |           |                    d           |                     t          |                                          t          |                     |                    d	           |                     t          |                                          t          |                     |                    d           |                     |                    d           |           | 	                    t          |j        d
           |                    t          |          dz              |                     |                    d          | j                   |                    t          |          dz              |                     |                    t          d                    | j                   |                    t          |          dz              |                     |                                | j                   |                                 | 	                    t          |j                   d S )Nr   r   r#   r%   r$   r&   
   r]   rS   rK   )r   r   r(   r)   r*   r1   r   r7   typer2   r3   lenrM   rN   rO   s      r   	test_readzMemoryTestMixin.test_read   s$   ll<((S!!A111ABQB000AAaC111C#abb'222tx000

1GAJJ//:::GAJJ//RaR999GAJJ//QqS:::GCLL113qrr7;;;

1s+++tx000r***

1B---

1GBKK00#666

1ejjll++T#YY777

3ejjll++T#YY777

1D))3///)UZ444

3s88a<   A111

3s88a<   GAJJ//:::

3s88a<   tx000*ej11111r   c                 >   |                      d          }|                     |dz            }|                     |                    d          | j                   |                     |                    t          d                    | j                   |                     |                                |           |                     |                                |           |                     |                                | j                   |                    d           |                     |                    d          |d d                    |                     |                    d          |dd                    |                     |                    d          |dd                    |                    d           |                     |                    t          d                    |d d                    |                     |                    t          d                    |dd                    |                     |                    t          d                    |dd                    |                    d           |                     |                    d          |           |                    d           |                     |                    t          d                    |           |                    d           |                     |                    d          | j                   |                     |                    t          d                    | j                   |                    t          |          dz  dz              |                     |                                | j                   |                      d          }|                     |d	z  d d                   }|                     |                                |           |                     |                                |           |                     |                                |d d                    |                     |                                | j                   |                    d           |                     t          |                                          t          |                     |                     |                                |           | 	                    t          |j        d
           |                                 | 	                    t          |j                   d S )N1234567890
r_   r   r$   rf      r]   r#   r/   rK   )r   r   r(   readliner*   r   r1   rh   rg   r2   r3   rM   rN   rO   s      r   test_readlinezMemoryTestMixin.test_readline   sf   ll>**S1W%%**DH555

33TX>>>))3///))3///))48444

1**CG444**C"I666**C2J777

1

33S!W===

33S2Y???

33SBZ@@@

1++S111

144c:::

1**DH555

33TX>>>

3s88a<!#$$$))48444ll>**cAgss^,,))3///))3///))3ss8444))48444

1enn..//c;;;))3///)U^R888*u~66666r   c                 f   |                      d          }|                     |dz            }|                     |                                |gdz             |                    d           |                     |                                |dd          g|gdz  z              |                    d           |                     |                    d          |gdz             |                    d           |                     |                    d          |gdz             |                    d           |                     |                    d          |gdz             |                    d           |                     t          |                                d                   t          |                     |                    d           |                     |                    d           |gdz             |                     t          |j        d	           |                    t          |          dz  d
z              |                     |                                g            |	                                 |                     t          |j                   d S )Nrk   rf   r$   rB   r   rl   r_   r]   rK   r#   )r   r   r(   	readlinesr1   rg   r2   r3   rh   rM   rN   rO   s      r   test_readlineszMemoryTestMixin.test_readlines   s6   ll>**S2X&&**SEBJ777

1**SWI	,ABBB

1,,seai888

1,,sebj999

1++cURZ888

1eoo//233T#YY???

1..
;;;)U_b999

3s88b=1$%%%**B///*eo66666r   c                 j   |                      d          }|                     |dz            }|                     t          |          |           |                     t          |d                     |                     t          |d                     d}|D ]}|                     ||           |dz  }|                     |d           |                    d           d}|D ]}|                     ||           |dz  }|                     |d           |                    t          |          dz  dz              |                     t          |          g            |                     |dz            }|	                                 | 
                    t          |j                   d S )Nrk   rf   __iter____next__r   r#   r_   )r   r   r(   iter
assertTruehasattrr1   rh   listrM   r2   rN   rt   )r
   r   rP   ilines        r   test_iteratorzMemoryTestMixin.test_iterator  s   ll>**S2X&&ee,,,z22333z22333 	 	DT3'''FAAB

1 	 	DT3'''FAAB

3s88b=1$%%%eb)))S1W%%*en55555r   c                    |                      d          }|                     |          }|                     |                                |           |                                 |                     |                                |           |                     t          |                                          t          |                     |                     |dz            }|                     |                                dd          |                      d                     |                     |          }|                                 |                     t          |j                   d S )Nr     890)	r   r   r(   rL   r)   rg   rM   r2   rN   rO   s      r   test_getvaluezMemoryTestMixin.test_getvalue  s%   ll<((S!!))3///

))3///enn..//c;;;S4Z(())"##.U0C0CDDDS!!*en55555r   c                     |                      d          }|                     |          }|                    d           |                     t          |j        d           |                     t          |j        dd           |                     t          |j        dd           |                     |                    d          d           |                     |                    dd          d           |                     |                                |           |                     |                    d          d           |                     |                    dd          d           |                     |                                |dd                     |                     |                    t          |                    t          |                     |                     |                                | j                   |                    t          |          dz              |                     |                                | j                   |                     |                    dd          t          |                     |                     |                                | j                   |	                                 |                     t          |j        d           d S )Nr   r$   r]   r#   r/   r   r_   )
r   r   r)   r2   rN   r1   r(   rh   r*   rM   rO   s      r   	test_seekzMemoryTestMixin.test_seek,  sR   ll<((S!!

1*ej"555*ej!R888*ej!Q777A***Aq))1---s+++A***Aq))1---s122w///CHH--s3xx888tx000

3s88a<   tx000Aq))3s88444tx000*ej!44444r   c                    |                      d          }|                     |          }|                     |                    t	          |          dz             d           |                     |                                | j                   |                     |                                d           |                     |                                |           |	                    | j                   |                     |                                |           |	                    |           |                     |                                ||                      d          z   |z              d S )Nr   r#       )
r   r   r(   r1   rh   r)   r*   r7   rL   rE   rO   s      r   test_overseekzMemoryTestMixin.test_overseekC  s0   ll<((S!!CHHqL112666tx000r***))3///DH))3///C))3d1C1C+Cc+IJJJJJr   c                    |                      d          }|                     |          }|                     |                                d           |                    d           |                     |                                d           |                    d           |                     |                                d           |                                 |                     t          |j                   d S r6   )r   r   r(   r7   r1   rM   r2   rN   rO   s      r   	test_tellzMemoryTestMixin.test_tellP  s    ll<((S!!q)))

1q)))

5u---*ej11111r   c                     |                      d          }|                     |          }|                     |                                d            d S r   )r   r   r(   flushrO   s      r   
test_flushzMemoryTestMixin.test_flush\  sH    ll<((S!!-----r   c                    |                                  }|                     |                                d           |                     |                                d           |                     |                                d           |                     |                                d           |                     |j        d           |                                 |                     t          |j                   |                     t          |j                   |                     t          |j                   |                     t          |j                   |                     |j        d           d S )NTF)
r   r(   writablereadableseekableisattyclosedrM   r2   rN   r
   rP   s     r   
test_flagszMemoryTestMixin.test_flagsb  s0   ))4000))4000))4000///u---*en555*en555*en555*el333t,,,,,r   c                                            d           fd} fd}                      |                                             |                       d S )Nr   c                  h     G d dj                   }  |           }|                                S )Nc                       e Zd ZdS )>MemoryTestMixin.test_subclassing.<locals>.test1.<locals>.MemION)r   r   r   r   r   r   MemIOr   t  s        r   r   r   rL   r   mr   r
   s     r   test1z/MemoryTestMixin.test_subclassing.<locals>.test1s  sJ           c

A::<<r   c                  n     G fddj                   }  | d           }|                                S )Nc                       e Zd Z fdZdS )>MemoryTestMixin.test_subclassing.<locals>.test2.<locals>.MemIOc                 >    j                             | |           d S r   )r   r   )meabr
   s      r   r   zGMemoryTestMixin.test_subclassing.<locals>.test2.<locals>.MemIO.__init__z  s!    L))"a00000r   Nr   r   r   r   r   s   r   r   r   y  s.        1 1 1 1 1 1 1r   r   r   r   s     r   test2z/MemoryTestMixin.test_subclassing.<locals>.test2x  sZ    1 1 1 1 1 1 1 1 1 1 c4  A::<<r   )r   r(   )r
   r   r   r   s   `  @r   test_subclassingz MemoryTestMixin.test_subclassingq  s    ll<((	  	  	  	  	  	 
	  	  	  	  	  	  	#&&&#&&&&&r   c                 `    t          d          D ]}|                                 }d|_        d S )NrS   r#   )ranger   foo)r
   _rP   s      r   test_instance_dict_leakz'MemoryTestMixin.test_instance_dict_leak  s9     s 	 	ALLNNEEII	 	r   c                                           d          }                     |          }d|_        |                    d            G  fdd j                  }dd l}d|_        |j        |_        ||_         ||d          }|                    d           t          dt          j        d	z             D ]#}||fD ]}t          j        t          j        ||
                    }                     |                                |                                                                |j        |j                                        |j        |j                                        |                                |                                           |                                                      t(          t          j        ||           %|`d S )Nr   *   r_   c                       e Zd Z fdZdS )6MemoryTestMixin.test_pickling.<locals>.PickleTestMemIOc                 L    j                             | |           || _        d S r   )r   r   r   )r   	initvaluer   r
   s      r   r   z?MemoryTestMixin.test_pickling.<locals>.PickleTestMemIO.__init__  s&    %%b)444r   Nr   r   s   r   PickleTestMemIOr     s.              r   r   r   __main__P   r#   )protocol)r   r   r   r1   r   r   r   r   r   r   pickleHIGHEST_PROTOCOLloadsdumpsr(   rL   	__class__r7   rM   r2   rN   )	r
   r   rP   r   r   submemioprotoobjobj2s	   `        r   test_picklingzMemoryTestMixin.test_pickling  s   ll<((S!!	

1	 	 	 	 	 	 	dl 	 	 	 	%/"'6'?$#2 "?3++a 1f59:: 	I 	IEx( I I|FLu$E$E$EFF  AAA  ???  $(333  TYY[[999

!!*flD%HHHHI $$$r   N)r   r   r   r?   rI   rQ   rU   r[   rb   rd   ri   rn   rq   r{   r   r   r   r   r   r   r   r   r   r   r   r   r:   r:   B   sQ       A A A& & &E E E< < <L L LB B B2
9 
9 
9$2 $2 $2L'7 '7 '7R7 7 706 6 626 6 65 5 5.K K K
2 
2 
2. . .- - -' ' '   #% #% #% #% #%r   r:   c                   n    e Zd Zej        Zed             Zej        ZdZ	d Z
d Zd Zd Zd Zd Zd	 Zd
S )PyBytesIOTestc                 ,    |                      d          S )Nascii)encode)ss    r   r   zPyBytesIOTest.buftype  s    xx   r   r   c                    |                      d          }|                                }|                     t          |          d           |                    d           |                                }|                     t          |          d           |                     t          |j        d           |                     t          |j                   |                     t          |j	                   | 
                    |j                   d|dd<   |                     t          |          d           |                     |                                d           ~t          j                     |                                 |	                                 |                     t          |j                   d S )N
   1234567890r$   sd   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs   abcr/   rA   s
   123abc7890)r   	getbufferr(   bytesr1   r2   BufferErrorrE   rF   rM   assertFalser   rL   r   
gc_collectrN   )r
   rP   r   s      r   test_getbufferzPyBytesIOTest.test_getbuffer  sr   ]++oos]333

1oos]333 	+u{J???+u~666+u{333&&&AaCs]333))=999 *eo66666r   c                    |                      d          }|                     |                     |                                          |           |                     |                     |                              d          |           d S )Nr   r]   )r   r(   r   read1r>   s     r   
test_read1zPyBytesIOTest.test_read1  sw    ll<((c**0022C888c**0044c:::::r   c                    |                      d          }|                     |          }t          d          }|                     |                    |          d           |                     |d           |                     |                    |          d           |                     |d           |                     |                    |          d           |                     |d           t          d          }|                    d           |                     |                    |          d           |                     |d	           t          d
          }|                    d           |                     |                    |          d           |                     |d
           |                     t          |j        d           dd l}|                    dd          }|                     |          }|                    |           |                     |	                                d	           |
                                 |                     t          |j        |           |                     d          }t                      }|                    d           |                    |           |                     |d
           d S )Nr   s   hellor$   s   12345s   67890r   s   hello worldrf   s   1234567890dr   rK   r   s   123r   )r   r   	bytearrayr(   readintor1   r2   r3   arraytobytesrM   rN   )r
   r   rP   r   r   r   s         r   test_readintozPyBytesIOTest.test_readinto  st   ll<((S!!h**A...H%%%**A...H%%%**A...H%%%n%%

1**B///N+++cNN

1**A...C   )U^R888KK^,,S!!qn555*ena888V$$KK

2qC     r   c                    |                      d          }|                     |          }|                     |                    dd          d           |                     |                    dd          d           |                     |                    dd          d           |                     |                    dd          d           |                     |                    dd          d	           |                     |                    dd          d
           |                    dd           |                     |                                |dd                     |                    d           |                    dd           |                     |                                |dd                     d S )Nr   r]   r#   r   r/   r_   rB   rf   r   r~   )r   r   r(   r1   r)   rO   s      r   test_relative_seekz PyBytesIOTest.test_relative_seek  s   ll<((S!!B**A...Aq))1---B**A...B**A...Aq))2...Aq))2...

2qs233x000

1

1as122w/////r   c                     |                                  }|                     t          | j         d           |                     t          |j        d           |                     t          |j        dg           d S r   )r   r2   r3   rE   rT   r   s     r   test_unicodezPyBytesIOTest.test_unicode  sf    )T\<@@@)U[,???)U%5~FFFFFr   c                 t   d}dd l }|                     dt          |                    }|                     |          }|                     |                                |           |                     |                    |          d           |                     |                                |           d S )Nr   r   r   rf   )r   rx   r   r(   rL   rE   )r
   r   r   r   rP   s        r   test_bytes_arrayzPyBytesIOTest.test_bytes_array  s    KKT#YY''Q))3///Q,,,))3/////r   c                     |                      d          }|                     |           |                     t          | j        |d            d S )Nr   )initial_bytes)r   )r   r   r2   r3   r>   s     r   test_issue5449zPyBytesIOTest.test_issue5449  sL    ll<((3''')T\3DAAAAAr   N)r   r   r   pyior<   staticmethodr   BytesIOr   r*   r   r   r   r   r   r   r   r   r   r   r   r     s          4! ! \!lG
C7 7 72; ; ;
! ! !B0 0 0 G G G0 0 0B B B B Br   r   c                   P    e 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S )TextIOTestMixinc                    |                      d           fd}|                     j        d                                d            |             |                     j        d                               d            |             |                     j        d                               d            |             |                     j        d           d S )	Nnewlinec                  Z                          d                                             d S )Nr   )r1   r)   rP   s   r   force_decodez<TextIOTestMixin.test_newlines_property.<locals>.force_decode%  s#    JJqMMMJJLLLLLr   a

b
)r   
cd)r   r   )r   r(   newlinesrE   )r
   r   rP   s     @r   test_newlines_propertyz&TextIOTestMixin.test_newlines_property   s    T**	 	 	 	 	 	...E...G888F)=>>>>>r   c                    |                                  }|                     t          |j        dd           |                     t          |j        dd           |                     t          |j        dd           |                     t          |j        dd           |                     t          |j        dd           |                     t          |j        dd           d S )Nr]   r#   r/   r~   r_   )r   r2   OSErrorr1   r   s     r   r   z"TextIOTestMixin.test_relative_seek3  s    '5:r1555'5:q!444'5:r1555'5:r1555'5:q!444'5:q!44444r   c                     |                                  }|                     |j                   |                     |j                   |                     |j                   d S r   )r   assertIsNoneencodingerrorsr   line_bufferingr   s     r   test_textio_propertiesz&TextIOTestMixin.test_textio_properties=  sZ     	%.)))%,'''-.....r   c                    |                      d          }|                     t          |          g d           |                     |                                d           |                                  }|                     |                    d          d           |                    d           |                     t          |          g d           |                     |                                d           d S )Na
b
cdr   r   r   r^   r   r   r(   rx   rL   rE   r1   r   s     r   test_newline_defaultz$TextIOTestMixin.test_newline_defaultF  s    ^,,e&>&>&>???))>:::^44a888

1e&>&>&>???))>:::::r   c                    |                      dd           }|                     t          |          g d           |                    d           |                     |                    d          d           |                     |                    d          d           |                     |                    d          d	           |                     |                    d          d
           |                     |                                d           |                      d           }|                     d|                    d                     |                     d|                    d                     |                     d|                    d                     |                    d           |                     |                                d           |                     |                                d           |                      dd           }|                     |                    d          d           d S )Nr   r   )r   zb
zc
dr   r#   r   r_   z
b
cr   za
b
c
dr   r/   r   r   za
bza
br   r(   rx   r1   r)   rL   rE   r   s     r   test_newline_nonez!TextIOTestMixin.test_newline_noneQ  s   ^T::e&@&@&@AAA

1A,,,A...A...A---))<888T**EKK..///EKK00111EKK//000

1|444))<888Xt44A/////r   c                 &   |                      dd          }|                     t          |          g d           |                    d           |                     |                    d          d           |                     |                    d          d	           |                     |                    d
          d           |                     |                                d           |                      d          }|                     d|                    d                     |                     d|                    d                     |                     d|                    d	                     |                     d|                    d                     |                    d           |                     t          |          g d           |                     |                                d           d S )Nr   rK   r   )r   r   cr  r   r%   za
br_   r  r#   r   r   bzdr  r   s     r   test_newline_emptyz"TextIOTestMixin.test_newline_emptyg  s   ^R88e&B&B&BCCC

1A111A...A---))>:::R((EKK..///EKK..///EKK..///EKK..///

1e&B&B&BCCC))>:::::r   c                    |                      dd          }|                     t          |          g d           |                     |                                d           |                      d          }|                     |                    d          d           |                    d           |                     t          |          g d           |                     |                                d           d S )Nr   r   r   r   r^   r   r   r   s     r   test_newline_lfzTextIOTestMixin.test_newline_lfz  s    ^T::e&>&>&>???))>:::T**^44a888

1e&>&>&>???))>:::::r   c                    |                      dd          }|                     |                                d           |                    d           |                     t	          |          g d           |                     |                                d           |                      d          }|                     |                    d          d           |                    d           |                     t	          |          g d           |                    d           |                     |                                g d           |                     |                                d           d S )Nr   r   r   zabcdr   )zar  r   r  r  r^   )r   r(   r)   r1   rx   rL   rE   rp   r   s     r   test_newline_crzTextIOTestMixin.test_newline_cr  sJ   ^T::~666

1e&F&F&FGGG))>:::T**^44a888

1e&F&F&FGGG

1**,L,L,LMMM))>:::::r   c                    |                      dd          }|                     |                                d           |                    d           |                     t	          |          g d           |                    d           |                     |                                g d           |                     |                                d           |                      d          }|                     |                    d          d           |                    d           |                     t	          |          g d           |                     |                                d           d S )Nr   r   r   z
a
b
cdr   )za
zb
r   r^   )r   r(   r)   r1   rx   rp   rL   rE   r   s     r   test_newline_crlfz!TextIOTestMixin.test_newline_crlf  sM   ^V<<'9:::

1e&B&B&BCCC

1**,H,H,HIII))+=>>>V,,^44a888

1e&B&B&BCCC))+=>>>>>r   c                     |                      dd           }|                     |                    d          d           |                     |                                d           d S )Nza
b
r   r$   za
b
)r   r(   r)   rL   r   s     r   test_issue5265zTextIOTestMixin.test_issue5265  s]    \488A111))844444r   c                     |                      t          | j        d           |                      t          | j        d           dD ]}|                     |           d S )N   
r   error)NrK   r   r   r   )r2   r3   r   rN   )r
   r   s     r   test_newline_argumentz%TextIOTestMixin.test_newline_argument  sl    )T\5AAA*dlGDDD5 	* 	*GLLL))))	* 	*r   N)r   r   r   r   r   r   r   r  r	  r  r  r  r  r  r   r   r   r   r     s        ? ? ?&5 5 5/ / /	; 	; 	;0 0 0,; ; ;&
; 
; 
;; ; ; ? ? ? 5 5 5* * * * *r   r   c                   8    e Zd ZeZej        Zej        ZdZ	d Z
dS )PyStringIOTestrK   c                 "   |                      d          }|                     |                                d           |                                  }|                    d           |                     |                                d           d S )Nu   )r   r(   r)   rE   rL   r   s     r   test_lone_surrogatesz#PyStringIOTest.test_lone_surrogates  sv    X&&x000H))844444r   N)r   r   r   strr   r   StringIOr   r<   r*   r  r   r   r   r  r    s=        GmG4
C5 5 5 5 5r   r  c                   N    e Zd ZdZeZej        ZdZ G d dej	                  Z
dS )PyStringIOPickleTestzETest if pickle restores properly the internal state of StringIO.
    rK   c                       e Zd Zd Zd ZdS )PyStringIOPickleTest.ioclassc           	      l    t          j        t          j        t          j        |i |                    S r   )r   r   r   r   r  clsargskwargss      r   __new__z$PyStringIOPickleTest.ioclass.__new__  s+    <T]D-KF-K-K L LMMMr   c                     d S r   r   r
   r#  r$  s      r   r   z%PyStringIOPickleTest.ioclass.__init__      Dr   Nr   r   r   r%  r   r   r   r   r   r    s5        	N 	N 	N	 	 	 	 	r   r   N)r   r   r   __doc__r  r   r   r<   r*   r  r   r   r   r   r  r    s]         G4
C    $-     r   r  c                       e Zd Zej        Zej        Zd Zd Ze	j
        Z
e	j        d             Zd Ze	j        d             Ze	j        d             Ze	j        d             Ze	j        d             Zd	S )
CBytesIOTestc                    |                                  }|                                }|                     t          |          d           t	          |d                    |                     |d         t                     |d         !|                     |d         t                     |                                 | 	                    t          |j                   d S )Nr/   r   r#   r_   )r   __getstate__r(   rh   r   assertIsInstanceintdictrM   r2   rN   r
   rP   states      r   test_getstatezCBytesIOTest.test_getstate  s    ""$$UQ'''%(eAh,,,8!!%(D111*e&899999r   c                    |                                  }|                    d           |                    t          d          dd f           |                    ddddif           |                     t          |j        d           |                     t
          |j        d           |                     t
          |j        d           |                     t
          |j        d	           |                     t
          |j        d
           |                     t
          |j                   |                     t
          |j        d           |                                 |                     t          |j        d           d S )N)   no errorr   Nr6  r   rX   r/   )r   r]   N)unicoder   N)r   r0   N)r   r   r   )s   len-testr   )s   closedr   N)r   __setstate__r   r2   rN   r3   rM   r   s     r   test_setstatezCBytesIOTest.test_setstate  sS   1222Ik22At<===KVQK8999*e&8/JJJ)U%79MNNN)U%79IJJJ)U%7EEE)U%79IJJJ)U%7888)U%7;;;*e&8:NOOOOOr   c                 j   t          j        d          }| j        }|                     t                              t          j                              |            |t          j                    |           d} |t          j        d|z            |t          j	        d|z            z              d S )NP2n2Pnr}      a)
r   calcobjsizecheck_sizeofr(   object
__sizeof__ior   sys	getsizeof)r
   basesizecheckns       r   test_sizeofzCBytesIOTest.test_sizeof  s    &x00!**2:<<88(CCCbjllH&&&bj""Hs}TAX/F/F$FGGGGGr   c                    d}t          j        |          }|                     |          }|                     t          j        |          |dz               ||           |                     t          j        |          |           d S )Ns                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   r#   )rB  getrefcountr   r(   )r
   mutationimmold_rcrP   s        r   _test_cow_mutationzCBytesIOTest._test_cow_mutation  s~    %%S!!--vz:::--v66666r   c                 6    d }|                      |           d S )Nc                 0    |                      d           d S )Nr#   )rF   r   s    r   rJ  z0CBytesIOTest.test_cow_truncate.<locals>.mutation  s    NN1r   rM  r
   rJ  s     r   test_cow_truncatezCBytesIOTest.test_cow_truncate  s+    	 	 	)))))r   c                 6    d }|                      |           d S )Nc                 Z    |                      d           |                     d           d S )Nr   s   foo)r1   rE   r   s    r   rJ  z-CBytesIOTest.test_cow_write.<locals>.mutation  s)    JJqMMMKKr   rP  rQ  s     r   test_cow_writezCBytesIOTest.test_cow_write  s-    	  	  	  	)))))r   c                     |                      d          }|                                fd}|                     |           d S )Ns   fooooooc                 2    |                                 d S r   )r8  )rP   r3  s    r   rJ  z0CBytesIOTest.test_cow_setstate.<locals>.mutation  s    u%%%%%r   )r   r.  rM  )r
   rP   rJ  r3  s      @r   test_cow_setstatezCBytesIOTest.test_cow_setstate  sZ     Z((""$$	& 	& 	& 	& 	&)))))r   c                     t          d          }t          j        |          }|                     |          }|                     t          j        |          |           d S )Ni   )r   rB  rI  r   r(   )r
   barL  rP   s       r   test_cow_mutablezCBytesIOTest.test_cow_mutable   sU    
 t__$$R  ,,f55555r   N)r   r   r   rA  r   r   r<   r4  r9  r   r>  cpython_onlyrG  rM  rR  rU  rX  r[  r   r   r   r,  r,    s        jG2	: 	: 	:P P P  'LH H H7 7 7 * * * * * * * * * 6 6 6 6 6r   r,  c                   <    e Zd Zej        Zej        Zd Zd Zd Z	dS )CStringIOTestc                    |                      d          }|                     |          }|                     |                                |           |                     |                    |          t          |                     |                     |                                t          |                     |                     |                                |           |                     |                    |          t          |                     |                     |                                t          |          dz             |                     |                                ||z              d S )Nu   𠌊𠍇r_   )r   r   r(   rL   rE   rh   r7   rO   s      r   test_widecharzCStringIOTest.test_widechar0  s+   ll122S!!))3///S))3s88444s3xx000))3///S))3s88444s3xx!|444))3955555r   c                    |                                  }|                                }|                     t          |          d           |                     |d         t
                     |                     |d         t
                     |                     |d         t                     |d         !|                     |d         t                     |                                 | 	                    t          |j                   d S )Nr%   r   r#   r_   r/   )r   r.  r(   rh   r/  r  r0  r1  rM   r2   rN   r2  s      r   r4  zCStringIOTest.test_getstate<  s    ""$$UQ'''eAh,,,eAh,,,eAh,,,8!!%(D111*e&899999r   c                 H   |                                  }|                    d           |                    dddddif           |                     t          |j        d           |                     t          |j        d           |                     t          |j        d	           |                     t          |j        d
           |                     t          |j        d           |                     t          |j        d           |                     t          |j        d           |                     t          |j                   |                     t          |j        d           |                                 |                     t          |j        d           d S )N)no errorr   r   Nrc  rK   r   rX   r/   )rK   rG   r   N)rK   rK   r]   N)r   rK   r   N)rK   r   r   N)rK   rK   r0   N)rK   rK   r   r   )zlen-testr   )r   rK   r   N)r   r8  r2   rN   r3   rM   r   s     r   r9  zCStringIOTest.test_setstateH  sj   6777JA{;<<<*e&8:LMMM*e&8:LMMM)U%79KLLL)U%79KLLL)U%79LMMM)U%7HHH)U%7III)U%7888)U%7;;;*e&8:QRRRRRr   N)
r   r   r   rA  r  r   r<   r`  r4  r9  r   r   r   r^  r^  *  sV        kG2
6 
6 
6
: 
: 
:S S S S Sr   r^  c                   B    e Zd Zej        Z G d dej                  ZdS )CStringIOPickleTestc                       e Zd Zd Zd ZdS )CStringIOPickleTest.ioclassc           	      l    t          j        t          j        t          j        |i |                    S r   )r   r   r   rA  r  r!  s      r   r%  z#CStringIOPickleTest.ioclass.__new__^  s+    <R[$-I&-I-I J JKKKr   c                     d S r   r   r'  s      r   r   z$CStringIOPickleTest.ioclass.__init__`  r(  r   Nr)  r   r   r   r   rg  ]  s5        	L 	L 	L	 	 	 	 	r   r   N)r   r   r   rA  r<   r  r   r   r   r   re  re  Z  sI        2    "+     r   re  r   )r*  unittesttestr   rA  _pyior   r   rB  r   r   r:   TestCaser   r   r  r  r,  r^  re  r   mainr   r   r   <module>ro     sd   
        				      



       *0 *0 *0 *0 *0 *0 *0 *0Zi% i% i% i% i% i% i% i%XmB mB mB mB mBO%8(:K mB mB mB`S* S* S* S* S* S* S* S*l5 5 5 5 5_&9$h&75 5 5"    ?H,=   U6 U6 U6 U6 U6= U6 U6 U6n-S -S -S -S -SN -S -S -S`    .    zHMOOOOO r   