B
    u9aTe                @   s8  d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ ej	dkrTd dl
mZ ndZd dlZd dlmZmZmZmZ d ddhZee dree j ee j d	ZeZd3ddZG dd dZG dd dZy
ejZW n( ek
r   G dd deeZY nX G dd dej dZ!ej!"e! G dd de!Z#ej#"e# d dl$m%Z% e#"e% G dd de!Z&ej&"e& G dd de&Z'G dd  d e&Z(G d!d" d"e'Z)G d#d$ d$e'Z*G d%d& d&e&Z+G d'd( d(e*e)Z,G d)d* d*e#Z%G d+d, d,e!Z-ej-"e- G d-d. d.ej.Z/G d/d0 d0e-Z0G d1d2 d2e0Z1dS )4    N)allocate_lock>   cygwinwin32)setmode)__all__SEEK_SETSEEK_CURSEEK_END      	SEEK_HOLEi    rTc          	   C   sz  t | tst| } t | tttfs0td|  t |tsFtd| t |ts\td| |d k	rzt |tsztd| |d k	rt |tstd| t|}|td st|t|krt	d| d|k}	d|k}
d	|k}d
|k}d|k}d|k}d|k}d|krD|	s"|s"|s"|r*t	ddd l
}|dtd d}
|rX|rXt	d|	|
 | | dkrvt	d|	s|
s|s|st	d|r|d k	rt	d|r|d k	rt	d|r|d k	rt	dt| |	rdpd|
rdpd |rd	pd |rd
pd |r,dp.d ||d}|}yd}|dksd|dk rl| rld}d}|dk rt}yt| j}W n ttfk
r   Y nX |dkr|}|dk rt	d|dkr|r|S t	d |rt||}n<|	s
|s
|rt||}n|
r(t||}nt	d!| |}|rB|S t|||||}|}||_|S    |   Y nX d S )"Nzinvalid file: %rzinvalid mode: %rzinvalid buffering: %rzinvalid encoding: %rzinvalid errors: %rzaxrwb+tUxr   wa+tbUz4mode U cannot be combined with 'x', 'w', 'a', or '+'r   z'U' mode is deprecatedr   Tz'can't have text and binary mode at oncer
   z)can't have read/write/append mode at oncez/must have exactly one of read/write/append modez-binary mode doesn't take an encoding argumentz+binary mode doesn't take an errors argumentz+binary mode doesn't take a newline argument )openerFr   zinvalid buffering sizezcan't have unbuffered text I/Ozunknown mode: %r)
isinstanceintosfspathstrbytes	TypeErrorsetlen
ValueErrorwarningswarnDeprecationWarningFileIOisattyDEFAULT_BUFFER_SIZEfstatfileno
st_blksizeOSErrorAttributeErrorBufferedRandomBufferedWriterBufferedReaderTextIOWrappermodeclose)filer1   	bufferingencodingerrorsnewlineclosefdr   ZmodesZcreatingZreadingZwritingZ	appendingZupdatingtextZbinaryr"   rawresultline_bufferingbsbuffer r?   /usr/lib/python3.7/_pyio.pyopen%   s    {




>




rA   c               @   s   e Zd Zdd ZdS )DocDescriptorc             C   s
   dt j S )Nz\open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True)

)rA   __doc__)selfobjtypr?   r?   r@   __get__   s    zDocDescriptor.__get__N)__name__
__module____qualname__rG   r?   r?   r?   r@   rB      s   rB   c               @   s   e Zd Ze Zdd ZdS )OpenWrapperc             O   s
   t ||S )N)rA   )clsargskwargsr?   r?   r@   __new__  s    zOpenWrapper.__new__N)rH   rI   rJ   rB   rC   rO   r?   r?   r?   r@   rK     s   rK   c               @   s   e Zd ZdS )UnsupportedOperationN)rH   rI   rJ   r?   r?   r?   r@   rP     s   rP   c               @   s   e Zd Zdd Zd5ddZdd Zd6d	d
Zdd ZdZdd Z	dd Z
dd Zd7ddZdd Zd8ddZdd Zd9ddZedd Zd:d d!Zd"d# Zd$d% Zd&d' Zd(d) Zd;d+d,Zd-d. Zd/d0 Zd<d1d2Zd3d4 ZdS )=IOBasec             C   s   t d| jj|f d S )Nz%s.%s() not supported)rP   	__class__rH   )rD   namer?   r?   r@   _unsupported<  s    zIOBase._unsupportedr   c             C   s   |  d d S )Nseek)rT   )rD   poswhencer?   r?   r@   rU   C  s    zIOBase.seekc             C   s   |  ddS )Nr   r
   )rU   )rD   r?   r?   r@   tellS  s    zIOBase.tellNc             C   s   |  d d S )Ntruncate)rT   )rD   rV   r?   r?   r@   rY   W  s    zIOBase.truncatec             C   s   |    d S )N)_checkClosed)rD   r?   r?   r@   flusha  s    zIOBase.flushFc             C   s    | j sz|   W d d| _ X d S )NT)_IOBase__closedr[   )rD   r?   r?   r@   r2   k  s    zIOBase.closec             C   s   y|    W n   Y nX d S )N)r2   )rD   r?   r?   r@   __del__v  s    zIOBase.__del__c             C   s   dS )NFr?   )rD   r?   r?   r@   seekable  s    zIOBase.seekablec             C   s    |   st|d krdn|d S )NzFile or stream is not seekable.)r^   rP   )rD   msgr?   r?   r@   _checkSeekable  s    zIOBase._checkSeekablec             C   s   dS )NFr?   )rD   r?   r?   r@   readable  s    zIOBase.readablec             C   s    |   st|d krdn|d S )NzFile or stream is not readable.)ra   rP   )rD   r_   r?   r?   r@   _checkReadable  s    zIOBase._checkReadablec             C   s   dS )NFr?   )rD   r?   r?   r@   writable  s    zIOBase.writablec             C   s    |   st|d krdn|d S )NzFile or stream is not writable.)rc   rP   )rD   r_   r?   r?   r@   _checkWritable  s    zIOBase._checkWritablec             C   s   | j S )N)r\   )rD   r?   r?   r@   closed  s    zIOBase.closedc             C   s   | j rt|d krdn|d S )NzI/O operation on closed file.)re   r!   )rD   r_   r?   r?   r@   rZ     s    zIOBase._checkClosedc             C   s   |    | S )N)rZ   )rD   r?   r?   r@   	__enter__  s    zIOBase.__enter__c             G   s   |    d S )N)r2   )rD   rM   r?   r?   r@   __exit__  s    zIOBase.__exit__c             C   s   |  d d S )Nr)   )rT   )rD   r?   r?   r@   r)     s    zIOBase.filenoc             C   s   |    dS )NF)rZ   )rD   r?   r?   r@   r&     s    zIOBase.isattyr   c                s   t  dr fdd}ndd }d kr0dn4y
