AlkantarClanX12

Your IP : 3.12.73.149


Current Path : /opt/alt/python39/lib64/python3.9/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/__pycache__/_pyio.cpython-39.opt-1.pyc

a

R�f�l�@szdZddlZddlZddlZddlZddlZddlZddlmZ	ej
dvrXddlm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>�cygwinZwin32)�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<t||�}n|
�rNt||�}nt	d#|��|}|�rj|WSt|||||�}|}||_|WS|���Yn0dS)$a�Open file and return a stream.  Raise OSError upon failure.

    file is either a text or byte string giving the name (and the path
    if the file isn't in the current working directory) of the file to
    be opened or an integer file descriptor of the file to be
    wrapped. (If a file descriptor is given, it is closed when the
    returned I/O object is closed, unless closefd is set to False.)

    mode is an optional string that specifies the mode in which the file is
    opened. It defaults to 'r' which means open for reading in text mode. Other
    common values are 'w' for writing (truncating the file if it already
    exists), 'x' for exclusive creation of a new file, and 'a' for appending
    (which on some Unix systems, means that all writes append to the end of the
    file regardless of the current seek position). In text mode, if encoding is
    not specified the encoding used is platform dependent. (For reading and
    writing raw bytes use binary mode and leave encoding unspecified.) The
    available modes are:

    ========= ===============================================================
    Character Meaning
    --------- ---------------------------------------------------------------
    'r'       open for reading (default)
    'w'       open for writing, truncating the file first
    'x'       create a new file and open it for writing
    'a'       open for writing, appending to the end of the file if it exists
    'b'       binary mode
    't'       text mode (default)
    '+'       open a disk file for updating (reading and writing)
    'U'       universal newline mode (deprecated)
    ========= ===============================================================

    The default mode is 'rt' (open for reading text). For binary random
    access, the mode 'w+b' opens and truncates the file to 0 bytes, while
    'r+b' opens the file without truncation. The 'x' mode implies 'w' and
    raises an `FileExistsError` if the file already exists.

    Python distinguishes between files opened in binary and text modes,
    even when the underlying operating system doesn't. Files opened in
    binary mode (appending 'b' to the mode argument) return contents as
    bytes objects without any decoding. In text mode (the default, or when
    't' is appended to the mode argument), the contents of the file are
    returned as strings, the bytes having been first decoded using a
    platform-dependent encoding or using the specified encoding if given.

    'U' mode is deprecated and will raise an exception in future versions
    of Python.  It has no effect in Python 3.  Use newline to control
    universal newlines mode.

    buffering is an optional integer used to set the buffering policy.
    Pass 0 to switch buffering off (only allowed in binary mode), 1 to select
    line buffering (only usable in text mode), and an integer > 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�)�openerFr
zinvalid 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)�filer3�	buffering�encoding�errors�newline�closefdrZmodesZcreatingZreadingZwritingZ	appendingZupdating�textZbinaryr#�raw�result�line_bufferingZbs�buffer�r@�*/opt/alt/python39/lib64/python3.9/_pyio.py�open+s�{




�������



rBcCs 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&rB)�pathr#r@r@rA�_open_code_with_warnings
�rEc@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)

)rB�__doc__)�self�obj�typr@r@rA�__get__s��zDocDescriptor.__get__)N)�__name__�
__module__�__qualname__rGrKr@r@r@rArFsrFc@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)rB)�cls�args�kwargsr@r@rA�__new__.szOpenWrapper.__new__N)rLrMrNrGrFrTr@r@r@rArO$srOc@seZdZdS)�UnsupportedOperationN)rLrMrNr@r@r@rArU7srUc@s�eZdZdZdd�Zd6dd�Zdd�Zd7d
d�Zdd
�ZdZ	dd�Z
dd�Zdd�Zd8dd�Z
dd�Zd9dd�Zdd�Zd:dd�Zedd ��Zd;d!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd<d,d-�Zd.d/�Zd0d1�Zd=d2d3�Zd4d5�Zd	S)>�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)rU�	__class__rL)rH�namer@r@rA�_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�rY�rH�pos�whencer@r@rArZdszIOBase.seekcCs|�dd�S)z5Return an int indicating the current stream position.rr	)rZ�rHr@r@rA�telltszIOBase.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[�rHr]r@r@rAraxszIOBase.truncatecCs|��dS)zuFlush write buffers, if applicable.

        This is not implemented for read-only and non-blocking streams.
        N��_checkClosedr_r@r@rA�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__closedrer_r@r@rAr4�s
