a �DOg�l�@szdZddlZddlZddlZddlZddlZddlZddlmZ ej dvrXddl m Z ndZ ddlZddlmZmZmZmZhd�Zeed�r�e�ej�e�ej�d ZeZeed �p�ejjZeZd6dd�Zdd�Zz ej Z Wne!�y�eZ Yn0Gdd�d�Z"Gdd�d�Z#z ej$Z$Wn&e!�yFGdd�de%e&�Z$Yn0Gdd�dej'd�Z(ej(�)e(�Gdd�de(�Z*ej*�)e*�ddl+m,Z,e*�)e,�Gdd�de(�Z-ej-�)e-�Gd d!�d!e-�Z.Gd"d#�d#e-�Z/Gd$d%�d%e.�Z0Gd&d'�d'e.�Z1Gd(d)�d)e-�Z2Gd*d+�d+e1e0�Z3Gd,d-�d-e*�Z,Gd.d/�d/e(�Z4ej4�)e4�Gd0d1�d1ej5�Z6Gd2d3�d3e4�Z7Gd4d5�d5e7�Z8dS)7z) Python implementation of the io module. �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 1 to indicate the size of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows: * Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device's "block size" and falling back on `io.DEFAULT_BUFFER_SIZE`. On many systems, the buffer will typically be 4096 or 8192 bytes long. * "Interactive" text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files. encoding is the str name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings. errors is an optional string that specifies how encoding errors are to be handled---this argument should not be used in binary mode. Pass 'strict' to raise a ValueError exception if there is an encoding error (the default of None has the same effect), or pass 'ignore' to ignore errors. (Note that ignoring encoding errors can lead to data loss.) See the documentation for codecs.register for a list of the permitted encoding error strings. newline is a string controlling how universal newlines works (it only applies to text mode). It can be None, '', '\n', '\r', and '\r\n'. It works as follows: * On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in '\n', '\r', or '\r\n', and these are translated into '\n' before being returned to the caller. If it is '', universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated. * On output, if newline is None, any '\n' characters written are translated to the system default line separator, os.linesep. If newline is '', no translation takes place. If newline is any of the other legal values, any '\n' characters written are translated to the given string. closedfd is a bool. If closefd is False, the underlying file descriptor will be kept open when the file is closed. This does not work when a file name is given and must be True in that case. The newly created file is non-inheritable. A custom opener can be used by passing a callable as *opener*. The underlying file descriptor for the file object is then obtained by calling *opener* with (*file*, *flags*). *opener* must return an open file descriptor (passing os.open as *opener* results in functionality similar to passing None). open() returns a file object whose type depends on the mode, and through which the standard file operations such as reading and writing are performed. When open() is used to open a file in a text mode ('w', 'r', 'wt', 'rt', etc.), it returns a TextIOWrapper. When used to open a file in a binary mode, the returned class varies: in read binary mode, it returns a BufferedReader; in write binary and append binary modes, it returns a BufferedWriter, and in read/write mode, it returns a BufferedRandom. It is also possible to use a string or bytearray as a file for both reading and writing. For strings StringIO can be used like a file opened in a text mode, and for bytes a BytesIO can be used like a file opened in a binary mode. zinvalid file: %rzinvalid mode: %rzinvalid buffering: %rN�invalid encoding: %r�invalid errors: %rzaxrwb+tU�xr �w�a�+�t�b�Uz4mode U cannot be combined with 'x', 'w', 'a', or '+'rz'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 argumentzaline buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used�)�openerFrzinvalid buffering sizezcan't have unbuffered text I/Ozunknown mode: %r)� isinstance�int�os�fspath�str�bytes� TypeError�set�len� ValueError�warnings�warn�DeprecationWarning�RuntimeWarning�FileIO�isatty�DEFAULT_BUFFER_SIZE�fstat�fileno� st_blksize�OSError�AttributeError�BufferedRandom�BufferedWriter�BufferedReader� TextIOWrapper�mode�close)�filer4� buffering�encoding�errors�newline�closefdrZmodesZcreating�reading�writingZ appendingZupdating�text�binaryr$�raw�result�line_buffering�bs�buffer�rE�/usr/lib64/python3.9/_pyio.py�open+s�{           � ������        rGcCs ddl}|�dtd�t|d�S)azOpens the provided file with mode ``'rb'``. This function should be used when the intent is to treat the contents as executable code. ``path`` should be an absolute path. When supported by the runtime, this function can be hooked in order to allow embedders more control over code files. This functionality is not supported on the current runtime. rNz(_pyio.open_code() may not be using hooksr �rb)r$r%r'rG)�pathr$rErErF�_open_code_with_warnings �rJc@seZdZdZddd�ZdS)� DocDescriptorz%Helper for builtins.open.__doc__ NcCs dtjS)Nz\open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True) )rG�__doc__)�self�obj�typrErErF�__get__s��zDocDescriptor.__get__)N)�__name__� __module__� __qualname__rLrPrErErErFrKsrKc@seZdZdZe�Zdd�ZdS)� OpenWrapperz�Wrapper for builtins.open Trick so that open won't become a bound method when stored as a class variable (as dbm.dumb does). See initstdio() in Python/pylifecycle.c. cOst|i|��S�N)rG)�cls�args�kwargsrErErF�__new__.szOpenWrapper.__new__N)rQrRrSrLrKrYrErErErFrT$srTc@s eZdZdS)�UnsupportedOperationN)rQrRrSrErErErFrZ7srZc@s�eZdZdZdd�Zd6dd�Zdd�Zd7d d �Zd d �ZdZ dd�Z dd�Z dd�Z d8dd�Z dd�Zd9dd�Zdd�Zd:dd�Zedd ��Zd;d!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd�IOBasea�The abstract base class for all I/O classes. This class provides dummy implementations for many methods that derived classes can override selectively; the default implementations represent a file that cannot be read, written or seeked. Even though IOBase does not declare read or write because their signatures will vary, implementations and clients should consider those methods part of the interface. Also, implementations may raise UnsupportedOperation when operations they do not support are called. The basic type used for binary data read from or written to a file is bytes. Other bytes-like objects are accepted as method arguments too. Text I/O classes work with str data. Note that calling any method (even inquiries) on a closed stream is undefined. Implementations may raise OSError in this case. IOBase (and its subclasses) support the iterator protocol, meaning that an IOBase object can be iterated over yielding the lines in a stream. IOBase also supports the :keyword:`with` statement. In this example, fp is closed after the suite of the with statement is complete: with open('spam.txt', 'r') as fp: fp.write('Spam and eggs!') cCstd|jj|f��dS)z@Internal: raise an OSError exception for unsupported operations.z%s.%s() not supportedN)rZ� __class__rQ)rM�namerErErF� _unsupported]s �zIOBase._unsupportedrcCs|�d�dS)a$Change stream position. Change the stream position to byte offset pos. Argument pos is interpreted relative to the position indicated by whence. Values for whence are ints: * 0 -- start of stream (the default); offset should be zero or positive * 1 -- current stream position; offset may be negative * 2 -- end of stream; offset is usually negative Some operating systems / file systems could provide additional values. Return an int indicating the new absolute position. �seekN�r^�rM�pos�whencerErErFr_dsz IOBase.seekcCs |�dd�S)z5Return an int indicating the current stream position.rr )r_�rMrErErF�telltsz IOBase.tellNcCs|�d�dS)z�Truncate file to size bytes. Size defaults to the current IO position as reported by tell(). Return the new size. �truncateNr`�rMrbrErErFrfxszIOBase.truncatecCs |��dS)zuFlush write buffers, if applicable. This is not implemented for read-only and non-blocking streams. N�� _checkClosedrdrErErF�flush�sz IOBase.flushFcCs&|js"z|��Wd|_nd|_0dS)ziFlush and close the IO object. This method has no effect if the file is already closed. TN)�_IOBase__closedrjrdrErErFr5�s z IOBase.closecCsTz |j}WntyYdS0|r(dStr6|��nz |��Wn Yn0dS)zDestructor. Calls close().N)�closedr/�_IOBASE_EMITS_UNRAISABLEr5)rMrlrErErF�__del__�s    zIOBase.__del__cCsdS)z�Return a bool indicating whether object supports random access. If False, seek(), tell() and truncate() will raise OSError. This method may need to do a test seek(). FrErdrErErF�seekable�szIOBase.seekablecCs |��st|durdn|��dS)zEInternal: raise UnsupportedOperation if file is not seekable NzFile or stream is not seekable.)rorZ�rM�msgrErErF�_checkSeekable�s ��zIOBase._checkSeekablecCsdS)zvReturn a bool indicating whether object was opened for reading. If False, read() will raise OSError. FrErdrErErF�readable�szIOBase.readablecCs |��st|durdn|��dS)zEInternal: raise UnsupportedOperation if file is not readable NzFile or stream is not readable.)rsrZrprErErF�_checkReadable�s ��zIOBase._checkReadablecCsdS)z�Return a bool indicating whether object was opened for writing. If False, write() and truncate() will raise OSError. FrErdrErErF�writable�szIOBase.writablecCs |��st|durdn|��dS)zEInternal: raise UnsupportedOperation if file is not writable NzFile or stream is not writable.)rurZrprErErF�_checkWritable�s ��zIOBase._checkWritablecCs|jS)z�closed: bool. True iff the file has been closed. For backwards compatibility, this is a property, not a predicate. )rkrdrErErFrl�sz IOBase.closedcCs|jrt|durdn|��dS)z7Internal: raise a ValueError if file is closed N�I/O operation on closed file.�rlr#rprErErFri�s ��zIOBase._checkClosedcCs |��|S)zCContext management protocol. Returns self (an instance of IOBase).rhrdrErErF� __enter__�szIOBase.__enter__cGs |��dS)z+Context management protocol. Calls close()N)r5)rMrWrErErF�__exit__�szIOBase.__exit__cCs|�d�dS)z�Returns underlying file descriptor (an int) if one exists. An OSError is raised if the IO object does not use a file descriptor. r,Nr`rdrErErFr,�sz IOBase.filenocCs |��dS)z{Return a bool indicating whether this is an 'interactive' stream. Return False if it can't be determined. FrhrdrErErFr)sz IOBase.isattyrcs�t�d�r��fdd�}ndd�}�dur0d�n2z �j}Wn tyZt��d���Yn0|��t�}�dks|t|��kr���|��}|s�q�||7}|�d �rhq�qht|�S) aNRead and return a line of bytes from the stream. If size is specified, at most size bytes will be read. Size should be an int. The line terminator is always b'\n' for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized. �peekcs>��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�!sNr� is not an integerrr|) �hasattr� __index__r/r � bytearrayr"�read�endswithr)rMr�r�� size_index�resrrEr�rF�readline s&      zIOBase.readlinecCs |��|SrUrhrdrErErF�__iter__6szIOBase.__iter__cCs|��}|st�|SrU)r�� StopIteration�rM�linerErErF�__next__:szIOBase.__next__cCsP|dus|dkrt|�Sd}g}|D]&}|�|�|t|�7}||kr$qLq$|S)z�Return a list of lines from the stream. hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint. Nr)�list�appendr")rM�hintr�linesr�rErErF� readlines@s  zIOBase.readlinescCs |��|D]}|�|�q dS)z�Write a list of lines to the stream. Line separators are not added, so it is usual for each of the lines provided to have a line separator at the end. N)ri�write)rMr�r�rErErF� writelinesRszIOBase.writelines)r)N)N)N)N)N)r)N)rQrRrSrLr^r_rerfrjrkr5rnrorrrsrtrurv�propertyrlriryrzr,r)r�r�r�r�r�rErErErFr[;s6          * r[)� metaclassc@s2eZdZdZd dd�Zdd�Zdd�Zd d �Zd S) � RawIOBasezBase class for raw binary I/O.rcCsP|dur d}|dkr|��St|���}|�|�}|dur>dS||d�=t|�S)z�Read and return up to size bytes, where size is an int. Returns an empty bytes object on EOF, or None if the object is set not to block and has no data to read. Nrr)�readallr�r��readintor)rMr�rrrErErFr�ms   zRawIOBase.readcCs4t�}|�t�}|sq ||7}q|r,t|�S|SdS)z+Read until EOF, using multiple read() call.N)r�r�r*r)rMr��datarErErFr�~s  zRawIOBase.readallcCs|�d�dS)z�Read bytes into a pre-allocated bytes-like object b. Returns an int representing the number of bytes read (0 for EOF), or None if the object is set not to block and has no data to read. r�Nr`�rMrrErErFr��szRawIOBase.readintocCs|�d�dS)z�Write the given buffer to the IO stream. Returns the number of bytes written, which may be less than the length of b in bytes. r�Nr`r�rErErFr��szRawIOBase.writeN)r)rQrRrSrLr�r�r�r�rErErErFr�_s  r�)r(c@sLeZdZdZddd�Zddd�Zdd�Zd d �Zd d �Zd d�Z dd�Z dS)�BufferedIOBaseaBase class for buffered IO objects. The main difference with RawIOBase is that the read() method supports omitting the size argument, and does not have a default implementation that defers to readinto(). In addition, read(), readinto() and write() may raise BlockingIOError if the underlying raw stream is in non-blocking mode and not ready; unlike their raw counterparts, they will never return None. A typical implementation should not inherit from a RawIOBase implementation, but wrap one. rcCs|�d�dS)a�Read and return up to size bytes, where size is an int. If the argument is omitted, None, or negative, reads and returns all data until EOF. If the argument is positive, and the underlying raw stream is not 'interactive', multiple raw reads may be issued to satisfy the byte count (unless EOF is reached first). But for interactive raw streams (XXX and for pipes?), at most one raw read will be issued, and a short result does not imply that EOF is imminent. Returns an empty bytes array on EOF. Raises BlockingIOError if the underlying raw stream has no data at the moment. r�Nr`r�rErErFr��szBufferedIOBase.readcCs|�d�dS)zaRead up to size bytes with at most one read() system call, where size is an int. �read1Nr`r�rErErFr��szBufferedIOBase.read1cCs|j|dd�S)afRead bytes into a pre-allocated bytes-like object b. Like read(), this may issue multiple reads to the underlying raw stream, unless the latter is 'interactive'. Returns an int representing the number of bytes read (0 for EOF). Raises BlockingIOError if the underlying raw stream has no data at the moment. F�r��� _readintor�rErErFr��s zBufferedIOBase.readintocCs|j|dd�S)z�Read bytes into buffer *b*, using at most one system call Returns an int representing the number of bytes read (0 for EOF). Raises BlockingIOError if the underlying raw stream has no data at the moment. Tr�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�rrErErFr��s   zBufferedIOBase._readintocCs|�d�dS)aWrite the given bytes buffer to the IO stream. Return the number of bytes written, which is always the length of b in bytes. Raises BlockingIOError if the buffer is full and the underlying raw stream cannot accept more data at the moment. r�Nr`r�rErErFr��s zBufferedIOBase.writecCs|�d�dS)z� Separate the underlying raw stream from the buffer and return it. After the raw stream has been detached, the buffer is in an unusable state. �detachNr`rdrErErFr��szBufferedIOBase.detachN)r)r) rQrRrSrLr�r�r�r�r�r�r�rErErErFr��s    r�c@s�eZdZdZdd�Zd$dd�Zdd�Zd%d d �Zd d �Zdd�Z dd�Z dd�Z e dd��Z e dd��Ze dd��Ze dd��Zdd�Zdd�Zd d!�Zd"d#�Zd S)&�_BufferedIOMixinz�A mixin implementation of BufferedIOBase with an underlying raw stream. This passes most requests on to the underlying raw stream. It does *not* provide implementations of read(), readinto() or write(). cCs ||_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@rer.rgrErErFres z_BufferedIOMixin.tellNcCs4|��|��|��|dur(|��}|j�|�SrU)rirvrjrer@rfrgrErErFrf%s z_BufferedIOMixin.truncatecCs|jrtd��|j��dS)N�flush on closed file)rlr#r@rjrdrErErFrj6sz_BufferedIOMixin.flushcCs8|jdur4|js4z|��W|j��n |j��0dSrU)r@rlrjr5rdrErErFr5;s z_BufferedIOMixin.closecCs*|jdurtd��|��|j}d|_|S)Nzraw stream already detached)r@r#rjr�r�rErErFr�Cs  z_BufferedIOMixin.detachcCs |j��SrU)r@rordrErErFroMsz_BufferedIOMixin.seekablecCs|jSrUr�rdrErErFr@Psz_BufferedIOMixin.rawcCs|jjSrU)r@rlrdrErErFrlTsz_BufferedIOMixin.closedcCs|jjSrU)r@r]rdrErErFr]Xsz_BufferedIOMixin.namecCs|jjSrU)r@r4rdrErErFr4\sz_BufferedIOMixin.modecCstd|jj�d���dS�Nzcannot pickle z object�r r\rQrdrErErF� __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,rdrErErFr,osz_BufferedIOMixin.filenocCs |j��SrU)r@r)rdrErErFr)rsz_BufferedIOMixin.isatty)r)N)rQrRrSrLr�r_rerfrjr5r�ror�r@rlr]r4r�r�r,r)rErErErFr� s*        r�cs�eZdZdZdZd!dd�Zdd�Zdd�Zd d �Z�fd d �Z d"dd�Z d#dd�Z dd�Z d$dd�Z dd�Zd%dd�Zdd�Zdd�Zdd �Z�ZS)&�BytesIOz0YdS)z�Read size bytes. Returns exactly size bytes of data unless the underlying raw IO stream reaches EOF or if the call would block in non-blocking mode. If size is negative, read until EOF or until read() would block. 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~) rMrZ nodata_valZ empty_valuesr�rb�chunk�chunksZ current_size�availZwanted�outrErErFr�1sL             zBufferedReader._read_unlockedrcCs4|j�|�|�Wd�S1s&0YdS)z�Returns buffered bytes without advancing the position. The argument indicates a desired minimal number of bytes; we do at most one raw read to satisfy it. We never return more than self.buffer_size. N)r��_peek_unlockedr�rErErFr{eszBufferedReader.peekcCsrt||j�}t|j�|j}||ks,|dkrb|j|}|j�|�}|rb|j|jd�||_d|_|j|jd�Sr�)r~r�r"r�r�r@r�)rMrZwantZhaveZto_read�currentrErErFr�os   zBufferedReader._peek_unlockedrcCsj|dkr|j}|dkrdS|j�6|�d�|�t|t|j�|j��Wd�S1s\0YdS)zd |_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)adOpen a file. The mode can be 'r' (default), 'w', 'x' or 'a' for reading, writing, exclusive creation or appending. The file will be created if it doesn't exist when opened for writing or appending; it will be truncated when opened for writing. A FileExistsError will be raised if it already exists when opened for creating. Opening a file for creating implies writing so this mode behaves in a similar way to 'w'. Add a '+' to the mode to allow simultaneous reading and writing. A custom opener can be used by passing a callable as *opener*. The underlying file descriptor for the file object is then obtained by calling opener with (*name*, *flags*). *opener* must return an open file descriptor (passing os.open as *opener* results in functionality similar to passing None). rrz$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_CLOEXECNz'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�r�rlr$r%�ResourceWarningr5)rMr$rErErFrnEs �zFileIO.__del__cCstd|jj�d���dSr�r�rdrErErFr�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\rRrSrlr]r/r�r4r�)rM� class_namer]rErErFr�Os�  � �zFileIO.__repr__cCs|jstd��dS)NzFile not open for reading)rrZrdrErErFrt]szFileIO._checkReadablecCs|jstd��dS)NzFile not open for writing)r�rZrprErErFrvaszFileIO._checkWritablecCsR|��|��|dus |dkr(|��Szt�|j|�WStyLYdS0dS)z�Read at most size bytes, returned as bytes. Only makes one system call, so less data may be returned than requested In non-blocking mode, returns None if no data is available. Return an empty bytes object at EOF. Nr)rirtr�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|�S)z�Read all data from the file, returned as bytes. In non-blocking mode, returns as much as is immediately available, or None if no data is available. Return an empty bytes object at EOF. rr N)rirtr*rrr�rr+�st_sizer.r�r"r�r�r�r)rM�bufsizerb�endrArr�rErErFr�us2     zFileIO.readallcCs4t|��d�}|�t|��}t|�}||d|�<|S)zSame as RawIOBase.readinto().r�N)r�r�r�r")rMr�mr�rrErErFr��s  zFileIO.readintocCs:|��|��zt�|j|�WSty4YdS0dS)aWrite bytes b to file, return number written. Only makes one system call, so not all of the data may be written. The number of bytes actually written is returned. In non-blocking mode, returns None if the write would block. N)rirvrr�r�r�r�rErErFr��s  z FileIO.writecCs*t|t�rtd��|��t�|j||�S)a�Move to new file position. Argument offset is a byte count. Optional argument whence defaults to SEEK_SET or 0 (offset from start of file, offset should be >= 0); other values are SEEK_CUR or 1 (move relative to current position, positive or negative), and SEEK_END or 2 (move relative to end of file, usually negative, although many platforms allow seeking beyond the end of a file). Note that not all file objects are seekable. zan integer is required)rr�r rirrr�rarErErFr_�s z FileIO.seekcCs|��t�|jdt�S)zYtell() -> int. Current file position. Can raise OSError for non seekable files.r)rirrr�rrdrErErFre�sz FileIO.tellcCs2|��|��|dur |��}t�|j|�|S)z�Truncate the file to at most size bytes. Size defaults to the current file position, as returned by tell(). The current file position is changed to the value of size. N)rirvrer� ftruncater�r�rErErFrf�s zFileIO.truncatecs8|js4z |jrt�|j�Wt���n t���0dS)z�Close the file. A closed file cannot be used for further I/O operations. close() may be called more than once without error. N)rlr�rr5r�r�rdr�rErFr5�s z FileIO.closecCsD|��|jdur>z |��Wnty6d|_Yn0d|_|jS)z$True if file supports random-access.NFT)ri� _seekablerer.rdrErErFro�s    zFileIO.seekablecCs|��|jS)z'True if file was opened in a read mode.)rirrdrErErFrs�szFileIO.readablecCs|��|jS)z(True if file was opened in a write mode.)rir�rdrErErFru�szFileIO.writablecCs|��|jS)z3Return the underlying file descriptor (an integer).)rir�rdrErErFr,�sz FileIO.filenocCs|��t�|j�S)z.True if the file is connected to a TTY device.)rirr)r�rdrErErFr)�sz FileIO.isattycCs|jS)z6True if the file descriptor will be closed by close().)r�rdrErErFr;�szFileIO.closefdcCsJ|jr|jrdSdSn0|jr,|jr&dSdSn|jrB|jr�Z#d?d@�Z$dSdAdB�Z%dCdD�Z&dTdEdF�Z'dUdGdH�Z(dIdJ�Z)dVdKdL�Z*e dMdN��Z+dS)Wr3aCharacter and line based layer over a BufferedIOBase object, buffer. encoding gives the name of the encoding that the stream will be decoded or encoded with. It defaults to locale.getpreferredencoding(False). errors determines the strictness of encoding and decoding (see the codecs.register) and defaults to "strict". newline can be None, '', '\n', '\r', or '\r\n'. It controls the handling of line endings. If it is None, universal newlines is enabled. With this enabled, on input, the lines endings '\n', '\r', or '\r\n' are translated to '\n' before being returned to the caller. Conversely, on output, '\n' is translated to the system default line separator, os.linesep. If newline is any other of its legal values, that newline becomes the newline when the file is read and it is returned untranslated. On output, '\n' is converted to the newline. If line_buffering is True, a call to flush is implied when a call to write contains a newline character. iNFc 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� _snapshotrDror�_tellingr�� _has_read1� _configure) rMrDr8r9r:rB� write_throughr@rqrErErFr��s@             �zTextIOWrapper.__init__cCs>|dur$t|t�s$tdt|�f��|dvr:td|f��dS)Nzillegal newline type: %r)Nrr.r,r-zillegal newline value: %r)rrr �typer#)rMr:rErErFr>�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_throughrrurDre� _get_encoderr9rE)rMr8r9r:rBrN�positionrErErFrMs&     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)rQrdrErErFr88szTextIOWrapper.encodingcCs|jSrU)rRrdrErErFr9<szTextIOWrapper.errorscCs|jSrU)r\rdrErErFrB@szTextIOWrapper.line_bufferingcCs|jSrU)r]rdrErErFrNDszTextIOWrapper.write_throughcCs|jSrU)r�rdrErErFrDHszTextIOWrapper.buffer)r8r9r:rBrNcCs�|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)z`Reconfigure the text stream with new parameters. This also flushes the stream. NzPIt is not possible to set the encoding or newline of stream after the first readr#rr)rT�EllipsisrZrRrrr rQrXr>rBrNrjrM)rMr8r9r:rBrNrErErF� reconfigureLs> ����      �zTextIOWrapper.reconfigurecCs|jrtd��|jS)Nrw)rlr#rrdrErErFrouszTextIOWrapper.seekablecCs |j��SrU)rDrsrdrErErFrszszTextIOWrapper.readablecCs |j��SrU)rDrurdrErErFru}szTextIOWrapper.writablecCs|j��|j|_dSrU)rDrjrrKrdrErErFrj�s zTextIOWrapper.flushcCs8|jdur4|js4z|��W|j��n |j��0dSrU)rDrlrjr5rdrErErFr5�s zTextIOWrapper.closecCs|jjSrU)rDrlrdrErErFrl�szTextIOWrapper.closedcCs|jjSrU)rDr]rdrErErFr]�szTextIOWrapper.namecCs |j��SrU)rDr,rdrErErFr,�szTextIOWrapper.filenocCs |j��SrU)rDr)rdrErErFr)�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)zWrite data, where s is a strr�zcan't write %s to text streamr.r,rN)rlr#rrr r\rQr"rYr\r[r3rSr^�encoderDr�rj�_set_decoded_charsrJrTr;)rMr �lengthZhaslf�encoderrrErErFr��s( �    zTextIOWrapper.writecCst�|j�}||j�|_|jSrU)r$�getincrementalencoderrQrRrS)rMZ make_encoderrErErFr^�s  zTextIOWrapper._get_encodercCs2t�|j�}||j�}|jr(t||j�}||_|SrU)r$�getincrementaldecoderrQrRrVr"rWrT)rMZ make_decoderr'rErErF� _get_decoder�s    zTextIOWrapper._get_decodercCs||_d|_dS)zSet the _decoded_chars buffer.rN)rHrI)rM�charsrErErFrc�sz TextIOWrapper._set_decoded_charscCsF|j}|dur|j|d�}n|j|||�}|jt|�7_|S)z'Advance into the _decoded_chars buffer.N)rIrHr")rMr�offsetrirErErF�_get_decoded_chars�s z TextIOWrapper._get_decoded_charscCs$|j|krtd��|j|8_dS)z!Rewind the _decoded_chars buffer.z"rewind decoded_chars out of boundsN)rI�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)zQ Read and decode the next chunk of data from the BufferedReader. Nz no decoderrP)rTr#rKr6rLrDr�� _CHUNK_SIZEr�r/rcr"rHrUrJ)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�@����)r8)rMr_rp� bytes_to_feed�need_eof� chars_to_skiprErErF� _pack_cookie�s � �zTextIOWrapper._pack_cookiecCsJt|d�\}}t|d�\}}t|d�\}}t|d�\}}|||t|�|fS)Nl)�divmodr8)rMZbigint�restr_rprxryrzrErErF�_unpack_cookie s zTextIOWrapper._unpack_cookiec Csb|jstd��|jstd��|��|j��}|j}|dusF|jdurX|j rTt d��|S|j\}}|t |�8}|j }|dkr�|� ||�S|��}�z�t|j|�}d}|t |�ks�J�|dk�r4|�d|f�t |�|d|���} | |k�r"|��\} } | �s| }|| 8}�qF|t | �8}d}q�||8}|d}q�d}|�d|f�||} |} |dk�rt|� | | �W|�|�Sd}d}d}t|t |��D]x}|d7}|t |�|||d���7}|��\}}|�s�||k�r�| |7} ||8}|dd} }}||k�r��q4�q�|t |jdd d ��7}d }||k�r4td ��|� | | |||�W|�|�S|�|�0dS) N�!underlying stream is not seekablez(telling position disabled by next() callzpending decoded textrr r�r FTr*z'can't reconstruct logical file position)rrZrKr.rjrDrerTrJrHrlr"rIr{r6rrUr9r/�range)rMr_r'rpZ next_inputrz� saved_stateZ skip_bytesZ skip_backrr�d� start_posZ start_flagsZ bytes_fedryZ chars_decoded�irorErErFre s�           �     � �zTextIOWrapper.tellcCs$|��|dur|��}|j�|�SrU)rjrerDrfrgrErErFrfs szTextIOWrapper.truncatecCs*|jdurtd��|��|j}d|_|S)Nzbuffer is already detached)rDr#rjr�)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|��dS)z9Reset the encoder (merely useful for proper BOM handling)rN)rSr^rEr9r;)r_rerdrErF�_reset_encoder� s  z*TextIOWrapper.seek.._reset_encoderr�rrz#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)rlr#rrZrrer rjrDr_rcrJrTr;r~rhr9r�r/r"rHr.rI) rMZcookiercr�r_r�rprxryrzrqrErdrFr_� 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�rTr*rF)rtr�r/r rTrhrkr/rDr�rcrJr"rs)rMr�r�r'rArrrErErFr�� s,  �   zTextIOWrapper.readcCs(d|_|��}|s$d|_|j|_t�|S)NF)rKr�rJrr�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�rr.r r,r r)rlr#r�r/r rkrTrhrWr}r"rVrXrsrHrcrJrm) rMr�r�r��startrb�endposZnlposZcrposrErErFr�� st             zTextIOWrapper.readlinecCs|jr|jjSdSrU)rTr!rdrErErFr!N szTextIOWrapper.newlines)NNNFF)NNNFF)N)rrFr)N)r)N)N),rQrRrSrLrnr�r�r>rMr�r�r8r9rBrNrDr`rarorsrurjr5rlr]r,r)r�r^rhrcrkrmrsr{r~rerfr�r_r�r�r�r!rErErErFr3�sn� *� $     � )    *� c  K  ]r3csReZdZdZd�fdd� Zdd�Zdd �Zed d ��Zed d ��Z dd�Z �Z S)�StringIOz�Text I/O implementation using an in-memory buffer. The initial_value argument sets the value of object. The newline argument is like the one of TextIOWrapper's constructor. rr.csftt|�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�rYrrr r�rOrQr�r_)rMZ initial_valuer:r�rErFr�Z s� � zStringIO.__init__c CsX|��|jp|��}|��}|��z |j|j��dd�W|�|�S|�|�0dS)NTr*) rjrTrhr6r;r/rDr�r9)rMr'Z old_staterErErFr�j s �zStringIO.getvaluecCs t�|�SrU)�objectr�rdrErErFr�t szStringIO.__repr__cCsdSrUrErdrErErFr9y szStringIO.errorscCsdSrUrErdrErErFr8} szStringIO.encodingcCs|�d�dS)Nr�r`rdrErErFr�� szStringIO.detach)rr.) rQrRrSrLr�r�r�r�r9r8r�r�rErEr�rFr�S s   r�)r rNNNTN)9rLr�abcr$r�r �sys�_threadrr��platform�msvcrtrr�iorrrr r�r��addr � SEEK_DATAr*r�r�dev_modermrFrGrJ� open_coder/rKrTrZr.r#�ABCMetar[�registerr��_ior(r�r�r�r2r1r�r0rr%r"r3r�rErErErF�s�     � [    # =   g kCiIJY@ U&