j}W n" tk
r\   tdY nX | t }x>dk st|k r | }|sP ||7 }|drlP qlW t|S )	Npeekc                 s>     d} | sdS | dd p&t| }dkr:t|}|S )Nr
      
r   )rh   findr    min)Z	readaheadn)rD   sizer?   r@   
nreadahead  s    

z#IOBase.readline.<locals>.nreadaheadc               S   s   dS )Nr
   r?   r?   r?   r?   r@   rn     s    r   z is not an integerr   ri   )	hasattr	__index__r,   r   	bytearrayr    readendswithr   )rD   rm   rn   
size_indexresr   r?   )rD   rm   r@   readline  s&    
	

zIOBase.readlinec             C   s   |    | S )N)rZ   )rD   r?   r?   r@   __iter__  s    zIOBase.__iter__c             C   s   |   }|st|S )N)rv   StopIteration)rD   liner?   r?   r@   __next__  s    zIOBase.__next__c             C   sR   |d ks|dkrt | S d}g }x,| D ]$}|| |t|7 }||kr&P q&W |S )Nr   )listappendr    )rD   Zhintrl   linesry   r?   r?   r@   	readlines  s    

zIOBase.readlinesc             C   s$   |    x|D ]}| | qW d S )N)rZ   write)rD   r}   ry   r?   r?   r@   
writelines$  s    
zIOBase.writelines)r   )N)N)N)N)N)r   )N)rH   rI   rJ   rT   rU   rX   rY   r[   r\   r2   r]   r^   r`   ra   rb   rc   rd   propertyre   rZ   rf   rg   r)   r&   rv   rw   rz   r~   r   r?   r?   r?   r@   rQ     s2   #






	

*
rQ   )	metaclassc               @   s.   e Zd ZdddZdd Zdd Zdd	 Zd
S )	RawIOBaser   c             C   sP   |d krd}|dk r|   S t| }| |}|d kr>d S ||d = t|S )Nr   r   )readallrq   rp   readintor   )rD   rm   r   rl   r?   r?   r@   rr   ?  s    

zRawIOBase.readc             C   s8   t  }x| t}|sP ||7 }qW |r0t|S |S d S )N)rq   rr   r'   r   )rD   ru   datar?   r?   r@   r   P  s    
zRawIOBase.readallc             C   s   |  d d S )Nr   )rT   )rD   r   r?   r?   r@   r   ^  s    zRawIOBase.readintoc             C   s   |  d d S )Nr   )rT   )rD   r   r?   r?   r@   r   f  s    zRawIOBase.writeN)r   )rH   rI   rJ   rr   r   r   r   r?   r?   r?   r@   r   1  s   
r   )r%   c               @   sH   e Zd ZdddZdddZdd Zdd	 Zd
d Zdd Zdd Z	dS )BufferedIOBaser   c             C   s   |  d d S )Nrr   )rT   )rD   rm   r?   r?   r@   rr     s    zBufferedIOBase.readc             C   s   |  d d S )Nread1)rT   )rD   rm   r?   r?   r@   r     s    zBufferedIOBase.read1c             C   s   | j |ddS )NF)r   )	_readinto)rD   r   r?   r?   r@   r     s    zBufferedIOBase.readintoc             C   s   | j |ddS )NT)r   )r   )rD   r   r?   r?   r@   	readinto1  s    	zBufferedIOBase.readinto1c             C   sV   t |tst|}|d}|r0| t|}n| t|}t|}||d |< |S )NB)r   
memoryviewcastr   r    rr   )rD   r   r   r   rl   r?   r?   r@   r     s    

zBufferedIOBase._readintoc             C   s   |  d d S )Nr   )rT   )rD   r   r?   r?   r@   r     s    	zBufferedIOBase.writec             C   s   |  d d S )Ndetach)rT   )rD   r?   r?   r@   r     s    zBufferedIOBase.detachN)r   )r   )
rH   rI   rJ   rr   r   r   r   r   r   r   r?   r?   r?   r@   r   s  s   

r   c               @   s   e Zd Zdd Zd#ddZdd Zd$d	d
Zdd Zdd Zdd Z	dd Z
edd Zedd Zedd Zedd Zdd Zdd Zdd  Zd!d" ZdS )%_BufferedIOMixinc             C   s
   || _ d S )N)_raw)rD   r:   r?   r?   r@   __init__  s    z_BufferedIOMixin.__init__r   c             C   s"   | j ||}|dk rtd|S )Nr   z#seek() returned an invalid position)r:   rU   r+   )rD   rV   rW   Znew_positionr?   r?   r@   rU     s    z_BufferedIOMixin.seekc             C   s   | j  }|dk rtd|S )Nr   z#tell() returned an invalid position)r:   rX   r+   )rD   rV   r?   r?   r@   rX     s    
z_BufferedIOMixin.tellNc             C   s$   |    |d kr|  }| j|S )N)r[   rX   r:   rY   )rD   rV   r?   r?   r@   rY     s    z_BufferedIOMixin.truncatec             C   s   | j rtd| j  d S )Nzflush on closed file)re   r!   r:   r[   )rD   r?   r?   r@   r[     s    z_BufferedIOMixin.flushc             C   s.   | j d k	r*| js*z|   W d | j   X d S )N)r:   re   r[   r2   )rD   r?   r?   r@   r2   
  s    z_BufferedIOMixin.closec             C   s*   | j d krtd|   | j}d | _|S )Nzraw stream already detached)r:   r!   r[   r   )rD   r:   r?   r?   r@   r     s    
z_BufferedIOMixin.detachc             C   s
   | j  S )N)r:   r^   )rD   r?   r?   r@   r^     s    z_BufferedIOMixin.seekablec             C   s   | j S )N)r   )rD   r?   r?   r@   r:     s    z_BufferedIOMixin.rawc             C   s   | j jS )N)r:   re   )rD   r?   r?   r@   re   #  s    z_BufferedIOMixin.closedc             C   s   | j jS )N)r:   rS   )rD   r?   r?   r@   rS   '  s    z_BufferedIOMixin.namec             C   s   | j jS )N)r:   r1   )rD   r?   r?   r@   r1   +  s    z_BufferedIOMixin.modec             C   s   t d| jjd S )Nz can not serialize a '{0}' object)r   formatrR   rH   )rD   r?   r?   r@   __getstate__/  s    z_BufferedIOMixin.__getstate__c             C   sJ   | j j}| j j}y
| j}W n tk
r6   d||S X d|||S d S )Nz<{}.{}>z<{}.{} name={!r}>)rR   rI   rJ   rS   	Exceptionr   )rD   modnameZclsnamerS   r?   r?   r@   __repr__3  s    
z_BufferedIOMixin.__repr__c             C   s
   | j  S )N)r:   r)   )rD   r?   r?   r@   r)   ?  s    z_BufferedIOMixin.filenoc             C   s
   | j  S )N)r:   r&   )rD   r?   r?   r@   r&   B  s    z_BufferedIOMixin.isatty)r   )N)rH   rI   rJ   r   rU   rX   rY   r[   r2   r   r^   r   r:   re   rS   r1   r   r   r)   r&   r?   r?   r?   r@   r     s    	


r   c                   s   e Zd ZdZd ddZdd Zdd Zdd	 Z fd
dZd!ddZ	d"ddZ
dd Zd#ddZdd Zd$ddZdd Zdd Zdd Z  ZS )%BytesIONc             C   s&   t  }|d k	r||7 }|| _d| _d S )Nr   )rq   _buffer_pos)rD   Zinitial_bytesbufr?   r?   r@   r   N  s
    zBytesIO.__init__c             C   s   | j rtd| j S )Nz__getstate__ on closed file)re   r!   __dict__copy)rD   r?   r?   r@   r   U  s    zBytesIO.__getstate__c             C   s   | j rtdt| jS )Nzgetvalue on closed file)re   r!   r   r   )rD   r?   r?   r@   getvalueZ  s    zBytesIO.getvaluec             C   s   | j rtdt| jS )Nzgetbuffer on closed file)re   r!   r   r   )rD   r?   r?   r@   	getbuffera  s    zBytesIO.getbufferc                s"   | j d k	r| j   t   d S )N)r   clearsuperr2   )rD   )rR   r?   r@   r2   h  s    

zBytesIO.closer   c             C   s   | j rtd|d krd}n4y
|j}W n" tk
rH   t|dY nX | }|dk rbt| j}t| j| jkrvdS tt| j| j| }| j| j| }|| _t	|S )Nzread from closed filer   z is not an integerr       )
re   r!   rp   r,   r   r    r   r   rk   r   )rD   rm   rt   Znewposr   r?   r?   r@   rr   m  s"    

zBytesIO.readc             C   s
   |  |S )N)rr   )rD   rm   r?   r?   r@   r     s    zBytesIO.read1c          	   C   s   | j rtdt|tr tdt|}|j}W d Q R X |dkrFdS | j}|t| j	krzd|t| j	  }|  j	|7  _	|| j	||| < |  j|7  _|S )Nzwrite to closed filez can't write str to binary streamr       )
re   r!   r   r   r   r   nbytesr   r    r   )rD   r   Zviewrl   rV   Zpaddingr?   r?   r@   r     s    

zBytesIO.writer   c             C   s   | j rtdy
|j}W n" tk
r:   t|dY nX | }|dkrh|dk r`td|f || _nD|dkrtd| j| | _n(|dkrtdt| j| | _ntd| jS )Nzseek on closed filez is not an integerr   znegative seek position %rr
   r   zunsupported whence value)	re   r!   rp   r,   r   r   maxr    r   )rD   rV   rW   	pos_indexr?   r?   r@   rU     s"    