zIOBase.closecCsTz
|j}WntyYdS0|r(dStr6|��nz|��WnYn0dS)zDestructor.  Calls close().N)�closedr.�_IOBASE_EMITS_UNRAISABLEr4)rHrgr@r@rA�__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().
        Fr@r_r@r@rA�seekable�szIOBase.seekablecCs |��st|durdn|��dS)zEInternal: raise UnsupportedOperation if file is not seekable
        NzFile or stream is not seekable.)rjrU�rH�msgr@r@rA�_checkSeekable�s��zIOBase._checkSeekablecCsdS)zvReturn a bool indicating whether object was opened for reading.

        If False, read() will raise OSError.
        Fr@r_r@r@rA�readable�szIOBase.readablecCs |��st|durdn|��dS)zEInternal: raise UnsupportedOperation if file is not readable
        NzFile or stream is not readable.)rnrUrkr@r@rA�_checkReadable�s��zIOBase._checkReadablecCsdS)z�Return a bool indicating whether object was opened for writing.

        If False, write() and truncate() will raise OSError.
        Fr@r_r@r@rA�writable�szIOBase.writablecCs |��st|durdn|��dS)zEInternal: raise UnsupportedOperation if file is not writable
        NzFile or stream is not writable.)rprUrkr@r@rA�_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.
        )rfr_r@r@rArg�sz
IOBase.closedcCs|jrt|durdn|��dS)z7Internal: raise a ValueError if file is closed
        N�I/O operation on closed file.�rgr"rkr@r@rArd�s��zIOBase._checkClosedcCs|��|S)zCContext management protocol.  Returns self (an instance of IOBase).rcr_r@r@rA�	__enter__�szIOBase.__enter__cGs|��dS)z+Context management protocol.  Calls close()N)r4)rHrRr@r@rA�__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[r_r@r@rAr+�sz
IOBase.filenocCs|��dS)z{Return a bool indicating whether this is an 'interactive' stream.

        Return False if it can't be determined.
        Frcr_r@r@rAr(sz
IOBase.isattyr
cs�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)rv�findr!�min)Z	readahead�n�rH�sizer@rA�
nreadaheads

z#IOBase.readline.<locals>.nreadaheadcSsdS�Nr	r@r@r@r@rAr}!sNr
� is not an integerrrw)	�hasattr�	__index__r.r�	bytearrayr!�read�endswithr)rHr|r}�
size_index�resrr@r{rA�readlines&
	

zIOBase.readlinecCs|��|SrPrcr_r@r@rA�__iter__6szIOBase.__iter__cCs|��}|st�|SrP)r��
StopIteration�rH�liner@r@rA�__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!)rH�hintrz�linesr�r@r@rA�	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)rd�write)rHr�r�r@r@rA�
writelinesRszIOBase.writelines)r)N)N)N)N)N)r
)N)rLrMrNrGrYrZr`rarerfr4rirjrmrnrorprq�propertyrgrdrtrur+r(r�r�r�r�r�r@r@r@rArV;s6 







	

*
rV)�	metaclassc@s2eZdZdZddd�Zdd�Zdd�Zd	d
�ZdS)
�	RawIOBasezBase class for raw binary I/O.r
cCsP|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.
        Nr
r)�readallr�r��readintor)rHr|rrzr@r@rAr�ms

zRawIOBase.readcCs4t�}|�t�}|sq ||7}q|r,t|�S|SdS)z+Read until EOF, using multiple read() call.N)r�r�r)r)rHr��datar@r@rAr�~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[�rHrr@r@rAr��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�r@r@rAr��szRawIOBase.writeN)r
)rLrMrNrGr�r�r�r�r@r@r@rAr�_s

r�)r'c@sLeZdZdZddd�Zddd�Zdd�Zd	d
�Zdd�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.
    r
cCs|�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{r@r@rAr��szBufferedIOBase.readcCs|�d�dS)zaRead up to size bytes with at most one read() system call,
        where size is an int.
        �read1Nr[r{r@r@rAr��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�r@r@rAr��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�r@r@rA�	readinto1�s	zBufferedIOBase.readinto1cCsVt|t�st|�}|�d�}|r0|�t|��}n|�t|��}t|�}||d|�<|S)N�B)r�
memoryview�castr�r!r�)rHrr�r�rzr@r@rAr��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�r@r@rAr��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[r_r@r@rAr��szBufferedIOBase.detachN)r
)r
)rLrMrNrGr�r�r�r�r�r�r�r@r@r@rAr��s

r�c@s�eZdZdZdd�Zd$dd�Zdd�Zd%d
d�Zdd
�Zdd�Z	dd�Z
dd�Ze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
||_dSrP��_raw�rHr<r@r@rA�__init__sz_BufferedIOMixin.__init__rcCs"|j�||�}|dkrtd��|S)Nrz#seek() returned an invalid position)r<rZr-)rHr]r^Znew_positionr@r@rArZsz_BufferedIOMixin.seekcCs|j��}|dkrtd��|S)Nrz#tell() returned an invalid position)r<r`r-rbr@r@rAr`s
z_BufferedIOMixin.tellNcCs4|��|��|��|dur(|��}|j�|�SrP)rdrqrer`r<rarbr@r@rAra%sz_BufferedIOMixin.truncatecCs|jrtd��|j��dS)N�flush on closed file)rgr"r<rer_r@r@rAre6sz_BufferedIOMixin.flushcCs8|jdur4|js4z|��W|j��n|j��0dSrP)r<rgrer4r_r@r@rAr4;s
z_BufferedIOMixin.closecCs*|jdurtd��|��|j}d|_|S)Nzraw stream already detached)r<r"rer�r�r@r@rAr�Cs
z_BufferedIOMixin.detachcCs
|j��SrP)r<rjr_r@r@rArjMsz_BufferedIOMixin.seekablecCs|jSrPr�r_r@r@rAr<Psz_BufferedIOMixin.rawcCs|jjSrP)r<rgr_r@r@rArgTsz_BufferedIOMixin.closedcCs|jjSrP)r<rXr_r@r@rArXXsz_BufferedIOMixin.namecCs|jjSrP)r<r3r_r@r@rAr3\sz_BufferedIOMixin.modecCstd|jj�d���dS�Nzcannot pickle z object�rrWrLr_r@r@rA�__getstate__`sz_BufferedIOMixin.__getstate__cCsL|jj}|jj}z
|j}Wnty8d�||�YS0d�|||�SdS)Nz<{}.{}>z<{}.{} name={!r}>)rWrMrNrXr.�format)rH�modnameZclsnamerXr@r@rA�__repr__cs
z_BufferedIOMixin.__repr__cCs
|j��SrP)r<r+r_r@r@rAr+osz_BufferedIOMixin.filenocCs
|j��SrP)r<r(r_r@r@rAr(rsz_BufferedIOMixin.isatty)r)N)rLrMrNrGr�rZr`rarer4r�rjr�r<rgrXr3r�r�r+r(r@r@r@rAr�s*






r�cs�eZdZdZdZd!dd�Zdd�Zdd�Zd	d
�Z�fdd�Z	d"dd�Z
d#dd�Zdd�Zd$dd�Z
dd�Zd%dd�Zdd�Zdd�Zdd �Z�ZS)&�BytesIOz<Buffered I/O implementation using an in-memory bytes buffer.NcCs&t�}|dur||7}||_d|_dS�Nr)r��_buffer�_pos)rHZ
initial_bytes�bufr@r@rAr�~s
zBytesIO.__init__cCs|jrtd��|j��S)Nz__getstate__ on closed file)rgr"�__dict__�copyr_r@r@rAr��szBytesIO.__getstate__cCs|jrtd��t|j�S)z8Return the bytes value (contents) of the buffer
        zgetvalue on closed file)rgr"rr�r_r@r@rA�getvalue�szBytesIO.getvaluecCs|jrtd��t|j�S)z;Return a readable and writable view of the buffer.
        zgetbuffer on closed file)rgr"r�r�r_r@r@rA�	getbuffer�szBytesIO.getbuffercs"|jdur|j��t���dSrP)r��clear�superr4r_�rWr@rAr4�s

