a �DOg�l�@svddlZddlZddlZddlZddlZddlZddlmZej dvrTddl m Z ndZ ddl Z ddl mZmZmZmZhd�Zeed�r�e�ej�e�ej�dZeZeed �p�ejjZeZd5d d�Zdd�Zz e jZWne �y�eZYn0Gdd�d�Z!Gdd�d�Z"z e j#Z#Wn&e �yBGdd�de$e%�Z#Yn0Gdd�dej&d�Z'e j'�(e'�Gdd�de'�Z)e j)�(e)�ddl*m+Z+e)�(e+�Gdd�de'�Z,e j,�(e,�Gdd �d e,�Z-Gd!d"�d"e,�Z.Gd#d$�d$e-�Z/Gd%d&�d&e-�Z0Gd'd(�d(e,�Z1Gd)d*�d*e0e/�Z2Gd+d,�d,e)�Z+Gd-d.�d.e'�Z3e j3�(e3�Gd/d0�d0ej4�Z5Gd1d2�d2e3�Z6Gd3d4�d4e6�Z7dS)6�N)� allocate_lock>�cygwin�win32)�setmode)�__all__�SEEK_SET�SEEK_CUR�SEEK_END>r��� SEEK_HOLEi Zgettotalrefcount�r�����Tc Cs�t|t�st�|�}t|tttf�s0td|��t|t�sFtd|��t|t�s\td|��|durzt|t�sztd|��|dur�t|t�s�td|��t|�}|td�s�t|�t|�kr�t d|��d|v} d|v} d |v} d |v} d |v} d |v}d |v}d|v�rD| �s"| �s"| �s"| �r*t d��ddl }|� dt d�d} |�rX|�rXt d��| | | | dk�rvt d��| �s�| �s�| �s�| �s�t d��|�r�|du�r�t d��|�r�|du�r�t d��|�r�|du�r�t d��|�r|dk�rddl }|� dt d�t|| �rd�pd| �r"d�p$d| �r2d �p4d| �rBd �pDd| �rRd �pTd||d�}|}�z"d}|dk�s�|dk�r�|���r�d}d}|dk�r�t}zt�|���j}Wnttf�y�Yn0|dk�r�|}|dk�r�t d ��|dk�r |�r|WSt d!��| �rt||�}n<| �s0| �s0| �r��d�}|sdS|�d�dp&t|�}�dkr:t|��}|S)Nr � r)r�findr"�min)Z readahead�n�rM�sizerErF� nreadaheads  z#IOBase.readline..nreadaheadcSsdS�Nr rErErErErFr�!sr� is not an integerrr�) �hasattr� __index__r/r � bytearrayr"�read�endswithr)rMr�r�� size_index�resrrEr�rF�readline s&      zIOBase.readlinecCs |��|SrUrjrerErErF�__iter__6szIOBase.__iter__cCs|��}|st�|SrU)r�� StopIteration�rM�linerErErF�__next__:szIOBase.__next__cCsP|dus|dkrt|�Sd}g}|D]&}|�|�|t|�7}||kr$qLq$|S�Nr)�list�appendr")rM�hintr��linesr�rErErF� readlines@s  zIOBase.readlinescCs |��|D]}|�|�q dSrU)rk�write)rMr�r�rErErF� writelinesRszIOBase.writelines)r)N)N)N)N)N)r)N)rQrRrSr^r_rfrhrlrmr5rprrrurvrwrxry�propertyrnrkr}r~r,r)r�r�r�r�r�rErErErFr[;s4"         * r[)� metaclassc@s.eZdZd dd�Zdd�Zdd�Zdd �Zd S) � RawIOBasercCsP|dur d}|dkr|��St|���}|�|�}|dur>dS||d�=t|�S)Nrr)�readallr�r��readintor)rMr�rr�rErErFr�ms   zRawIOBase.readcCs4t�}|�t�}|sq ||7}q|r,t|�S|SdSrU)r�r�r*r)rMr��datarErErFr�~s  zRawIOBase.readallcCs|�d�dS)Nr�r`�rMrrErErFr��szRawIOBase.readintocCs|�d�dS�Nr�r`r�rErErFr��szRawIOBase.writeN)r)rQrRrSr�r�r�r�rErErErFr�_s r�)r(c@sHeZdZddd�Zddd�Zdd�Zdd �Zd d �Zd d �Zdd�Z dS)�BufferedIOBasercCs|�d�dS�Nr�r`r�rErErFr��szBufferedIOBase.readcCs|�d�dS)N�read1r`r�rErErFr��szBufferedIOBase.read1cCs|j|dd�S)NF�r��� _readintor�rErErFr��s zBufferedIOBase.readintocCs|j|dd�S)NTr�r�r�rErErF� readinto1�s zBufferedIOBase.readinto1cCsVt|t�st|�}|�d�}|r0|�t|��}n|�t|��}t|�}||d|�<|S�N�B)r� memoryview�castr�r"r�)rMrr�r�r�rErErFr��s   zBufferedIOBase._readintocCs|�d�dSr�r`r�rErErFr��s zBufferedIOBase.writecCs|�d�dS�N�detachr`rerErErFr��szBufferedIOBase.detachN)r)r) rQrRrSr�r�r�r�r�r�r�rErErErFr��s    r�c@s�eZdZdd�Zd#dd�Zdd�Zd$d d �Zd d �Zd d�Zdd�Z dd�Z e dd��Z e dd��Z e dd��Ze dd��Zdd�Zdd�Zdd �Zd!d"�ZdS)%�_BufferedIOMixincCs ||_dSrU��_raw�rMr@rErErF�__init__sz_BufferedIOMixin.__init__rcCs"|j�||�}|dkrtd��|S)Nrz#seek() returned an invalid position)r@r_r.)rMrbrcZ new_positionrErErFr_sz_BufferedIOMixin.seekcCs|j��}|dkrtd��|S)Nrz#tell() returned an invalid position)r@rfr.rirErErFrfs z_BufferedIOMixin.tellNcCs4|��|��|��|dur(|��}|j�|�SrU)rkryrlrfr@rhrirErErFrh%s z_BufferedIOMixin.truncatecCs|jrtd��|j��dS)N�flush on closed file)rnr#r@rlrerErErFrl6sz_BufferedIOMixin.flushcCs8|jdur4|js4z|��W|j��n |j��0dSrU)r@rnrlr5rerErErFr5;s z_BufferedIOMixin.closecCs*|jdurtd��|��|j}d|_|S)Nzraw stream already detached)r@r#rlr�r�rErErFr�Cs  z_BufferedIOMixin.detachcCs |j��SrU)r@rrrerErErFrrMsz_BufferedIOMixin.seekablecCs|jSrUr�rerErErFr@Psz_BufferedIOMixin.rawcCs|jjSrU)r@rnrerErErFrnTsz_BufferedIOMixin.closedcCs|jjSrU)r@r]rerErErFr]Xsz_BufferedIOMixin.namecCs|jjSrU)r@r4rerErErFr4\sz_BufferedIOMixin.modecCstd|jj�d���dS�Nzcannot pickle z object�r r\rQrerErErF� __getstate__`sz_BufferedIOMixin.__getstate__cCsL|jj}|jj}z |j}Wnty8d�||�YS0d�|||�SdS)Nz<{}.{}>z<{}.{} name={!r}>)r\rRrSr]r/�format)rM�modnameZclsnamer]rErErF�__repr__cs  z_BufferedIOMixin.__repr__cCs |j��SrU)r@r,rerErErFr,osz_BufferedIOMixin.filenocCs |j��SrU)r@r)rerErErFr)rsz_BufferedIOMixin.isatty)r)N)rQrRrSr�r_rfrhrlr5r�rrr�r@rnr]r4r�r�r,r)rErErErFr� s(         r�cs�eZdZdZd dd�Zdd�Zdd�Zdd �Z�fd d �Zd!d d�Z d"dd�Z dd�Z d#dd�Z dd�Z d$dd�Zdd�Zdd�Zdd�Z�ZS)%�BytesIONcCs&t�}|dur||7}||_d|_dSr�)r��_buffer�_pos)rMZ initial_bytes�bufrErErFr�~s zBytesIO.__init__cCs|jrtd��|j��S)Nz__getstate__ on closed file)rnr#�__dict__�copyrerErErFr��szBytesIO.__getstate__cCs|jrtd��t|j�S)Nzgetvalue on closed file)rnr#rr�rerErErF�getvalue�szBytesIO.getvaluecCs|jrtd��t|j�S)Nzgetbuffer on closed file)rnr#r�r�rerErErF� getbuffer�szBytesIO.getbuffercs"|jdur|j��t���dSrU)r��clear�superr5re�r\rErFr5�s  z BytesIO.closercCs�|jrtd��|durd}n2z |j}Wn tyFt|�d���Yn0|�}|dkr`t|j�}t|j�|jkrtdStt|j�|j|�}|j|j|�}||_t |�S)N�read from closed filerr�r�) rnr#r�r/r r"r�r�r�r)rMr�r�ZnewposrrErErFr��s"   z BytesIO.readcCs |�|�SrU)r�r�rErErFr��sz BytesIO.read1cCs�|jrtd��t|t�r td��t|��}|j}Wd�n1sD0Y|dkrZdS|j}|t|j �kr�d|t|j �}|j |7_ ||j |||�<|j|7_|S)N�write to closed file� can't write str to binary streamr�) rnr#rrr r��nbytesr�r"r�)rMr�viewr�rbZpaddingrErErFr��s  $z BytesIO.writercCs�|jrtd��z |j}Wn ty8t|�d���Yn0|�}|dkrf|dkr^td|f��||_nD|dkr�td|j|�|_n(|dkr�tdt|j�|�|_ntd��|jS)Nzseek on closed filer�r�negative seek position %rr r zunsupported whence value) rnr#r�r/r r��maxr"r�)rMrbrc� pos_indexrErErFr_�s"  z BytesIO.seekcCs|jrtd��|jS)N�tell on closed file)rnr#r�rerErErFrf�sz BytesIO.tellcCsv|jrtd��|dur|j}nHz |j}Wn tyHt|�d���Yn0|�}|dkrftd|f��|j|d�=|S)Nztruncate on closed filer�rznegative truncate position %r)rnr#r�r�r/r r�)rMrbr�rErErFrh�s   zBytesIO.truncatecCs|jrtd��dS�Nr{Tr|rerErErFrv�szBytesIO.readablecCs|jrtd��dSr�r|rerErErFrx�szBytesIO.writablecCs|jrtd��dSr�r|rerErErFrr�szBytesIO.seekable)N)r)r)r)N)rQrRrSr�r�r�r�r�r5r�r�r�r_rfrhrvrxrr� __classcell__rErEr�rFr�vs      r�c@steZdZefdd�Zdd�Zdd�Zddd �Zdd d �Zdd d�Z ddd�Z ddd�Z dd�Z dd�Z ddd�ZdS) r2cCsF|��std��t�||�|dkr,td��||_|��t�|_dS)Nz "raw" argument must be readable.r�invalid buffer size) rvr.r�r�r#� buffer_size�_reset_read_buf�Lock� _read_lock�rMr@r�rErErFr�s zBufferedReader.__init__cCs |j��SrU)r@rvrerErErFrvszBufferedReader.readablecCsd|_d|_dS)Nr�r)� _read_buf� _read_posrerErErFr� szBufferedReader._reset_read_bufNcCsL|dur|dkrtd��|j�|�|�Wd�S1s>0YdS)Nrzinvalid number of bytes to read)r#r��_read_unlockedr�rErErFr�$szBufferedReader.readc Cs�d}d}|j}|j}|dus$|dkr�|��t|jd�rj|j��}|durZ||d�pXdS||d�|S||d�g}d}|j��}||vr�|}q�|t|�7}|�|�q|d� |�p�|St|�|} || kr�|j|7_||||�S||d�g}t |j |�} | |k�rH|j�| �}||v�r.|}�qH| t|�7} |�|��qt || �}d� |�} | |d�|_d|_| �r�| d|�S|S)Nr�)r�Nrr�r) r�r�r�r�r@r�r�r"r��joinr�r�r�) rMr�Z nodata_valZ empty_valuesr�rb�chunk�chunksZ current_size�availZwanted�outrErErFr�1sL             zBufferedReader._read_unlockedrcCs4|j�|�|�Wd�S1s&0YdSrU)r��_peek_unlockedr�rErErFreszBufferedReader.peekcCsrt||j�}t|j�|j}||ks,|dkrb|j|}|j�|�}|rb|j|jd�||_d|_|j|jd�Sr�)r�r�r"r�r�r@r�)rMr�ZwantZhaveZto_read�currentrErErFr�os   zBufferedReader._peek_unlockedrcCsj|dkr|j}|dkrdS|j�6|�d�|�t|t|j�|j��Wd�S1s\0YdS)Nrr�r )r�r�r�r�r�r"r�r�r�rErErFr�zs �zBufferedReader.read1cCs t|t�st|�}|jdkr dS|�d�}d}|j��|t|�kr�tt|j�|jt|��}|r�|j|j|j|�||||�<|j|7_||7}|t|�kr�q�t|�||j kr�|j � ||d��}|s�q�||7}n|r�|s�|� d�s�q�|r6|r6q�q6Wd�n1�s0Y|S)Nrr�r ) rr�r�r�r�r"r�r�r�r�r@r�r�)rMr�r��writtenr�r�rErErFr��s6    �   $zBufferedReader._readintocCst�|�t|j�|jSrU)r�rfr"r�r�rerErErFrf�szBufferedReader.tellcCsp|tvrtd��|j�F|dkr4|t|j�|j8}t�|||�}|��|Wd�S1sb0YdS)N�invalid whence valuer ) �valid_seek_flagsr#r�r"r�r�r�r_r�rarErErFr_�szBufferedReader.seek)N)N)r)r)r)r)rQrRrSr*r�rvr�r�r�rr�r�r�rfr_rErErErFr2s  4 .r2c@s\eZdZefdd�Zdd�Zdd�Zddd �Zd d �Zd d �Z dd�Z ddd�Z dd�Z dS)r1cCsF|��std��t�||�|dkr,td��||_t�|_t�|_ dS)Nz "raw" argument must be writable.rr�) rxr.r�r�r#r�r�� _write_bufr�� _write_lockr�rErErFr��s zBufferedWriter.__init__cCs |j��SrU)r@rxrerErErFrx�szBufferedWriter.writablec Cst|t�rtd��|j��|jr(td��t|j�|jkr@|� �t|j�}|j� |�t|j�|}t|j�|jkr�z |� �Wnnt y�}zVt|j�|jkr�t|j�|j}||8}|jd|j�|_t |j |j |��WYd}~n d}~00|Wd�S1�s 0YdS)Nr�r�)rrr r�rnr#r"r�r��_flush_unlocked�extend�BlockingIOError�errno�strerror)rMr�beforer��eZoveragerErErFr��s(    &zBufferedWriter.writeNcCsP|j�6|��|dur"|j��}|j�|�Wd�S1sB0YdSrU)r�r�r@rfrhrirErErFrh�s  zBufferedWriter.truncatecCs2|j�|��Wd�n1s$0YdSrU)r�r�rerErErFrlszBufferedWriter.flushcCs�|jrtd��|jr�z|j�|j�}Wnty@td��Yn0|durXttjdd��|t |j�ksn|dkrvt d��|jd|�=qdS)Nr�zHself.raw should implement RawIOBase: it should not raise BlockingIOErrorz)write could not complete without blockingrz*write() returned incorrect number of bytes) rnr#r�r@r�r�� RuntimeErrorr��EAGAINr"r.�rMr�rErErFr�s �zBufferedWriter._flush_unlockedcCst�|�t|j�SrU)r�rfr"r�rerErErFrfszBufferedWriter.tellrcCsP|tvrtd��|j�&|��t�|||�Wd�S1sB0YdS)Nr�)r�r#r�r�r�r_rarErErFr_s zBufferedWriter.seekcCs�|j�0|jdus|jr(Wd�dSWd�n1s<0Yz<|��W|j�|j��Wd�q�1sx0Yn2|j�|j��Wd�n1s�0Y0dSrU)r�r@rnrlr5rerErErFr5 s. *�zBufferedWriter.close)N)r) rQrRrSr*r�rxr�rhrlr�rfr_r5rErErErFr1�s   r1c@s�eZdZefdd�Zddd�Zdd�Zdd �Zdd d �Zd d d�Z dd�Z dd�Z dd�Z dd�Z dd�Zdd�Zedd��ZdS)!�BufferedRWPaircCs<|��std��|��s td��t||�|_t||�|_dS)Nz#"reader" argument must be readable.z#"writer" argument must be writable.)rvr.rxr2�readerr1�writer)rMr�r�r�rErErFr�@s  zBufferedRWPair.__init__rcCs|dur d}|j�|�S�Nr)r�r�r�rErErFr�NszBufferedRWPair.readcCs |j�|�SrU)r�r�r�rErErFr�SszBufferedRWPair.readintocCs |j�|�SrU)r�r�r�rErErFr�VszBufferedRWPair.writercCs |j�|�SrU)r�rr�rErErFrYszBufferedRWPair.peekcCs |j�|�SrU)r�r�r�rErErFr�\szBufferedRWPair.read1cCs |j�|�SrU)r�r�r�rErErFr�_szBufferedRWPair.readinto1cCs |j��SrU)r�rvrerErErFrvbszBufferedRWPair.readablecCs |j��SrU)r�rxrerErErFrxeszBufferedRWPair.writablecCs |j��SrU)r�rlrerErErFrlhszBufferedRWPair.flushcCs*z|j��W|j��n |j��0dSrU)r�r5r�rerErErFr5ks zBufferedRWPair.closecCs|j��p|j��SrU)r�r)r�rerErErFr)qszBufferedRWPair.isattycCs|jjSrU)r�rnrerErErFrntszBufferedRWPair.closedN)r)r)r)rQrRrSr*r�r�r�r�rr�r�rvrxrlr5r)r�rnrErErErFr�0s    r�c@sjeZdZefdd�Zddd�Zdd�Zdd d �Zdd d �Zd d�Z ddd�Z ddd�Z dd�Z dd�Z dS)r0cCs(|��t�|||�t�|||�dSrU)rur2r�r1r�rErErFr��szBufferedRandom.__init__rcCs�|tvrtd��|��|jr^|j�*|j�|jt|j�d�Wd�n1sT0Y|j�||�}|j�|� �Wd�n1s�0Y|dkr�t d��|S)Nr�r rz seek() returned invalid position) r�r#rlr�r�r@r_r�r"r�r.rarErErFr_�s8&zBufferedRandom.seekcCs|jrt�|�St�|�SdSrU)r�r1rfr2rerErErFrf�s zBufferedRandom.tellNcCs|dur|��}t�||�SrU)rfr1rhrirErErFrh�szBufferedRandom.truncatecCs |dur d}|��t�||�Sr�)rlr2r�r�rErErFr��szBufferedRandom.readcCs|��t�||�SrU)rlr2r�r�rErErFr��szBufferedRandom.readintocCs|��t�||�SrU)rlr2rr�rErErFr�szBufferedRandom.peekrcCs|��t�||�SrU)rlr2r�r�rErErFr��szBufferedRandom.read1cCs|��t�||�SrU)rlr2r�r�rErErFr��szBufferedRandom.readinto1cCsZ|jrN|j�2|j�|jt|j�d�|��Wd�n1sD0Yt�||�Sr�) r�r�r@r_r�r"r�r1r�r�rErErFr��s &zBufferedRandom.write)r)N)N)r)r)rQrRrSr*r�r_rfrhr�r�rr�r�r�rErErErFr0ys      r0cs�eZdZdZdZdZdZdZdZdZ d0dd�Z dd �Z d d �Z d d �Z dd�Zd1dd�Zd2dd�Zdd�Zdd�Zdd�Zefdd�Zdd�Zd3dd�Z�fd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zed,d-��Zed.d/��Z �Z!S)4r(rFNTr c CsH|jdkr0z|jrt�|j�Wd|_nd|_0t|t�rBtd��t|t�rb|}|dkrftd��nd}t|t �s~td|f��t |�t d�ks�td|f��t dd�|D��d ks�|� d �d kr�td ��d |vr�d |_ d |_tjtjB}nTd|vr�d |_d}n@d|v�rd |_tjtjB}n"d|v�r>d |_d |_tjtjB}d |v�rTd |_d |_|j�rp|j�rp|tjO}n|j�r�|tjO}n |tjO}|ttdd�O}ttdd��p�ttdd�}||O}d}�zT|dk�r@|�s�td��|du�r�t�||d�}n0|||�}t|t��std��|dk�r*td��|}|�s@t�|d�||_t�|�} z(t�| j��rvt t!j"t�#t!j"�|��Wnt$�y�Yn0t| dd�|_%|j%d k�r�t&|_%t'�r�t'|tj(�||_)|j�rzt�*|dt+�Wn6t�y} z| j!t!j,k�r�WYd} ~ n d} ~ 00Wn"|du�r6t�|��Yn0||_dS)Nrrz$integer argument expected, got floatznegative file descriptorzinvalid mode: %szxrwab+css|]}|dvVqdS)ZrwaxNrE)�.0�crErErF� �r�z"FileIO.__init__..r rzKMust have exactly one of create/read/write/append mode and at most one plusrTr rr�O_BINARYZ O_NOINHERIT� O_CLOEXECz'Cannot use closefd=False with file namei�zexpected integer from openerzNegative file descriptorFr-)-�_fd�_closefdrr5r�floatr rr#rr!�sum�count�_created� _writable�O_EXCL�O_CREAT� _readable�O_TRUNC� _appending�O_APPEND�O_RDWR�O_RDONLY�O_WRONLY�getattrrGr.�set_inheritabler+�stat�S_ISDIR�st_mode�IsADirectoryErrorr�ZEISDIRr�r/�_blksizer*�_setmoder�r]�lseekr ZESPIPE) rMr6r4r;r�fd�flagsZnoinherit_flagZowned_fdZfdfstatr�rErErFr��s�     $        �        �    zFileIO.__init__cCsB|jdkr>|jr>|js>ddl}|jd|ftd|d�|��dS)Nrzunclosed file %rr )� stacklevel�source)r�rrnr$r%�ResourceWarningr5)rMr$rErErFrpEs �zFileIO.__del__cCstd|jj�d���dSr�r�rerErErFr�LszFileIO.__getstate__cCsnd|jj|jjf}|jr"d|Sz |j}Wn(tyTd||j|j|jfYS0d|||j|jfSdS)Nz%s.%sz <%s [closed]>z<%s fd=%d mode=%r closefd=%r>z<%s name=%r mode=%r closefd=%r>) r\rRrSrnr]r/r�r4r)rM� class_namer]rErErFr�Os�  � �zFileIO.__repr__cCs|jstd��dS)NzFile not open for reading)rrZrerErErFrw]szFileIO._checkReadablecCs|jstd��dS)NzFile not open for writing)rrZrsrErErFryaszFileIO._checkWritablecCsR|��|��|dus |dkr(|��Szt�|j|�WStyLYdS0dSr�)rkrwr�rr�r�r�r�rErErFr�es z FileIO.readcCs�|��|��t}z6t�|jdt�}t�|j�j}||krH||d}Wnt y\Yn0t �}t |�|kr�t |�}|t |t�7}|t |�}zt� |j|�}Wnty�|r�Yq�YdS0|s�q�||7}qdt|�Srd)rkrwr*rrr�rr+�st_sizer.r�r"r�r�r�r)rM�bufsizerb�endrAr�r�rErErFr�us2     zFileIO.readallcCs4t|��d�}|�t|��}t|�}||d|�<|Sr�)r�r�r�r")rMr�mr�r�rErErFr��s  zFileIO.readintocCs:|��|��zt�|j|�WSty4YdS0dSrU)rkryrr�r�r�r�rErErFr��s  z FileIO.writecCs*t|t�rtd��|��t�|j||�S)Nzan integer is required)rrr rkrrr�rarErErFr_�s z FileIO.seekcCs|��t�|jdt�Sr�)rkrrr�rrerErErFrf�sz FileIO.tellcCs2|��|��|dur |��}t�|j|�|SrU)rkryrfr� ftruncater�r�rErErFrh�s zFileIO.truncatecs8|js4z |jrt�|j�Wt���n t���0dSrU)rnrrr5r�r�rer�rErFr5�s z FileIO.closecCsD|��|jdur>z |��Wnty6d|_Yn0d|_|jS)NFT)rk� _seekablerfr.rerErErFrr�s    zFileIO.seekablecCs|��|jSrU)rkrrerErErFrv�szFileIO.readablecCs|��|jSrU)rkrrerErErFrx�szFileIO.writablecCs|��|jSrU)rkr�rerErErFr,�sz FileIO.filenocCs|��t�|j�SrU)rkrr)r�rerErErFr)�sz FileIO.isattycCs|jSrU)rrerErErFr;�szFileIO.closefdcCsJ|jr|jrdSdSn0|jr,|jr&dSdSn|jrB|jr�s z"IncrementalNewlineDecoder.getstatecCs8|\}}t|d@�|_|jdur4|j�||d?f�dSr�)�boolr1r/�setstate)rM�stater�r?rErErFrA�s z"IncrementalNewlineDecoder.setstatecCs$d|_d|_|jdur |j��dS)NrF)r0r1r/�resetrerErErFrC�s zIncrementalNewlineDecoder.resetr r �cCs d|jS)N)Nr6r4)r4r6r5)r6r5)r4r5)r4r6r5)r0rerErErFr)�s�z"IncrementalNewlineDecoder.newlinesN)r+)F) rQrRrSr�r7r>rArCr8r9r:r�r)rErErErFr*]s   r*c@sreZdZdZdZdNdd�Zdd�ZdOdd �Zd d �Ze d d ��Z e dd��Z e dd��Z e dd��Z e dd��Zddeddd�dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Ze d#d$��Ze d%d&��Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�ZdPd3d4�Zd5d6�Zd7d8�Z dQd:d;�Z!dd?�Z#dRd@dA�Z$dBdC�Z%dSdDdE�Z&dTdFdG�Z'dHdI�Z(dUdJdK�Z)e dLdM��Z*dS)Vr3iNFc Cs$|�|�|durrzt�|���}Wnttfy:Yn0|durrz ddl}Wntyfd}Yn 0|�d�}t |t �s�t d|��t � |�js�d}t||��|dur�d}n$t |t �s�t d|��tr�t �|�||_d|_d|_d|_|j��|_|_t|jd �|_|�|||||�dS) Nr�asciiFrzG%r is not a text encoding; use codecs.open() to handle arbitrary codecsr+rrr�)�_check_newliner�device_encodingr,r/rZ�locale� ImportError�getpreferredencodingrrr#r,�lookup�_is_text_encoding� LookupError� _CHECK_ERRORS� lookup_errorr��_decoded_chars�_decoded_chars_used� _snapshotrDrrr#�_tellingr�� _has_read1� _configure) rMrDr8r9r:rB� write_throughrHrtrErErFr��s@             �zTextIOWrapper.__init__cCs>|dur$t|t�s$tdt|�f��|dvr:td|f��dS)Nzillegal newline type: %r)Nrr6r4r5zillegal newline value: %r)rrr �typer#)rMr:rErErFrF�szTextIOWrapper._check_newlinecCs�||_||_d|_d|_d|_| |_|du|_||_|dk|_|pHt j |_ ||_ ||_ |jr�|��r�|j��}|dkr�z|���d�Wnty�Yn0dS)N�rr)� _encoding�_errors�_encoder�_decoder� _b2cratio�_readuniversal�_readtranslate�_readnl�_writetranslater�linesep�_writenl�_line_buffering�_write_throughr#rxrDrf� _get_encoderrArM)rMr8r9r:rBrV�positionrErErFrUs&     zTextIOWrapper._configurecCs|d�|jj|jj�}z |j}Wnty0Yn0|d�|�7}z |j}Wnty\Yn0|d�|�7}|d�|j�S)Nz<{}.{}z name={0!r}z mode={0!r}z encoding={0!r}>)r�r\rRrSr]r/r4r8)rMrAr]r4rErErFr�'s �    zTextIOWrapper.__repr__cCs|jSrU)rYrerErErFr88szTextIOWrapper.encodingcCs|jSrU)rZrerErErFr9<szTextIOWrapper.errorscCs|jSrU)rdrerErErFrB@szTextIOWrapper.line_bufferingcCs|jSrU)rererErErFrVDszTextIOWrapper.write_throughcCs|jSrU)r�rerErErFrDHszTextIOWrapper.buffer)r8r9r:rBrVcCs�|jdur*|dus"|dus"|tur*td��|durH|durB|j}q^d}nt|t�s^td|��|durn|j}nt|t�s�td|��|tur�|j}|� |�|dur�|j }|dur�|j }|� �|� |||||�dS)NzPIt is not possible to set the encoding or newline of stream after the first readr+rr)r\�EllipsisrZrZrrr rYr`rFrBrVrlrU)rMr8r9r:rBrVrErErF� reconfigureLs> ����      �zTextIOWrapper.reconfigurecCs|jrtd��|jSrz)rnr#r#rerErErFrruszTextIOWrapper.seekablecCs |j��SrU)rDrvrerErErFrvzszTextIOWrapper.readablecCs |j��SrU)rDrxrerErErFrx}szTextIOWrapper.writablecCs|j��|j|_dSrU)rDrlr#rSrerErErFrl�s zTextIOWrapper.flushcCs8|jdur4|js4z|��W|j��n |j��0dSrU)rDrnrlr5rerErErFr5�s zTextIOWrapper.closecCs|jjSrU)rDrnrerErErFrn�szTextIOWrapper.closedcCs|jjSrU)rDr]rerErErFr]�szTextIOWrapper.namecCs |j��SrU)rDr,rerErErFr,�szTextIOWrapper.filenocCs |j��SrU)rDr)rerErErFr)�szTextIOWrapper.isattycCs�|jrtd��t|t�s(td|jj��t|�}|js<|j oBd|v}|rf|jrf|j dkrf|� d|j �}|j pr|� �}|�|�}|j�|�|j r�|s�d|vr�|��|�d�d|_|jr�|j��|S)Nr�zcan't write %s to text streamr6r4r)rnr#rrr r\rQr"rardrcr;r[rf�encoderDr�rl�_set_decoded_charsrRr\rC)rMr(�lengthZhaslf�encoderrrErErFr��s( �    zTextIOWrapper.writecCst�|j�}||j�|_|jSrU)r,�getincrementalencoderrYrZr[)rMZ make_encoderrErErFrf�s  zTextIOWrapper._get_encodercCs2t�|j�}||j�}|jr(t||j�}||_|SrU)r,�getincrementaldecoderrYrZr^r*r_r\)rMZ make_decoderr/rErErF� _get_decoder�s    zTextIOWrapper._get_decodercCs||_d|_dSr�)rPrQ)rM�charsrErErFrk�sz TextIOWrapper._set_decoded_charscCsF|j}|dur|j|d�}n|j|||�}|jt|�7_|SrU)rQrPr")rMr��offsetrqrErErF�_get_decoded_chars�s z TextIOWrapper._get_decoded_charscCs$|j|krtd��|j|8_dS)Nz"rewind decoded_chars out of bounds)rQ�AssertionErrorr�rErErF�_rewind_decoded_chars�s z#TextIOWrapper._rewind_decoded_charscCs�|jdurtd��|jr&|j��\}}|jr<|j�|j�}n|j�|j�}| }|j� ||�}|� |�|r�t |�t |j �|_ nd|_ |jr�|||f|_| S)Nz no decoderrX)r\r#rSr>rTrDr�� _CHUNK_SIZEr�r7rkr"rPr]rR)rM� dec_buffer� dec_flags� input_chunk�eofZ decoded_charsrErErF� _read_chunk�s  zTextIOWrapper._read_chunkrcCs(||d>B|d>B|d>Bt|�d>BS)N�@����)r@)rMrgrx� bytes_to_feed�need_eof� chars_to_skiprErErF� _pack_cookie�s � �zTextIOWrapper._pack_cookiecCsJt|d�\}}t|d�\}}t|d�\}}t|d�\}}|||t|�|fS)Nl)�divmodr@)rMZbigint�restrgrxr�r�r�rErErF�_unpack_cookie s zTextIOWrapper._unpack_cookiec CsP|jstd��|jstd��|��|j��}|j}|dusF|jdurX|j rTt d��|S|j\}}|t |�8}|j }|dkr�|� ||�S|��}�z�t|j|�}d}|dk�r"|�d|f�t |�|d|���} | |k�r|��\} } | s�| }|| 8}�q4|t | �8}d}q�||8}|d}q�d}|�d|f�||} |} |dk�rb|� | | �W|�|�Sd}d}d}t|t |��D]x}|d7}|t |�|||d���7}|��\}}|�s�||k�r�| |7} ||8}|dd} }}||k�r|�q"�q||t |jdd d ��7}d }||k�r"td ��|� | | |||�W|�|�S|�|�0dS) N�!underlying stream is not seekablez(telling position disabled by next() callzpending decoded textrr r�r FTr2z'can't reconstruct logical file position)r#rZrSr.rlrDrfr\rRrPrtr"rQr�r>rr]rAr7�range)rMrgr/rxZ next_inputr�� saved_stateZ skip_bytesZ skip_backr�r�d� start_posZ start_flagsZ bytes_fedr�Z chars_decoded�irwrErErFrf s�           �     � �zTextIOWrapper.tellcCs$|��|dur|��}|j�|�SrU)rlrfrDrhrirErErFrhs szTextIOWrapper.truncatecCs*|jdurtd��|��|j}d|_|S)Nzbuffer is already detached)rDr#rlr�)rMrDrErErFr�y s  zTextIOWrapper.detachc s��fdd�}�jrtd���js(td��|tkrN|dkr@td��d}���}nZ|tkr�|dkrftd������j� d|�}�� d�d�_ �j r��j � �||�|S|dkr�td |f��|dkr�td |f�������|�\}}}}} �j� |��� d�d�_ |dk�r*�j �r*�j � �n@�j �s>|�s>| �rj�j �pL����_ �j �d |f�|d f�_ | �r��j�|�} �� �j �| |��|| f�_ t�j�| k�r�td ��| �_||�|S) NcsFz�jp���}Wnty$Yn0|dkr:|�d�n|��dSr�)r[rfrMrArC)rgrmrerErF�_reset_encoder� s  z*TextIOWrapper.seek.._reset_encoderr�r�rz#can't do nonzero cur-relative seeksz#can't do nonzero end-relative seeksrzunsupported whence (%r)r�r�z#can't restore logical file position)rnr#r#rZrrfr rlrDr_rkrRr\rCr�rprAr�r7r"rPr.rQ) rMZcookiercr�rgr�rxr�r�r�ryrErerFr_� s`    �       � zTextIOWrapper.seekcCs�|��|durd}n2z |j}Wn ty@t|�d���Yn0|�}|jpT|��}|dkr�|��|j|j� �dd�}|� d�d|_ |Sd}|�|�}t |�|kr�|s�|� � }||�|t |��7}q�|SdS)Nrr�rTr2rF)rwr�r/r r\rprsr7rDr�rkrRr"r{)rMr�r�r/rArzrErErFr�� s,  �   zTextIOWrapper.readcCs(d|_|��}|s$d|_|j|_t�|Srq)rSr�rRr#r�r�rErErFr�� szTextIOWrapper.__next__c Cs|jrtd��|durd}n2z |j}Wn tyFt|�d���Yn0|�}|��}d}|jsh|��d}}|jr�|� d|�}|dkr�|d}�q�nt |�}n�|j �rD|� d|�}|� d|�}|dkr�|dkr�t |�}n |d}�q�nX|dk�r|d}�q�n@||k�r|d}�q�n(||dk�r6|d}�q�n |d}�q�n(|� |j �}|dk�rl|t |j �}�q�|dk�r�t |�|k�r�|}�q�|� ��r�|j�r��q��q�|j�r�||��7}qp|�d �d|_|Sqp|dk�r�||k�r�|}|�t |�|�|d|�S) Nr�rr�rr6r r4r r)rnr#r�r/r rsr\rpr_r�r"r^r`r{rPrkrRru) rMr�r�r��startrb�endposZnlposZcrposrErErFr�� st             zTextIOWrapper.readlinecCs|jr|jjSdSrU)r\r)rerErErFr)N szTextIOWrapper.newlines)NNNFF)NNNFF)N)rrFr)N)r)N)N)+rQrRrSrvr�r�rFrUr�r�r8r9rBrVrDrhrirrrvrxrlr5rnr]r,r)r�rfrprkrsrur{r�r�rfrhr�r_r�r�r�r)rErErErFr3�sl� *� $     � )    *� c  K  ]r3csNeZdZd�fdd� Zdd�Zdd�Zed d ��Zed d ��Zd d�Z �Z S)�StringIOrr6csftt|�jt�dd|d�|dur(d|_|durbt|t�sNtd�t |�j ���|� |�|� d�dS)Nzutf-8� surrogatepass)r8r9r:Fz*initial_value must be str or None, not {0}r) r�r�r�r�rarrr r�rWrQr�r_)rMZ initial_valuer:r�rErFr�Z s� � zStringIO.__init__c CsX|��|jp|��}|��}|��z |j|j��dd�W|�|�S|�|�0dS)NTr2) rlr\rpr>rCr7rDr�rA)rMr/Z old_staterErErFr�j s �zStringIO.getvaluecCs t�|�SrU)�objectr�rerErErFr�t szStringIO.__repr__cCsdSrUrErerErErFr9y szStringIO.errorscCsdSrUrErerErErFr8} szStringIO.encodingcCs|�d�dSr�r`rerErErFr�� szStringIO.detach)rr6) rQrRrSr�r�r�r�r9r8r�r�rErEr�rFr�S s   r�)r rNNNTN)8r�abcr,r�r�sys�_threadrr��platform�msvcrtrr�iorrrr r�r��addr � SEEK_DATAr*r�r�dev_moderorNrGrJ� open_coder/rKrTrZr.r#�ABCMetar[�registerr��_ior(r�r�r�r2r1r�r0r'r-r*r3r�rErErErF�s�     � [    # =   g kCiIJY@ U&