zBytesIO.seekc             C   s   | j rtd| jS )Nztell on closed file)re   r!   r   )rD   r?   r?   r@   rX     s    zBytesIO.tellc             C   sx   | j rtd|d kr| j}nJy
|j}W n" tk
rJ   t|dY nX | }|dk rhtd|f | j|d = |S )Nztruncate on closed filez is not an integerr   znegative truncate position %r)re   r!   r   rp   r,   r   r   )rD   rV   r   r?   r?   r@   rY     s    
zBytesIO.truncatec             C   s   | j rtddS )NzI/O operation on closed file.T)re   r!   )rD   r?   r?   r@   ra     s    zBytesIO.readablec             C   s   | j rtddS )NzI/O operation on closed file.T)re   r!   )rD   r?   r?   r@   rc     s    zBytesIO.writablec             C   s   | j rtddS )NzI/O operation on closed file.T)re   r!   )rD   r?   r?   r@   r^     s    zBytesIO.seekable)N)r   )r   )r   )N)rH   rI   rJ   r   r   r   r   r   r2   rr   r   r   rU   rX   rY   ra   rc   r^   __classcell__r?   r?   )rR   r@   r   F  s   




r   c               @   st   e Zd ZefddZdd Zdd Zddd	Zdd
dZdddZ	dddZ
dddZdd Zdd ZdddZdS ) r/   c             C   sF   |  stdt| | |dkr,td|| _|   t | _d S )Nz "raw" argument must be readable.r   zinvalid buffer size)	ra   r+   r   r   r!   buffer_size_reset_read_bufLock
_read_lock)rD   r:   r   r?   r?   r@   r     s    zBufferedReader.__init__c             C   s
   | j  S )N)r:   ra   )rD   r?   r?   r@   ra     s    zBufferedReader.readablec             C   s   d| _ d| _d S )Nr   r   )	_read_buf	_read_pos)rD   r?   r?   r@   r     s    zBufferedReader._reset_read_bufNc          	   C   s4   |d k	r|dk rt d| j | |S Q R X d S )Nr   zinvalid number of bytes to read)r!   r   _read_unlocked)rD   rm   r?   r?   r@   rr     s    zBufferedReader.readc             C   s  d}d}| j }| j}|d ks$|dkr|   t| jdrj| j }|d krZ||d  pXd S ||d  | S ||d  g}d}x2| j }||kr|}P |t|7 }|| q~W d	|p|S t|| }	||	kr|  j|7  _||||  S ||d  g}t
| j|}
xB|	|k rL| j|
}||kr2|}P |	t|7 }	|| qW t||	}d	|}||d  | _ d| _|r|d | S |S )Nr   )r   Nr   r   r   )r   r   r   ro   r:   r   rr   r    r|   joinr   r   rk   )rD   rl   Z
nodata_valZempty_valuesr   rV   chunkZchunksZcurrent_sizeavailZwantedoutr?   r?   r@   r     sN    




zBufferedReader._read_unlockedr   c          	   C   s   | j  | |S Q R X d S )N)r   _peek_unlocked)rD   rm   r?   r?   r@   rh   5  s    zBufferedReader.peekc             C   sr   t || j}t| j| j }||k s,|dkrb| j| }| j|}|rb| j| jd  | | _d| _| j| jd  S )Nr   )rk   r   r    r   r   r:   rr   )rD   rl   ZwantZhaveZto_readZcurrentr?   r?   r@   r   ?  s    
zBufferedReader._peek_unlockedr   c          	   C   sR   |dk r| j }|dkrdS | j( | d | t|t| j| j S Q R X d S )Nr   r   r
   )r   r   r   r   rk   r    r   r   )rD   rm   r?   r?   r@   r   J  s    