z
BytesIO.closer
cCs�|jrtd��|durd}n2z
|j}Wn tyFt|�d���Yn0|�}|dkr`t|j�}t|j�|jkrtdStt|j�|j|�}|j|j|�}||_t	|�S)N�read from closed filer
rr�)
rgr"r�r.rr!r�r�ryr)rHr|r�Znewposrr@r@rAr��s"

zBytesIO.readcCs
|�|�S)z"This is the same as read.
        )r�r{r@r@rAr��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�)
rgr"rrrr��nbytesr�r!r�)rHrZviewrzr]Zpaddingr@r@rAr��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 filerr�negative seek position %rr	r
zunsupported whence value)	rgr"r�r.rr��maxr!r�)rHr]r^�	pos_indexr@r@rArZ�s"
zBytesIO.seekcCs|jrtd��|jS)N�tell on closed file)rgr"r�r_r@r@rAr`�szBytesIO.tellcCsv|jrtd��|dur|j}nHz
|j}Wn tyHt|�d���Yn0|�}|dkrftd|f��|j|d�=|S)Nztruncate on closed filerrznegative truncate position %r)rgr"r�r�r.rr�)rHr]r�r@r@rAra�s
zBytesIO.truncatecCs|jrtd��dS�NrrTrsr_r@r@rArn�szBytesIO.readablecCs|jrtd��dSr�rsr_r@r@rArp�szBytesIO.writablecCs|jrtd��dSr�rsr_r@r@rArj�szBytesIO.seekable)N)r
)r
)r)N)rLrMrNrGr�r�r�r�r�r4r�r�r�rZr`rarnrprj�
__classcell__r@r@r�rAr�vs 




r�c@sxeZdZdZefdd�Zdd�Zdd�Zdd	d
�Zddd�Z	ddd�Z
ddd�Zddd�Zdd�Z
dd�Zd dd�ZdS)!r1aBufferedReader(raw[, buffer_size])

    A buffer for a readable, sequential BaseRawIO object.

    The constructor creates a BufferedReader for the given readable raw
    stream and buffer_size. If buffer_size is omitted, DEFAULT_BUFFER_SIZE
    is used.
    cCsF|��std��t�||�|dkr,td��||_|��t�|_dS)zMCreate a new buffered reader using the given readable raw IO object.
        z "raw" argument must be readable.r�invalid buffer sizeN)	rnr-r�r�r"�buffer_size�_reset_read_buf�Lock�
_read_lock�rHr<r�r@r@rAr�szBufferedReader.__init__cCs
|j��SrP)r<rnr_r@r@rArnszBufferedReader.readablecCsd|_d|_dS)Nr�r)�	_read_buf�	_read_posr_r@r@rAr� szBufferedReader._reset_read_bufNcCsL|dur|dkrtd��|j�|�|�Wd�S1s>0YdS)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.
        Nr
zinvalid number of bytes to read)r"r��_read_unlockedr{r@r@rAr�$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�Nr
r�r)
r�r�r�r�r<r�r�r!r��joinr�r�ry)rHrzZ
nodata_valZempty_valuesr�r]�chunkZchunksZcurrent_size�availZwanted�outr@r@rAr�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{r@r@rArveszBufferedReader.peekcCsrt||j�}t|j�|j}||ks,|dkrb|j|}|j�|�}|rb|j|jd�||_d|_|j|jd�Sr�)ryr�r!r�r�r<r�)rHrzZwantZhaveZto_readZcurrentr@r@rAr�os
zBufferedReader._peek_unlockedr
cCsj|dkr|j}|dkrdS|j�6|�d�|�t|t|j�|j��Wd�S1s\0YdS)z<Reads up to size bytes, with at most one read() system call.rr�r	N)r�r�r�r�ryr!r�r�r{r@r@rAr�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)z2Read data into *buf* with at most one system call.rr�Nr	)
rr�r�r�r�r!ryr�r�r�r<r�r�)rHr�r��writtenr�rzr@r@rAr��s6


�

$zBufferedReader._readintocCst�|�t|j�|jSrP)r�r`r!r�r�r_r@r@rAr`�szBufferedReader.tellcCsp|tvrtd��|j�F|dkr4|t|j�|j8}t�|||�}|��|Wd�S1sb0YdS)N�invalid whence valuer	)	�valid_seek_flagsr"r�r!r�r�r�rZr�r\r@r@rArZ�szBufferedReader.seek)N)N)r)r)r
)r)rLrMrNrGr)r�rnr�r�r�rvr�r�r�r`rZr@r@r@rAr1s	