zBufferedReader.read1c          	   C   s  t |tst|}|jdkr dS |d}d}| j x|t|k rtt| j| j t|}|r| j| j| j|  |||| < |  j|7  _||7 }|t|krP t|| | j	kr| j
||d  }|sP ||7 }n|r|s| dsP |r8|r8P q8W W d Q R X |S )Nr   r   r
   )r   r   r   r   r   r    rk   r   r   r   r:   r   r   )rD   r   r   writtenr   rl   r?   r?   r@   r   \  s4    


"

zBufferedReader._readintoc             C   s   t | t| j | j S )N)r   rX   r    r   r   )rD   r?   r?   r@   rX     s    zBufferedReader.tellc          	   C   sX   |t krtd| j8 |dkr4|t| j| j 8 }t| ||}|   |S Q R X d S )Nzinvalid whence valuer
   )	valid_seek_flagsr!   r   r    r   r   r   rU   r   )rD   rV   rW   r?   r?   r@   rU     s    zBufferedReader.seek)N)N)r   )r   )r   )r   )rH   rI   rJ   r'   r   ra   r   rr   r   rh   r   r   r   rX   rU   r?   r?   r?   r@   r/     s   

4



.r/   c               @   s\   e Zd ZefddZdd Zdd Zddd	Zd
d Zdd Z	dd Z
dddZdd ZdS )r.   c             C   sF   |  stdt| | |dkr,td|| _t | _t | _	d S )Nz "raw" argument must be writable.r   zinvalid buffer size)
rc   r+   r   r   r!   r   rq   
_write_bufr   _write_lock)rD   r:   r   r?   r?   r@   r     s    zBufferedWriter.__init__c             C   s
   | j  S )N)r:   rc   )rD   r?   r?   r@   rc     s    zBufferedWriter.writablec             C   s   t |trtd| j | jr(tdt| j| jkr@| 	  t| j}| j
| t| j| }t| j| jkry| 	  W nl tk
r } zNt| j| jkrt| j| j }||8 }| jd | j | _t|j|j|W d d }~X Y nX |S Q R X d S )Nz can't write str to binary streamzwrite to closed file)r   r   r   r   re   r!   r    r   r   _flush_unlockedextendBlockingIOErrorerrnostrerror)rD   r   Zbeforer   eZoverager?   r?   r@   r     s(    

"zBufferedWriter.writeNc          	   C   s8   | j ( |   |d kr"| j }| j|S Q R X d S )N)r   r   r:   rX   rY   )rD   rV   r?   r?   r@   rY     s
    
zBufferedWriter.truncatec          	   C   s   | j  |   W d Q R X d S )N)r   r   )rD   r?   r?   r@   r[     s    zBufferedWriter.flushc             C   s   | j rtdxz| jry| j| j}W n tk
rD   tdY nX |d kr\ttjdd|t	| jksr|dk rzt
d| jd |= qW d S )Nzflush on closed filezHself.raw should implement RawIOBase: it should not raise BlockingIOErrorz)write could not complete without blockingr   z*write() returned incorrect number of bytes)re   r!   r   r:   r   r   RuntimeErrorr   ZEAGAINr    r+   )rD   rl   r?   r?   r@   r     s    zBufferedWriter._flush_unlockedc             C   s   t | t| j S )N)r   rX   r    r   )rD   r?   r?   r@   rX     s    zBufferedWriter.tellr   c          	   C   s8   |t krtd| j |   t| ||S Q R X d S )Nzinvalid whence value)r   r!   r   r   r   rU   )rD   rV   rW   r?   r?   r@   rU     s
    zBufferedWriter.seekc             C   sV   | j  | jd ks| jrd S W d Q R X z|   W d | j  | j  W d Q R X X d S )N)r   r:   re   r[   r2   )rD   r?   r?   r@   r2     s    zBufferedWriter.close)N)r   )rH   rI   rJ   r'   r   rc   r   rY   r[   r   rX   rU   r2   r?   r?   r?   r@   r.     s   	

r.   c               @   s   e Zd ZefddZdddZdd Zdd	 ZdddZd ddZ	dd Z
dd Zdd Zdd Zdd Zdd Zedd ZdS )!BufferedRWPairc             C   s<   |  std| s tdt||| _t||| _d S )Nz#"reader" argument must be readable.z#"writer" argument must be writable.)ra   r+   rc   r/   readerr.   writer)rD   r   r   r   r?   r?   r@   r     s    zBufferedRWPair.__init__r   c             C   s   |d krd}| j |S )Nr   )r   rr   )rD   rm   r?   r?   r@   rr     s    zBufferedRWPair.readc             C   s   | j |S )N)r   r   )rD   r   r?   r?   r@   r   #  s    zBufferedRWPair.readintoc             C   s   | j |S )N)r   r   )rD   r   r?   r?   r@   r   &  s    zBufferedRWPair.writer   c             C   s   | j |S )N)r   rh   )rD   rm   r?   r?   r@   rh   )  s    zBufferedRWPair.peekc             C   s   | j |S )N)r   r   )rD   rm   r?   r?   r@   r   ,  s    zBufferedRWPair.read1c             C   s   | j |S )N)r   r   )rD   r   r?   r?   r@   r   /  s    zBufferedRWPair.readinto1c             C   s
   | j  S )N)r   ra   )rD   r?   r?   r@   ra   2  s    zBufferedRWPair.readablec             C   s
   | j  S )N)r   rc   )rD   r?   r?   r@   rc   5  s    zBufferedRWPair.writablec             C   s
   | j  S )N)r   r[   )rD   r?   r?   r@   r[   8  s    zBufferedRWPair.flushc             C   s    z| j   W d | j  X d S )N)r   r2   r   )rD   r?   r?   r@   r2   ;  s    zBufferedRWPair.closec             C   s   | j  p| j S )N)r   r&   r   )rD   r?   r?   r@   r&   A  s    zBufferedRWPair.isattyc             C   s   | j jS )N)r   re   )rD   r?   r?   r@   re   D  s    zBufferedRWPair.closedN)r   )r   )r   )rH   rI   rJ   r'   r   rr   r   r   rh   r   r   ra   rc   r[   r2   r&   r   re   r?   r?   r?   r@   r      s   