4



.r1c@s`eZdZdZefdd�Zdd�Zdd�Zdd	d
�Zdd�Z	d
d�Z
dd�Zddd�Zdd�Z
dS)r0z�A buffer for a writeable sequential RawIO object.

    The constructor creates a BufferedWriter for the given writeable raw
    stream. If the buffer_size is not given, it defaults to
    DEFAULT_BUFFER_SIZE.
    cCsF|��std��t�||�|dkr,td��||_t�|_t�|_	dS)Nz "raw" argument must be writable.rr�)
rpr-r�r�r"r�r��
_write_bufr��_write_lockr�r@r@rAr��szBufferedWriter.__init__cCs
|j��SrP)r<rpr_r@r@rArp�szBufferedWriter.writablecCst|t�rtd��|j��|jr(td��t|j�|jkr@|�	�t|j�}|j�
|�t|j�|}t|j�|jkr�z|�	�Wnnty�}zVt|j�|jkr�t|j�|j}||8}|jd|j�|_t|j|j
|��WYd}~n
d}~00|Wd�S1�s
0YdS)Nr�r�)rrrr�rgr"r!r�r��_flush_unlocked�extend�BlockingIOError�errno�strerror)rHrZbeforer��eZoverager@r@rAr��s(

&zBufferedWriter.writeNcCsP|j�6|��|dur"|j��}|j�|�Wd�S1sB0YdSrP)r�r�r<r`rarbr@r@rAra�s

zBufferedWriter.truncatecCs2|j�|��Wd�n1s$0YdSrP)r�r�r_r@r@rAreszBufferedWriter.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)rgr"r�r<r�r��RuntimeErrorr�ZEAGAINr!r-�rHrzr@r@rAr�s�zBufferedWriter._flush_unlockedcCst�|�t|j�SrP)r�r`r!r�r_r@r@rAr`szBufferedWriter.tellrcCsP|tvrtd��|j�&|��t�|||�Wd�S1sB0YdS)Nr�)r�r"r�r�r�rZr\r@r@rArZs
zBufferedWriter.seekcCs�|j�0|jdus|jr(Wd�dSWd�n1s<0Yz<|��W|j�|j��Wd�q�1sx0Yn2|j�|j��Wd�n1s�0Y0dSrP)r�r<rgrer4r_r@r@rAr4 s.
*�zBufferedWriter.close)N)r)rLrMrNrGr)r�rpr�rarer�r`rZr4r@r@r@rAr0�s

r0c@s�eZdZdZefdd�Zddd�Zdd�Zd	d
�Zd dd
�Z	d!dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zedd��ZdS)"�BufferedRWPaira�A buffered reader and writer object together.

    A buffered reader object and buffered writer object put together to
    form a sequential IO object that can read and write. This is typically
    used with a socket or two-way pipe.

    reader and writer are RawIOBase objects that are readable and
    writeable respectively. If the buffer_size is omitted it defaults to
    DEFAULT_BUFFER_SIZE.
    cCs<|��std��|��s td��t||�|_t||�|_dS)zEConstructor.

        The arguments are two RawIO instances.
        z#"reader" argument must be readable.z#"writer" argument must be writable.N)rnr-rpr1�readerr0�writer)rHr�r�r�r@r@rAr�@szBufferedRWPair.__init__r
cCs|durd}|j�|�S�Nr
)r�r�r{r@r@rAr�NszBufferedRWPair.readcCs|j�|�SrP)r�r�r�r@r@rAr�SszBufferedRWPair.readintocCs|j�|�SrP)r�r�r�r@r@rAr�VszBufferedRWPair.writercCs|j�|�SrP)r�rvr{r@r@rArvYszBufferedRWPair.peekcCs|j�|�SrP)r�r�r{r@r@rAr�\szBufferedRWPair.read1cCs|j�|�SrP)r�r�r�r@r@rAr�_szBufferedRWPair.readinto1cCs
|j��SrP)r�rnr_r@r@rArnbszBufferedRWPair.readablecCs
|j��SrP)r�rpr_r@r@rArpeszBufferedRWPair.writablecCs
|j��SrP)r�rer_r@r@rArehszBufferedRWPair.flushcCs*z|j��W|j��n|j��0dSrP)r�r4r�r_r@r@rAr4kszBufferedRWPair.closecCs|j��p|j��SrP)r�r(r�r_r@r@rAr(qszBufferedRWPair.isattycCs|jjSrP)r�rgr_r@r@rArgtszBufferedRWPair.closedN)r
)r)r
)rLrMrNrGr)r�r�r�r�rvr�r�rnrprer4r(r�rgr@r@r@rAr�0s


r�c@sneZdZdZefdd�Zddd�Zdd�Zdd
d�Zddd
�Z	dd�Z
ddd�Zddd�Zdd�Z
dd�Zd	S)r/z�A buffered interface to random access streams.

    The constructor creates a reader and writer for a seekable stream,
    raw, given in the first argument. If the buffer_size is omitted it
    defaults to DEFAULT_BUFFER_SIZE.
    cCs(|��t�|||�t�|||�dSrP)rmr1r�r0r�r@r@rAr��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"rer�r�r<rZr�r!r�r-r\r@r@rArZ�s8&zBufferedRandom.seekcCs|jrt�|�St�|�SdSrP)r�r0r`r1r_r@r@rAr`�s
zBufferedRandom.tellNcCs|dur|��}t�||�SrP)r`r0rarbr@r@rAra�szBufferedRandom.truncatecCs |durd}|��t�||�Sr�)rer1r�r{r@r@rAr��szBufferedRandom.readcCs|��t�||�SrP)rer1r�r�r@r@rAr��szBufferedRandom.readintocCs|��t�||�SrP)rer1rvr{r@r@rArv�szBufferedRandom.peekr
cCs|��t�||�SrP)rer1r�r{r@r@rAr��szBufferedRandom.read1cCs|��t�||�SrP)rer1r�r�r@r@rAr��szBufferedRandom.readinto1cCsZ|jrN|j�2|j�|jt|j�d�|��Wd�n1sD0Yt�||�Sr~)	r�r�r<rZr�r!r�r0r�r�r@r@rAr��s
&zBufferedRandom.write)r)N)N)r)r
)rLrMrNrGr)r�rZr`rar�r�rvr�r�r�r@r@r@rAr/ys




r/cs�eZdZdZdZdZdZdZdZdZ	d0dd�Z
dd	�Zd
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'r
FNTr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��tdd�|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)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).
        rr
z$integer argument expected, got floatznegative file descriptorzinvalid mode: %szxrwab+css|]}|dvVqdS)ZrwaxNr@)�.0�cr@r@rA�	<genexpr>�r�z"FileIO.__init__.<locals>.<genexpr>r	rzKMust have exactly one of create/read/write/append mode and at most one plusrTrrr�O_BINARYZO_NOINHERIT�	O_CLOEXECNz'Cannot use closefd=False with file namei�zexpected integer from openerzNegative file descriptorFr,)-�_fd�_closefdrr4r�floatrrr"rr �sum�count�_created�	_writable�O_EXCL�O_CREAT�	_readable�O_TRUNC�
_appending�O_APPEND�O_RDWR�O_RDONLY�O_WRONLY�getattrrBr-�set_inheritabler*�stat�S_ISDIR�st_mode�IsADirectoryErrorr�ZEISDIRr�r.�_blksizer)�_setmoder�rX�lseekrZESPIPE)rHr5r3r:r�fd�flagsZnoinherit_flagZowned_fdZfdfstatr�r@r@rAr��s�




$




�




�

zFileIO.__init__cCsB|jdkr>|jr>|js>ddl}|jd|ftd|d�|��dS)Nrzunclosed file %rr
)�
stacklevel�source)r�r�rgr#r$�ResourceWarningr4)rHr#r@r@rAriEs�zFileIO.__del__cCstd|jj�d���dSr�r�r_r@r@rAr�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>)	rWrMrNrgrXr.r�r3r�)rH�
class_namerXr@r@rAr�Os�
�
�zFileIO.__repr__cCs|jstd��dS)NzFile not open for reading)r�rUr_r@r@rAro]szFileIO._checkReadablecCs|jstd��dS)NzFile not open for writing)r�rUrkr@r@rArqaszFileIO._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)rdror�rr�r�r�r{r@r@rAr�eszFileIO.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)rdror)rrr�rr*�st_sizer-r�r!r�r�r�r)rH�bufsizer]�endr=rzr�r@r@rAr�us2
zFileIO.readallcCs4t|��d�}|�t|��}t|�}||d|�<|S)zSame as RawIOBase.readinto().r�N)r�r�r�r!)rHr�mr�rzr@r@rAr��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)rdrqrr�r�r�r�r@r@rAr��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�rrdrrr�r\r@r@rArZ�s
zFileIO.seekcCs|��t�|jdt�S)zYtell() -> int.  Current file position.

        Can raise OSError for non seekable files.r)rdrrr�rr_r@r@rAr`�szFileIO.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)rdrqr`r�	ftruncater�r{r@r@rAra�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)rgr�rr4r�r�r_r�r@rAr4�s
zFileIO.closecCsD|��|jdur>z|��Wnty6d|_Yn0d|_|jS)z$True if file supports random-access.NFT)rd�	_seekabler`r-r_r@r@rArj�s
zFileIO.seekablecCs|��|jS)z'True if file was opened in a read mode.)rdr�r_r@r@rArn�szFileIO.readablecCs|��|jS)z(True if file was opened in a write mode.)rdr�r_r@r@rArp�szFileIO.writablecCs|��|jS)z3Return the underlying file descriptor (an integer).)rdr�r_r@r@rAr+�sz
FileIO.filenocCs|��t�|j�S)z.True if the file is connected to a TTY device.)rdrr(r�r_r@r@rAr(�sz
FileIO.isattycCs|jS)z6True if the file descriptor will be closed by close().)r�r_r@r@rAr:�szFileIO.closefdcCsJ|jr|jrdSdSn0|jr,|jr&dSdSn|jrB|jr<dSdSndSdS)	zString giving the file modezxb+Zxbzab+Zabzrb+rC�wbN)r�r�r�r�r_r@r@rAr3szFileIO.mode)rTN)N)N)N)"rLrMrNr�r�r�r�r�rr�r�rir�r�rorqr�r�r�r�rrZr`rar4rjrnrpr+r(r�r:r3r�r@r@r�rAr'�s<
y