r   c               @   sj   e Zd ZefddZdddZdd Zdd	d
ZdddZdd Z	dddZ
dddZdd Zdd ZdS )r-   c             C   s(   |   t| || t| || d S )N)r`   r/   r   r.   )rD   r:   r   r?   r?   r@   r   R  s    zBufferedRandom.__init__r   c          	   C   s   |t krtd|   | jrJ| j  | j| jt| j d W d Q R X | j||}| j | 	  W d Q R X |dk rt
d|S )Nzinvalid whence valuer
   r   z seek() returned invalid position)r   r!   r[   r   r   r:   rU   r   r    r   r+   )rD   rV   rW   r?   r?   r@   rU   W  s    $zBufferedRandom.seekc             C   s   | j rt| S t| S d S )N)r   r.   rX   r/   )rD   r?   r?   r@   rX   h  s    
zBufferedRandom.tellNc             C   s   |d kr|   }t| |S )N)rX   r.   rY   )rD   rV   r?   r?   r@   rY   n  s    zBufferedRandom.truncatec             C   s    |d krd}|    t| |S )Nr   )r[   r/   rr   )rD   rm   r?   r?   r@   rr   t  s    zBufferedRandom.readc             C   s   |    t| |S )N)r[   r/   r   )rD   r   r?   r?   r@   r   z  s    zBufferedRandom.readintoc             C   s   |    t| |S )N)r[   r/   rh   )rD   rm   r?   r?   r@   rh   ~  s    zBufferedRandom.peekr   c             C   s   |    t| |S )N)r[   r/   r   )rD   rm   r?   r?   r@   r     s    zBufferedRandom.read1c             C   s   |    t| |S )N)r[   r/   r   )rD   r   r?   r?   r@   r     s    zBufferedRandom.readinto1c          	   C   sF   | j r:| j( | j| jt| j  d |   W d Q R X t| |S )Nr
   )	r   r   r:   rU   r   r    r   r.   r   )rD   r   r?   r?   r@   r     s
    zBufferedRandom.write)r   )N)N)r   )r   )rH   rI   rJ   r'   r   rU   rX   rY   rr   r   rh   r   r   r   r?   r?   r?   r@   r-   I  s   	




r-   c                   s   e Zd ZdZdZdZdZdZdZdZ	d0ddZ
dd	 Zd
d Zdd Zdd Zd1ddZd2ddZdd Zdd Zdd ZefddZdd Zd3ddZ fd d!Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zed,d- Zed.d/ Z   Z!S )4r%   r   FNTr   c       
      C   s  | j dkr*z| jrt| j  W d d| _ X t|tr<tdt|tr\|}|dk r`tdnd}t|t	sxtd|f t
|t
dkstd|f tdd |D d	ks|d
d	krtdd|krd| _d| _tjtjB }nTd|krd| _d}n@d|krd| _tjtjB }n"d|kr8d| _d| _tjtjB }d
|krNd| _d| _| jrj| jrj|tjO }n| jr~|tjO }n
|tjO }|ttddO }ttddpttdd}||O }d }y|dk r:|std|d krt||d}n0|||}t|tstd|dk r$td|}|s:t|d || _t|}	y(t|	jrpt t!j"t#t!j"|W n t$k
r   Y nX t|	dd| _%| j%d	krt&| _%t'rt'|tj( || _)| jrt*|dt+ W n"   |d k	rt|  Y nX || _ d S )Nr   r   z$integer argument expected, got floatznegative file descriptorzinvalid mode: %szxrwab+c             s   s   | ]}|d kV  qdS )ZrwaxNr?   ).0cr?   r?   r@   	<genexpr>  s    z"FileIO.__init__.<locals>.<genexpr>r
   r   zKMust have exactly one of create/read/write/append mode and at most one plusr   Tr   r   r   O_BINARYZO_NOINHERIT	O_CLOEXECz'Cannot use closefd=False with file namei  zexpected integer from openerzNegative file descriptorFr*   ),_fd_closefdr   r2   r   floatr   r   r!   r   r   sumcount_created	_writableO_EXCLO_CREAT	_readableO_TRUNC
_appendingO_APPENDO_RDWRO_RDONLYO_WRONLYgetattrrA   r+   set_inheritabler(   statS_ISDIRst_modeIsADirectoryErrorr   ZEISDIRr   r,   _blksizer'   _setmoder   rS   lseekr	   )
rD   r3   r1   r8   r   fdflagsZnoinherit_flagZowned_fdZfdfstatr?   r?   r@   r     s    




$










zFileIO.__init__c             C   sB   | j dkr>| jr>| js>dd l}|jd| f td| d |   d S )Nr   zunclosed file %rr   )
stacklevelsource)r   r   re   r"   r#   ResourceWarningr2   )rD   r"   r?   r?   r@   r]     s
    
zFileIO.__del__c             C   s   t d| jjd S )Nzcannot serialize '%s' object)r   rR   rH   )rD   r?   r?   r@   r     s    zFileIO.__getstate__c             C   sl   d| j j| j jf }| jr"d| S y
| j}W n& tk
rR   d|| j| j| jf S X d||| j| jf S d S )Nz%s.%sz<%s [closed]>z<%s fd=%d mode=%r closefd=%r>z<%s name=%r mode=%r closefd=%r>)	rR   rI   rJ   re   rS   r,   r   r1   r   )rD   
class_namerS   r?   r?   r@   r     s    
zFileIO.__repr__c             C   s   | j stdd S )NzFile not open for reading)r   rP   )rD   r?   r?   r@   rb   )  s    zFileIO._checkReadablec             C   s   | j stdd S )NzFile not open for writing)r   rP   )rD   r_   r?   r?   r@   rd   -  s    zFileIO._checkWritablec             C   sP   |    |   |d ks |dk r(|  S yt| j|S  tk
rJ   d S X d S )Nr   )rZ   rb   r   r   rr   r   r   )rD   rm   r?   r?   r@   rr   1  s    zFileIO.readc             C   s   |    |   t}y6t| jdt}t| jj}||krH|| d }W n t	k
r^   Y nX t
 }xnt||krt|}|t|t7 }|t| }yt| j|}W n tk
r   |rP d S X |sP ||7 }qhW t|S )Nr   r
   )rZ   rb   r'   r   r   r   r   r(   st_sizer+   rq   r    r   rr   r   r   )rD   bufsizerV   endr;   rl   r   r?   r?   r@   r   A  s4    zFileIO.readallc             C   s4   t |d}| t|}t|}||d |< |S )Nr   )r   r   rr   r    )rD   r   mr   rl   r?   r?   r@   r   d  s
    zFileIO.readintoc             C   s8   |    |   yt| j|S  tk