#



r'c@s`eZdZdZddd�Zdd�Zddd	�Zd
d�Zdd
�Ze	dd��Z
e	dd��Ze	dd��ZdS)�
TextIOBaseznBase class for text I/O.

    This class provides a character and line based interface to stream
    I/O.
    r
cCs|�d�dS)z�Read at most size characters from stream, where size is an int.

        Read from underlying buffer until we have size characters or we hit EOF.
        If size is negative or omitted, read until EOF.

        Returns a string.
        r�Nr[r{r@r@rAr�"szTextIOBase.readcCs|�d�dS)z.Write string s to stream and returning an int.r�Nr[)rH�sr@r@rAr�,szTextIOBase.writeNcCs|�d�dS)z*Truncate size to pos, where pos is an int.raNr[rbr@r@rAra0szTextIOBase.truncatecCs|�d�dS)z_Read until newline or EOF.

        Returns an empty string if EOF is hit immediately.
        r�Nr[r_r@r@rAr�4szTextIOBase.readlinecCs|�d�dS)z�
        Separate the underlying buffer from the TextIOBase and return it.

        After the underlying buffer has been detached, the TextIO is in an
        unusable state.
        r�Nr[r_r@r@rAr�;szTextIOBase.detachcCsdS)zSubclasses should override.Nr@r_r@r@rAr7DszTextIOBase.encodingcCsdS)z�Line endings translated so far.

        Only line endings translated during reading are considered.

        Subclasses should override.
        Nr@r_r@r@rA�newlinesIszTextIOBase.newlinescCsdS)zMError setting of the decoder or encoder.

        Subclasses should override.Nr@r_r@r@rAr8SszTextIOBase.errors)r
)N)
rLrMrNrGr�r�rar�r�r�r7rr8r@r@r@rArs


	

	rc@sTeZdZdZddd�Zddd�Zdd	�Zd
d�Zdd
�ZdZ	dZ
dZedd��Z
dS)�IncrementalNewlineDecodera+Codec used when reading a file in universal newlines mode.  It wraps
    another incremental decoder, translating \r\n and \r into \n.  It also
    records the types of newlines encountered.  When used with
    translate=False, it ensures that the newline sequence is returned in
    one piece.
    �strictcCs,tjj||d�||_||_d|_d|_dS)N)r8rF)�codecs�IncrementalDecoderr��	translate�decoder�seennl�	pendingcr)rHrrr8r@r@rAr�ds