r2   d S X d S )N)rZ   rd   r   r   r   r   )rD   r   r?   r?   r@   r   l  s    zFileIO.writec             C   s*   t |trtd|   t| j||S )Nzan integer is required)r   r   r   rZ   r   r   r   )rD   rV   rW   r?   r?   r@   rU   z  s    
zFileIO.seekc             C   s   |    t| jdtS )Nr   )rZ   r   r   r   r   )rD   r?   r?   r@   rX     s    zFileIO.tellc             C   s2   |    |   |d kr |  }t| j| |S )N)rZ   rd   rX   r   	ftruncater   )rD   rm   r?   r?   r@   rY     s    zFileIO.truncatec                s.   | j s*z| jrt| j W d t   X d S )N)re   r   r   r2   r   r   )rD   )rR   r?   r@   r2     s
    zFileIO.closec             C   sF   |    | jd kr@y|   W n tk
r8   d| _Y nX d| _| jS )NFT)rZ   	_seekablerX   r+   )rD   r?   r?   r@   r^     s    
zFileIO.seekablec             C   s   |    | jS )N)rZ   r   )rD   r?   r?   r@   ra     s    zFileIO.readablec             C   s   |    | jS )N)rZ   r   )rD   r?   r?   r@   rc     s    zFileIO.writablec             C   s   |    | jS )N)rZ   r   )rD   r?   r?   r@   r)     s    zFileIO.filenoc             C   s   |    t| jS )N)rZ   r   r&   r   )rD   r?   r?   r@   r&     s    zFileIO.isattyc             C   s   | j S )N)r   )rD   r?   r?   r@   r8     s    zFileIO.closefdc             C   sJ   | j r| jrdS dS n0| jr,| jr&dS dS n| jrB| jr<dS dS ndS d S )Nzxb+Zxbzab+Zabzrb+rbwb)r   r   r   r   )rD   r?   r?   r@   r1     s    zFileIO.mode)r   TN)N)N)N)"rH   rI   rJ   r   r   r   r   r   r   r   r   r]   r   r   rb   rd   rr   r   r   r   r   rU   rX   rY   r2   r^   ra   rc   r)   r&   r   r8   r1   r   r?   r?   )rR   r@   r%     s8   
u

#
r%   c               @   s\   e Zd ZdddZdd ZdddZd	d
 Zdd Zedd Z	edd Z
edd ZdS )
TextIOBaser   c             C   s   |  d d S )Nrr   )rT   )rD   rm   r?   r?   r@   rr     s    zTextIOBase.readc             C   s   |  d d S )Nr   )rT   )rD   sr?   r?   r@   r     s    zTextIOBase.writeNc             C   s   |  d d S )NrY   )rT   )rD   rV   r?   r?   r@   rY     s    zTextIOBase.truncatec             C   s   |  d d S )Nrv   )rT   )rD   r?   r?   r@   rv      s    zTextIOBase.readlinec             C   s   |  d d S )Nr   )rT   )rD   r?   r?   r@   r     s    zTextIOBase.detachc             C   s   d S )Nr?   )rD   r?   r?   r@   r5     s    zTextIOBase.encodingc             C   s   d S )Nr?   )rD   r?   r?   r@   newlines  s    zTextIOBase.newlinesc             C   s   d S )Nr?   )rD   r?   r?   r@   r6     s    zTextIOBase.errors)r   )N)rH   rI   rJ   rr   r   rY   rv   r   r   r5   r   r6   r?   r?   r?   r@   r     s   


	
r   c               @   sP   e Zd ZdddZdddZdd Zd	d
 Zdd ZdZdZ	dZ
edd ZdS )IncrementalNewlineDecoderstrictc             C   s,   t jj| |d || _|| _d| _d| _d S )N)r6   r   F)codecsIncrementalDecoderr   	translatedecoderseennl	pendingcr)rD   r   r   r6   r?   r?   r@   r   0  s
    z"IncrementalNewlineDecoder.__init__Fc             C   s   | j d kr|}n| j j||d}| jr<|s.|r<d| }d| _|dr\|s\|d d }d| _|d}|d| }|d| }|  j|o| j|o| jB |o| jB O  _| j	r|r|
dd}|r|
dd}|S )N)finalFr   Tz

)r   decoder   rs   r   r   _LF_CR_CRLFr   replace)rD   inputr   outputZcrlfZcrZlfr?   r?   r@   r   7  s(    

"z IncrementalNewlineDecoder.decodec             C   s@   | j d krd}d}n| j  \}}|dK }| jr8|dO }||fS )Nr   r   r
   )r   getstater   )rD   r   flagr?   r?   r@   r  V  s    
z"IncrementalNewlineDecoder.getstatec             C   s8   |\}}t |d@ | _| jd k	r4| j||d? f d S )Nr
   )boolr   r   setstate)rD   stater   r  r?   r?   r@   r  a  s    
z"IncrementalNewlineDecoder.setstatec             C   s$   d| _ d| _| jd k	r | j  d S )Nr   F)r   r   r   reset)rD   r?   r?   r@   r  g  s    
zIncrementalNewlineDecoder.resetr
   r      c             C   s
   d| j  S )N)Nr   r   )r   r   z
)r   z
)r   z
)r   r   z
)r   )rD   r?   r?   r@   r   q  s    z"IncrementalNewlineDecoder.newlinesN)r   )F)rH   rI   rJ   r   r   r  r  r  r   r   r   r   r   r?   r?   r?   r@   r   )  s   

r   c               @   sr  e Zd ZdZdZdNddZdd ZdOdd	Zd
d Ze	dd Z
e	dd Ze	dd Ze	dd Ze	dd ZddedddddZdd Zdd Zdd Zdd  Zd!d" Ze	d#d$ Ze	d%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 ZdPd3d4Zd5d6 Zd7d8 Z dQd:d;Z!d<d= Z"d>d? Z#dRd@dAZ$dBdC Z%dSdDdEZ&dTdFdGZ'dHdI Z(dUdJdKZ)e	dLdM Z*dS )Vr0   i   NFc       	   	   C   s  |  | |d krvyt| }W n ttfk
r<   Y nX |d krvydd l}W n tk
rj   d}Y nX |d}t	|t
std| t|jsd}t|| |d krd}nt	|t
std| || _d| _d| _d | _| j  | _| _t| jd	| _| ||||| d S )
Nr   asciiFzinvalid encoding: %rzG%r is not a text encoding; use codecs.open() to handle arbitrary codecsr   zinvalid errors: %rr   r   )_check_newliner   device_encodingr)   r,   rP   localeImportErrorgetpreferredencodingr   r   r!   r   lookup_is_text_encodingLookupErrorr   _decoded_chars_decoded_chars_used	_snapshotr>   r^   r   _tellingro   
_has_read1
_configure)	rD   r>   r5   r6   r7   r<   write_throughr  r_   r?   r?   r@   r     s:    





zTextIOWrapper.__init__c             C   s>   |d k	r$t |ts$tdt|f |dkr:td|f d S )Nzillegal newline type: %r)Nr   r   r   z
zillegal newline value: %r)r   r   r   typer!   )rD   r7   r?   r?   r@   r
    s    zTextIOWrapper._check_newlinec             C   s   || _ || _d | _d | _d| _| | _|d k| _|| _|dk| _|pHt	j
| _|| _|| _| jr|  r| j }|dkry|  d W n tk
r   Y nX d S )Ng        r   r   )	_encoding_errors_encoder_decoder	_b2cratio_readuniversal_readtranslate_readnl_writetranslater   linesep_writenl_line_buffering_write_throughr   rc   r>   rX   _get_encoderr  r  )rD   r5   r6   r7   r<   r  positionr?   r?   r@   r    s&    


zTextIOWrapper._configurec             C   s   d | jj| jj}y
| j}W n tk
r2   Y nX |d |7 }y
| j}W n tk
r`   Y nX |d |7 }|d | j S )Nz<{}.{}z name={0!r}z mode={0!r}z encoding={0!r}>)r   rR   rI   rJ   rS   r   r1   r5   )rD   r;   rS   r1   r?   r?   r@   r     s    



zTextIOWrapper.__repr__c             C   s   | j S )N)r  )rD   r?   r?   r@   r5     s    zTextIOWrapper.encodingc             C   s   | j S )N)r  )rD   r?   r?   r@   r6     s    zTextIOWrapper.errorsc             C   s   | j S )N)r%  )rD   r?   r?   r@   r<   
  s    zTextIOWrapper.line_bufferingc             C   s   | j S )N)r&  )rD   r?   r?   r@   r    s    zTextIOWrapper.write_throughc             C   s   | j S )N)r   )rD   r?   r?   r@   r>     s    zTextIOWrapper.buffer)r5   r6   r7   r<   r  c            C   s   | j d k	r*|d k	s"|d k	s"|tk	r*td|d krH|d krB| j}q^d}nt|ts^td| |d krn| j}nt|tstd| |tkr| j}| 	| |d kr| j
}|d kr| j}|   | ||||| d S )NzPIt is not possible to set the encoding or newline of stream after the first readr   zinvalid errors: %rzinvalid encoding: %r)r  EllipsisrP   r  r   r   r   r  r!  r
  r<   r  r[   r  )rD   r5   r6   r7   r<   r  r?   r?   r@   reconfigure  s2    




zTextIOWrapper.reconfigurec             C   s   | j rtd| jS )NzI/O operation on closed file.)re   r!   r   )rD   r?   r?   r@   r^   ?  s    zTextIOWrapper.seekablec             C   s
   | j  S )N)r>   ra   )rD   r?   r?   r@   ra   D  s    zTextIOWrapper.readablec             C   s
   | j  S )N)r>   rc   )rD   r?   r?   r@   rc   G  s    zTextIOWrapper.writablec             C   s   | j   | j| _d S )N)r>   r[   r   r  )rD   r?   r?   r@   r[   J  s    
zTextIOWrapper.flushc             C   s.   | j d k	r*| js*z|   W d | j   X d S )N)r>   re   r[   r2   )rD   r?   r?   r@   r2   N  s    zTextIOWrapper.closec             C   s   | j jS )N)r>   re   )rD   r?   r?   r@   re   U  s    zTextIOWrapper.closedc             C   s   | j jS )N)r>   rS   )rD   r?   r?   r@   rS   Y  s    zTextIOWrapper.namec             C   s
   | j  S )N)r>   r)   )rD   r?   r?   r@   r)   ]  s    zTextIOWrapper.filenoc             C   s
   | j  S )N)r>   r&   )rD   r?   r?   r@   r&   `  s    zTextIOWrapper.isattyc             C   s   | j rtdt|ts(td|jj t|}| js<| j	oBd|k}|rf| jrf| j
dkrf|d| j
}| jpr|  }||}| j| | j	r|sd|kr|   | d d | _| jr| j  |S )Nzwrite to closed filezcan't write %s to text streamr   r   r   )re   r!   r   r   r   rR   rH   r    r"  r%  r$  r   r  r'  encoder>   r   r[   _set_decoded_charsr  r  r  )rD   r   lengthZhaslfencoderr   r?   r?   r@   r   c  s&    



zTextIOWrapper.writec             C   s   t | j}|| j| _| jS )N)r   getincrementalencoderr  r  r  )rD   Zmake_encoderr?   r?   r@   r'  z  s    zTextIOWrapper._get_encoderc             C   s2   t | j}|| j}| jr(t|| j}|| _|S )N)r   getincrementaldecoderr  r  r  r   r   r  )rD   Zmake_decoderr   r?   r?   r@   _get_decoder  s    
zTextIOWrapper._get_decoderc             C   s   || _ d| _d S )Nr   )r  r  )rD   charsr?   r?   r@   r,    s    z TextIOWrapper._set_decoded_charsc             C   sF   | j }|d kr| j|d  }n| j|||  }|  j t|7  _ |S )N)r  r  r    )rD   rl   offsetr2  r?   r?   r@   _get_decoded_chars  s    z TextIOWrapper._get_decoded_charsc             C   s$   | j |k rtd|  j |8  _ d S )Nz"rewind decoded_chars out of bounds)r  AssertionError)rD   rl   r?   r?   r@   _rewind_decoded_chars  s    
z#TextIOWrapper._rewind_decoded_charsc             C   s   | j d krtd| jr&| j  \}}| jr<| j| j}n| j| j}| }| j 	||}| 
| |rt|t| j | _nd| _| jr||| f| _| S )Nz
no decoderg        )r  r!   r  r  r  r>   r   _CHUNK_SIZErr   r   r,  r    r  r  r  )rD   
dec_buffer	dec_flagsinput_chunkeofZdecoded_charsr?   r?   r@   _read_chunk  s     

zTextIOWrapper._read_chunkr   c             C   s(   ||d> B |d> B |d> B t |d> B S )N@            )r  )rD   r(  r9  bytes_to_feedneed_eofchars_to_skipr?   r?   r@   _pack_cookie  s    zTextIOWrapper._pack_cookiec             C   sF   t |d\}}t |d\}}t |d\}}t |d\}}|||||fS )Nl            )divmod)rD   Zbigintrestr(  r9  rA  rB  rC  r?   r?   r@   _unpack_cookie  s
    zTextIOWrapper._unpack_cookiec          	   C   s:  | j std| jstd|   | j }| j}|d ksF| jd krX| j	rTt