z"IncrementalNewlineDecoder.__init__FcCs�|jdur|}n|jj||d�}|jr<|s.|r<d|}d|_|�d�r\|s\|dd�}d|_|�d�}|�d�|}|�d�|}|j|o�|j|o�|jB|o�|jBO_|j	r�|r�|�
dd�}|r�|�
dd�}|S)N��final�
Fr
T�
�
)r�decoderr�r�r�_LF�_CR�_CRLFr�replace)rH�inputr�outputZcrlfZcrZlfr@r@rAr#ks*

�z IncrementalNewlineDecoder.decodecCs@|jdurd}d}n|j��\}}|dK}|jr8|dO}||fS)Nr�rr	)r�getstater)rHr��flagr@r@rAr*�s
z"IncrementalNewlineDecoder.getstatecCs8|\}}t|d@�|_|jdur4|j�||d?f�dSr~)�boolrr�setstate)rH�stater�r+r@r@rAr-�s
z"IncrementalNewlineDecoder.setstatecCs$d|_d|_|jdur |j��dS)NrF)rrr�resetr_r@r@rAr/�s
zIncrementalNewlineDecoder.resetr	r
�cCs
d|jS)N)Nr"r )r r"r!)r"r!)r r!)r r"r!)rr_r@r@rAr�s�z"IncrementalNewlineDecoder.newlinesN)r)F)rLrMrNrGr�r#r*r-r/r$r%r&r�rr@r@r@rAr]s

rc@sveZdZdZdZdZdOdd�Zdd�ZdPd	d
�Zdd�Z	e
d
d��Ze
dd��Ze
dd��Z
e
dd��Ze
dd��Zddeddd�dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Ze
d$d%��Ze
d&d'��Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�ZdQd4d5�Zd6d7�Z d8d9�Z!dRd;d<�Z"d=d>�Z#d?d@�Z$dSdAdB�Z%dCdD�Z&dTdEdF�Z'dUdGdH�Z(dIdJ�Z)dVdKdL�Z*e
dMdN��Z+dS)Wr2aCharacter 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�td|��t�
|�js�d}t||��|dur�d}n$t	|t
�s�td|��tr�t�|�||_d|_d|_d|_|j��|_|_t|jd	�|_|�|||||�dS)
Nr�asciiFrzG%r is not a text encoding; use codecs.open() to handle arbitrary codecsrrrr�)�_check_newliner�device_encodingr+r.rU�locale�ImportErrorZgetpreferredencodingrrr"r�lookup�_is_text_encoding�LookupError�
_CHECK_ERRORS�lookup_errorr��_decoded_chars�_decoded_chars_used�	_snapshotr?rjr�_tellingr��
_has_read1�
_configure)	rHr?r7r8r9r>�
write_throughr4rlr@r@rAr��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")rHr9r@r@rAr2�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_throughrrpr?r`�_get_encoderr-r8)rHr7r8r9r>rA�positionr@r@rAr@s&


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�rWrMrNrXr.r3r7)rHr=rXr3r@r@rAr�'s
�

zTextIOWrapper.__repr__cCs|jSrP)rDr_r@r@rAr78szTextIOWrapper.encodingcCs|jSrP)rEr_r@r@rAr8<szTextIOWrapper.errorscCs|jSrP)rOr_r@r@rAr>@szTextIOWrapper.line_bufferingcCs|jSrP)rPr_r@r@rArADszTextIOWrapper.write_throughcCs|jSrP)r�r_r@r@rAr?HszTextIOWrapper.buffer)r7r8r9r>rAcCs�|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 readrrr)rG�EllipsisrUrErrrrDrKr2r>rArer@)rHr7r8r9r>rAr@r@rA�reconfigureLs>
����



�zTextIOWrapper.reconfigurecCs|jrtd��|jS)Nrr)rgr"rr_r@r@rArjuszTextIOWrapper.seekablecCs
|j��SrP)r?rnr_r@r@rArnzszTextIOWrapper.readablecCs
|j��SrP)r?rpr_r@r@rArp}szTextIOWrapper.writablecCs|j��|j|_dSrP)r?rerr>r_r@r@rAre�s
zTextIOWrapper.flushcCs8|jdur4|js4z|��W|j��n|j��0dSrP)r?rgrer4r_r@r@rAr4�s
zTextIOWrapper.closecCs|jjSrP)r?rgr_r@r@rArg�szTextIOWrapper.closedcCs|jjSrP)r?rXr_r@r@rArX�szTextIOWrapper.namecCs
|j��SrP)r?r+r_r@r@rAr+�szTextIOWrapper.filenocCs
|j��SrP)r?r(r_r@r@rAr(�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)rgr"rrrrWrLr!rLrOrNr'rFrQ�encoder?r�re�_set_decoded_charsr=rGr/)rHrZlengthZhaslf�encoderrr@r@rAr��s(
�


zTextIOWrapper.writecCst�|j�}||j�|_|jSrP)r�getincrementalencoderrDrErF)rHZmake_encoderr@r@rArQ�szTextIOWrapper._get_encodercCs2t�|j�}||j�}|jr(t||j�}||_|SrP)r�getincrementaldecoderrDrErIrrJrG)rHZmake_decoderrr@r@rA�_get_decoder�s
zTextIOWrapper._get_decodercCs||_d|_dS)zSet the _decoded_chars buffer.rN)r;r<)rH�charsr@r@rArV�sz TextIOWrapper._set_decoded_charscCsF|j}|dur|j|d�}n|j|||�}|jt|�7_|S)z'Advance into the _decoded_chars buffer.N)r<r;r!)rHrz�offsetr[r@r@rA�_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)r<�AssertionErrorr�r@r@rA�_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 decoderrC)rGr"r>r*r?r?r��_CHUNK_SIZEr�r#rVr!r;rHr=)rH�
dec_buffer�	dec_flags�input_chunk�eofZ
decoded_charsr@r@rA�_read_chunk�s 