d|S | j\}}|t|8 }| j}|dkr| ||S | }zt| j| }d}x|dkr"|d|f t||d | }	|	|kr| \}
}|
s|}||	8 }P |t|
8 }d}q||8 }|d }qW d}|d|f || }|}|dkrX| ||S d}d}d}xt|t|D ]t}|d7 }|t||||d  7 }| \}}|s||kr||7 }||8 }|dd  }}}||krtP qtW |t|jddd	7 }d}||k rtd
| |||||S || X d S )Nz!underlying stream is not seekablez(telling position disabled by next() callzpending decoded textr   r
   r   r   T)r   z'can't reconstruct logical file position)r   rP   r  r+   r[   r>   rX   r  r  r  r5  r    r  rD  r  r   r  r  r   range)rD   r(  r   r9  Z
next_inputrC  Zsaved_stateZ
skip_bytesZ	skip_backrl   r   d	start_posZstart_flagsZ	bytes_fedrB  Zchars_decodedir8  r?   r?   r@   rX     sv    





zTextIOWrapper.tellc             C   s$   |    |d kr|  }| j|S )N)r[   rX   r>   rY   )rD   rV   r?   r?   r@   rY   =	  s    zTextIOWrapper.truncatec             C   s*   | j d krtd|   | j}d | _|S )Nzbuffer is already detached)r>   r!   r[   r   )rD   r>   r?   r?   r@   r   C	  s    
zTextIOWrapper.detachc                s   fdd} j rtd js(td|dkrL|dkr@tdd}  }|dkr|dkrdtd	    jdd} d
 d  _	 j
r j
  || |S |dkrtd|f |dk rtd|f     |\}}}}}	 j|  d
 d  _	|dkr( j
r( j
  n@ j
s<|s<|	rh j
pJ   _
 j
d|f |df _	|	r j|}
  j
|
| ||
f _	t j|	k rtd|	 _|| |S )Nc                sH   y j p  }W n tk
r&   Y nX | dkr<|d n|  d S )Nr   )r  r'  r  r  r  )r(  r.  )rD   r?   r@   _reset_encoderL	  s    z*TextIOWrapper.seek.<locals>._reset_encoderztell on closed filez!underlying stream is not seekabler
   r   z#can't do nonzero cur-relative seeksr   z#can't do nonzero end-relative seeksr   zunsupported whence (%r)znegative seek position %rr   z#can't restore logical file position)re   r!   r   rP   rX   r[   r>   rU   r,  r  r  r  rG  r1  r  rr   r   r    r  r+   r  )rD   ZcookierW   rL  r(  rJ  r9  rA  rB  rC  r:  r?   )rD   r@   rU   K	  s\    




zTextIOWrapper.seekc             C   s   |    |d krd}n4y
|j}W n" tk
rB   t|dY nX | }| jpV|  }|dk r|  |j| j	 dd }| 
d d | _|S d}| |}x4t||k r|s|   }|| |t| 7 }qW |S d S )Nr   z is not an integerr   T)r   r   F)rb   rp   r,   r   r  r1  r4  r   r>   rr   r,  r  r    r<  )rD   rm   rt   r   r;   r;  r?   r?   r@   rr   	  s*    



zTextIOWrapper.readc             C   s(   d| _ |  }|s$d | _| j| _ t|S )NF)r  rv   r  r   rx   )rD   ry   r?   r?   r@   rz   	  s    zTextIOWrapper.__next__c       	      C   s  | j rtd|d krd}n4y
|j}W n" tk
rH   t|dY nX | }|  }d}| jsj|   d  }}xV| jr|	d|}|dkr|d }P nt
|}n| jr>|	d|}|	d|}|dkr|dkrt
|}n
|d }P nP|dkr|d }P n:||k r|d }P n$||d kr2|d }P n
|d }P n&|	| j}|dkrd|t
| j }P |dkrt
||kr|}P x|  r| jrP qW | jr||  7 }qv| d	 d | _|S qvW |dkr||kr|}| t
||  |d | S )
Nzread from closed filer   z is not an integerr   r   r
   r   r   r   )re   r!   rp   r,   r   r4  r  r1  r   rj   r    r  r!  r<  r  r,  r  r6  )	rD   rm   rt   ry   startrV   endposZnlposZcrposr?   r?   r@   rv   	  sv    






zTextIOWrapper.readlinec             C   s   | j r| j jS d S )N)r  r   )rD   r?   r?   r@   r   
  s    zTextIOWrapper.newlines)NNNFF)NNNFF)N)r   r   r   r   )N)r   )N)N)+rH   rI   rJ   r7  r   r   r
  r  r   r   r5   r6   r<   r  r>   r)  r*  r^   ra   rc   r[   r2   re   rS   r)   r&   r   r'  r1  r,  r4  r6  r<  rD  rG  rX   rY   r   rU   rr   rz   rv   r   r?   r?   r?   r@   r0   ~  sT    
' 
#'

* 
	c

K
	
]r0   c                   sN   e Zd Zd fdd	Zdd Zdd Zed	d
 Zedd Zdd Z	  Z
S )StringIOr   r   c                sf   t t| jt dd|d |d kr(d| _|d k	rbt|tsNtdt	|j
| | | d d S )Nzutf-8surrogatepass)r5   r6   r7   Fz*initial_value must be str or None, not {0}r   )r   rO  r   r   r"  r   r   r   r   r  rH   r   rU   )rD   Zinitial_valuer7   )rR   r?   r@   r   $
  s    

zStringIO.__init__c          	   C   sL   |    | jp|  }| }|  z|j| j ddS || X d S )NT)r   )	r[   r  r1  r  r  r   r>   r   r  )rD   r   Z	old_stater?   r?   r@   r   4
  s    zStringIO.getvaluec             C   s
   t | S )N)objectr   )rD   r?   r?   r@   r   >
  s    zStringIO.__repr__c             C   s   d S )Nr?   )rD   r?   r?   r@   r6   C
  s    zStringIO.errorsc             C   s   d S )Nr?   )rD   r?   r?   r@   r5   G
  s    zStringIO.encodingc             C   s   |  d d S )Nr   )rT   )rD   r?   r?   r@   r   K
  s    zStringIO.detach)r   r   )rH   rI   rJ   r   r   r   r   r6   r5   r   r   r?   r?   )rR   r@   rO  
  s   
rO  )r   r   NNNTN)2r   abcr   r   r   sys_threadr   r   platformZmsvcrtr   r   ior   r   r   r	   r   ro   addr   	SEEK_DATAr'   r   rA   rB   rK   rP   r,   r+   r!   ABCMetarQ   registerr   _ior%   r   r   r   r/   r.   r   r-   r   r   r   r0   rO  r?   r?   r?   r@   <module>   sr   


 
 T	
  =
gi  CiIJ  U@U     $