zTextIOWrapper._read_chunkrcCs(||d>B|d>B|d>Bt|�d>BS)N�@���)r,)rHrRrb�
bytes_to_feed�need_eof�
chars_to_skipr@r@rA�_pack_cookie�s
�
�zTextIOWrapper._pack_cookiecCsJt|d�\}}t|d�\}}t|d�\}}t|d�\}}|||t|�|fS)Nl)�divmodr,)rHZbigint�restrRrbrjrkrlr@r@rA�_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
FTrz'can't reconstruct logical file position)rrUr>r-rer?r`rGr=r;r^r!r<rmr*rrHr-r#�range)rHrRrrbZ
next_inputrlZsaved_stateZ
skip_bytesZ	skip_backrzr�d�	start_posZstart_flagsZ	bytes_fedrkZ
chars_decoded�irar@r@rAr`	s�





 
�



�
�zTextIOWrapper.tellcCs$|��|dur|��}|j�|�SrP)rer`r?rarbr@r@rAras	szTextIOWrapper.truncatecCs*|jdurtd��|��|j}d|_|S)Nzbuffer is already detached)r?r"rer�)rHr?r@r@rAr�y	s
zTextIOWrapper.detachcs��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�|df�_|	�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)rFrQr8r-r/)rRrWr_r@rA�_reset_encoder�	sz*TextIOWrapper.seek.<locals>._reset_encoderr�rqrz#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)rgr"rrUrr`rrer?rZrVr=rGr/rprZr-r�r#r!r;r-r<)rHZcookier^rvrRrtrbrjrkrlrcr@r_rArZ�	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)Nr
rrTrrF)ror�r.rrGrZr]r#r?r�rVr=r!re)rHr|r�rr=rdr@r@rAr��	s,
�


zTextIOWrapper.readcCs(d|_|��}|s$d|_|j|_t�|S)NF)r>r�r=rr�r�r@r@rAr��	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�r
rrr"r	r r
r)rgr"r�r.rr]rGrZrJrxr!rIrKrer;rVr=r_)	rHr|r�r��startr]�endposZnlposZcrposr@r@rAr��	st







zTextIOWrapper.readlinecCs|jr|jjSdSrP)rGrr_r@r@rArN
szTextIOWrapper.newlines)NNNFF)NNNFF)N)rrFr)N)r)N)N),rLrMrNrGr`r�r�r2r@r�r�r7r8r>rAr?rSrTrjrnrprer4rgrXr+r(r�rQrZrVr]r_rermrpr`rar�rZr�r�r�rr@r@r@rAr2�sn�
*�
$




�)



*�

c

K
	
]r2csReZdZdZd�fdd�	Zdd�Zdd	�Zed
d��Zedd
��Z	dd�Z
�ZS)�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)r7r8r9Fz*initial_value must be str or None, not {0}r)
r�ryr�r�rLrrrr�rBrLr�rZ)rHZ
initial_valuer9r�r@rAr�Z
s�
�
zStringIO.__init__c	CsX|��|jp|��}|��}|��z |j|j��dd�W|�|�S|�|�0dS)NTr)	rerGrZr*r/r#r?r�r-)rHrZ	old_stater@r@rAr�j
s
�zStringIO.getvaluecCs
t�|�SrP)�objectr�r_r@r@rAr�t
szStringIO.__repr__cCsdSrPr@r_r@r@rAr8y
szStringIO.errorscCsdSrPr@r_r@r@rAr7}
szStringIO.encodingcCs|�d�dS)Nr�r[r_r@r@rAr��
szStringIO.detach)rr")rLrMrNrGr�r�r�r�r8r7r�r�r@r@r�rAryS
s


ry)rr
NNNTN)9rGr�abcrr�r��sys�_threadrr��platformZmsvcrtrr�iorrrrr�r��addr�	SEEK_DATAr)r�r�dev_moderhr9rBrE�	open_coder.rFrOrUr-r"�ABCMetarV�registerr��_ior'r�r�r�r1r0r�r/rrrr2ryr@r@r@rA�<module>s�

�
[

	
#=
gkCiIJY@U&