AlkantarClanX12

Your IP : 3.14.246.52


Current Path : /lib64/python3.6/__pycache__/
Upload File :
Current File : //lib64/python3.6/__pycache__/_pyio.cpython-36.pyc

3


 \!X�@sbdZddlZddlZddlZddlZddlZddlZyddlmZ	Wn e
k
rdddlmZ	YnXejd5kr~ddl
mZndZddlZddlmZmZmZmZddd	hZeed
�r�ejej�ejej�d6ZeZd8dd�ZGdd�d�ZGdd�d�Zy
ejZWn(e k
�r.Gdd�de!e"�ZYnXGdd�dej#d�Z$ej$j%e$�Gdd�de$�Z&ej&j%e&�ddl'm(Z(e&j%e(�Gdd�de$�Z)ej)j%e)�Gdd �d e)�Z*Gd!d"�d"e)�Z+Gd#d$�d$e*�Z,Gd%d&�d&e*�Z-Gd'd(�d(e)�Z.Gd)d*�d*e-e,�Z/Gd+d,�d,e&�Z(Gd-d.�d.e$�Z0ej0j%e0�Gd/d0�d0ej1�Z2Gd1d2�d2e0�Z3Gd3d4�d4e3�Z4dS)9z)
Python implementation of the io module.
�N)�
allocate_lock�win32�cygwin)�setmode)�__all__�SEEK_SET�SEEK_CUR�SEEK_END���	SEEK_HOLE�i�rTcCs~t|t�stj|�}t|tttf�s0td|��t|t�sFtd|��t|t�s\td|��|dk	r|t|t�r|td|��|dk	r�t|t�r�td|��t|�}|td�s�t|�t|�kr�t	d|��d|k}	d	|k}
d
|k}d|k}d|k}
d
|k}d|k}d|k�rH|	�s&|�s&|�s&|
�r.t	d��ddl
}|jdtd�d}
|�r\|�r\t	d��|	|
||dk�rzt	d��|	�p�|
�p�|�p�|�s�t	d��|�r�|dk	�r�t	d��|�r�|dk	�r�t	d��|�r�|dk	�r�t	d��t
||	�r�d�p�d|
�rd	�pd|�rd
�pd|�r d�p"d|
�r0d�p2d||d�}|}�yd}|dk�sh|dk�rp|j��rpd"}d}|dk�r�t}ytj|j��j}Wnttfk
�r�YnX|dk�r�|}|dk�r�t	d��|dk�r�|�r�|St	d ��|
�r�t||�}n<|	�s|�s|�rt||�}n|
�r,t||�}nt	d!|��|}|�rF|St|||||�}|}||_|S|j��YnXdS)#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: %rNzinvalid encoding: %rzinvalid errors: %rzaxrwb+tU�xr�w�a�+�t�b�Uz4mode U cannot be combined with 'x', 'w', 'a', or '+'rz'U' mode is deprecatedrTz'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�)�openerFzinvalid buffering sizezcan't have unbuffered text I/Ozunknown 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)�filer2�	buffering�encoding�errors�newline�closefdrZmodesZcreatingZreadingZwritingZ	appendingZupdating�textZbinaryr#�raw�result�line_bufferingZbs�buffer�r?�/usr/lib64/python3.6/_pyio.py�open(s�{




>




rAc@seZdZdZdd�ZdS)�
DocDescriptorz%Helper for builtins.open.__doc__
    cCs
dtjS)Nz\open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True)

)rA�__doc__)�self�obj�typr?r?r@�__get__�szDocDescriptor.__get__N)�__name__�
__module__�__qualname__rCrGr?r?r?r@rB�srBc@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.
    cOs
t||�S)N)rA)�cls�args�kwargsr?r?r@�__new__szOpenWrapper.__new__N)rHrIrJrCrBrOr?r?r?r@rKsrKc@seZdZdS)�UnsupportedOperationN)rHrIrJr?r?r?r@rPsrPc@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)?�IOBaseagThe abstract base class for all I/O classes, acting on streams of
    bytes. There is no public constructor.

    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, readinto, 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. In
    some cases (such as readinto), a writable object is required. 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)rP�	__class__rH)rD�namer?r?r@�_unsupported@szIOBase._unsupportedrcCs|jd�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)rT)rD�pos�whencer?r?r@rUGszIOBase.seekcCs|jdd�S)z5Return an int indicating the current stream position.rr
)rU)rDr?r?r@�tellWszIOBase.tellNcCs|jd�dS)z�Truncate file to size bytes.

        Size defaults to the current IO position as reported by tell().  Return
        the new size.
        �truncateN)rT)rDrVr?r?r@rY[szIOBase.truncatecCs|j�dS)zuFlush write buffers, if applicable.

        This is not implemented for read-only and non-blocking streams.
        N)�_checkClosed)rDr?r?r@�flusheszIOBase.flushFcCs |jsz|j�Wdd|_XdS)ziFlush and close the IO object.

        This method has no effect if the file is already closed.
        NT)�_IOBase__closedr[)rDr?r?r@r3oszIOBase.closec	Csy|j�WnYnXdS)zDestructor.  Calls close().N)r3)rDr?r?r@�__del__zs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?)rDr?r?r@�seekable�szIOBase.seekablecCs |j�st|dkrdn|��dS)zEInternal: raise UnsupportedOperation if file is not seekable
        NzFile or stream is not seekable.)r^rP)rD�msgr?r?r@�_checkSeekable�szIOBase._checkSeekablecCsdS)zvReturn a bool indicating whether object was opened for reading.

        If False, read() will raise OSError.
        Fr?)rDr?r?r@�readable�szIOBase.readablecCs |j�st|dkrdn|��dS)zEInternal: raise UnsupportedOperation if file is not readable
        NzFile or stream is not readable.)rarP)rDr_r?r?r@�_checkReadable�szIOBase._checkReadablecCsdS)z�Return a bool indicating whether object was opened for writing.

        If False, write() and truncate() will raise OSError.
        Fr?)rDr?r?r@�writable�szIOBase.writablecCs |j�st|dkrdn|��dS)zEInternal: raise UnsupportedOperation if file is not writable
        NzFile or stream is not writable.)rcrP)rDr_r?r?r@�_checkWritable�szIOBase._checkWritablecCs|jS)z�closed: bool.  True iff the file has been closed.

        For backwards compatibility, this is a property, not a predicate.
        )r\)rDr?r?r@�closed�sz
IOBase.closedcCs|jrt|dkrdn|��dS)z7Internal: raise a ValueError if file is closed
        NzI/O operation on closed file.)rer")rDr_r?r?r@rZ�szIOBase._checkClosedcCs|j�|S)zCContext management protocol.  Returns self (an instance of IOBase).)rZ)rDr?r?r@�	__enter__�szIOBase.__enter__cGs|j�dS)z+Context management protocol.  Calls close()N)r3)rDrMr?r?r@�__exit__�szIOBase.__exit__cCs|jd�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*N)rT)rDr?r?r@r*�sz
IOBase.filenocCs|j�dS)z{Return a bool indicating whether this is an 'interactive' stream.

        Return False if it can't be determined.
        F)rZ)rDr?r?r@r'�sz
IOBase.isattyr
cs�t�d�r��fdd�}ndd�}�dkr0d
�nt�t�sBtd��t�}x>�dks^t|��kr��j|��}|spP||7}|jd	�rJPqJWt|�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>�jd�}|sdS|jd�dp&t|�}�dkr:t|��}|S)Nr
�
r)rh�findr!�min)Z	readahead�n)rD�sizer?r@�
nreadahead�s

z#IOBase.readline.<locals>.nreadaheadcSsdS)Nr
r?r?r?r?r@rn�sNr
zsize must be an integerrrir)	�hasattrrrr�	bytearrayr!�read�endswithr)rDrmrn�resrr?)rDrmr@�readline�s 
	

zIOBase.readlinecCs|j�|S)N)rZ)rDr?r?r@�__iter__szIOBase.__iter__cCs|j�}|st�|S)N)rt�
StopIteration)rD�liner?r?r@�__next__szIOBase.__next__cCsR|dks|dkrt|�Sd}g}x,|D]$}|j|�|t|�7}||kr&Pq&W|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!)rDZhintrl�linesrwr?r?r@�	readliness

zIOBase.readlinescCs$|j�x|D]}|j|�qWdS)N)rZ�write)rDr{rwr?r?r@�
writelines#s
zIOBase.writelines)r)N)N)N)N)Nr)r)N)rHrIrJrCrTrUrXrYr[r\r3r]r^r`rarbrcrd�propertyrerZrfrgr*r'rtrurxr|r~r?r?r?r@rQs4 






	

%
rQ)�	metaclassc@s2eZdZdZd
dd�Zdd�Zdd�Zd	d
�ZdS)�	RawIOBasezBase class for raw binary I/O.r
cCsP|dkrd}|dkr|j�St|j��}|j|�}|dkr>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
rr)�readallrp�	__index__�readintor)rDrmrrlr?r?r@rq9s

zRawIOBase.readcCs8t�}x|jt�}|sP||7}qW|r0t|�S|SdS)z+Read until EOF, using multiple read() call.N)rprqr(r)rDrs�datar?r?r@r�Js
zRawIOBase.readallcCs|jd�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�N)rT)rDrr?r?r@r�XszRawIOBase.readintocCs|jd�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}N)rT)rDrr?r?r@r}`szRawIOBase.writeNr)r)rHrIrJrCrqr�r�r}r?r?r?r@r�+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.
    NcCs|jd�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.
        rqN)rT)rDrmr?r?r@rq~szBufferedIOBase.readcCs|jd�dS)zaRead up to size bytes with at most one read() system call,
        where size is an int.
        �read1N)rT)rDrmr?r?r@r��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�)�	_readinto)rDrr?r?r@r��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.
        T)r�)r�)rDrr?r?r@�	readinto1�s	zBufferedIOBase.readinto1cCsVt|t�st|�}|jd�}|r0|jt|��}n|jt|��}t|�}||d|�<|S)N�B)r�
memoryview�castr�r!rq)rDrr�r�rlr?r?r@r��s

zBufferedIOBase._readintocCs|jd�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}N)rT)rDrr?r?r@r}�s	zBufferedIOBase.writecCs|jd�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.
        �detachN)rT)rDr?r?r@r��szBufferedIOBase.detach)N)N)rHrIrJrCrqr�r�r�r�r}r�r?r?r?r@r�ms

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
||_dS)N)�_raw)rDr;r?r?r@�__init__�sz_BufferedIOMixin.__init__rcCs"|jj||�}|dkrtd��|S)Nrz#seek() returned an invalid position)r;rUr,)rDrVrWZnew_positionr?r?r@rU�sz_BufferedIOMixin.seekcCs|jj�}|dkrtd��|S)Nrz#tell() returned an invalid position)r;rXr,)rDrVr?r?r@rX�s
z_BufferedIOMixin.tellNcCs$|j�|dkr|j�}|jj|�S)N)r[rXr;rY)rDrVr?r?r@rY�sz_BufferedIOMixin.truncatecCs|jrtd��|jj�dS)Nzflush of closed file)rer"r;r[)rDr?r?r@r[�sz_BufferedIOMixin.flushc
Cs0|jdk	r,|jr,z|j�Wd|jj�XdS)N)r;rer[r3)rDr?r?r@r3sz_BufferedIOMixin.closecCs*|jdkrtd��|j�|j}d|_|S)Nzraw stream already detached)r;r"r[r�)rDr;r?r?r@r�s
z_BufferedIOMixin.detachcCs
|jj�S)N)r;r^)rDr?r?r@r^sz_BufferedIOMixin.seekablecCs|jS)N)r�)rDr?r?r@r;sz_BufferedIOMixin.rawcCs|jjS)N)r;re)rDr?r?r@resz_BufferedIOMixin.closedcCs|jjS)N)r;rS)rDr?r?r@rS!sz_BufferedIOMixin.namecCs|jjS)N)r;r2)rDr?r?r@r2%sz_BufferedIOMixin.modecCstdj|jj���dS)Nz can not serialize a '{0}' object)r�formatrRrH)rDr?r?r@�__getstate__)sz_BufferedIOMixin.__getstate__cCsJ|jj}|jj}y
|j}Wntk
r6dj||�SXdj|||�SdS)Nz<{}.{}>z<{}.{} name={!r}>)rRrIrJrS�	Exceptionr�)rD�modnameZclsnamerSr?r?r@�__repr__-s
z_BufferedIOMixin.__repr__cCs
|jj�S)N)r;r*)rDr?r?r@r*9sz_BufferedIOMixin.filenocCs
|jj�S)N)r;r')rDr?r?r@r'<sz_BufferedIOMixin.isatty)r)N)rHrIrJrCr�rUrXrYr[r3r�r^rr;rerSr2r�r�r*r'r?r?r?r@r��s"


r�cs�eZdZdZd dd�Zdd�Zdd�Zd	d
�Z�fdd�Zd!d
d�Z	dd�Z
dd�Zd"dd�Zdd�Z
d#dd�Zdd�Zdd�Zdd�Z�ZS)$�BytesIOz<Buffered I/O implementation using an in-memory bytes buffer.NcCs&t�}|dk	r||7}||_d|_dS)Nr)rp�_buffer�_pos)rDZ
initial_bytes�bufr?r?r@r�Ds
zBytesIO.__init__cCs|jrtd��|jj�S)Nz__getstate__ on closed file)rer"�__dict__�copy)rDr?r?r@r�KszBytesIO.__getstate__cCs|jrtd��t|j�S)z8Return the bytes value (contents) of the buffer
        zgetvalue on closed file)rer"rr�)rDr?r?r@�getvaluePszBytesIO.getvaluecCs|jrtd��t|j�S)z;Return a readable and writable view of the buffer.
        zgetbuffer on closed file)rer"r�r�)rDr?r?r@�	getbufferWszBytesIO.getbuffercs|jj�t�j�dS)N)r��clear�superr3)rD)rRr?r@r3^s
z
BytesIO.closecCst|jrtd��|dkrd}|dkr,t|j�}t|j�|jkr@dStt|j�|j|�}|j|j|�}||_t|�S)Nzread from closed filer
r�r)rer"r!r�r�rkr)rDrmZnewposrr?r?r@rqbs
zBytesIO.readcCs
|j|�S)z"This is the same as read.
        )rq)rDrmr?r?r@r�psz
BytesIO.read1cCs�|jrtd��t|t�r td��t|��}|j}WdQRX|dkrFdS|j}|t|j	�krzd|t|j	�}|j	|7_	||j	|||�<|j|7_|S)Nzwrite to closed filez can't write str to binary streamr�)
rer"rrrr��nbytesr�r!r�)rDrZviewrlrVZpaddingr?r?r@r}us

z
BytesIO.writercCs�|jrtd��y
|jWn,tk
rD}ztd�|�WYdd}~XnX|dkrl|dkrdtd|f��||_nD|dkr�td|j|�|_n(|dkr�tdt|j�|�|_ntd��|jS)Nzseek on closed filezan integer is requiredrznegative seek position %rr
rzunsupported whence value)	rer"r�r-rr��maxr!r�)rDrVrW�errr?r?r@rU�s 
zBytesIO.seekcCs|jrtd��|jS)Nztell on closed file)rer"r�)rDr?r?r@rX�szBytesIO.tellcCs||jrtd��|dkr|j}nNy
|jWn,tk
rT}ztd�|�WYdd}~XnX|dkrltd|f��|j|d�=|S)Nztruncate on closed filezan integer is requiredrznegative truncate position %r)rer"r�r�r-rr�)rDrVr�r?r?r@rY�s
zBytesIO.truncatecCs|jrtd��dS)NzI/O operation on closed file.T)rer")rDr?r?r@ra�szBytesIO.readablecCs|jrtd��dS)NzI/O operation on closed file.T)rer")rDr?r?r@rc�szBytesIO.writablecCs|jrtd��dS)NzI/O operation on closed file.T)rer")rDr?r?r@r^�szBytesIO.seekable)N)N)r)N)rHrIrJrCr�r�r�r�r3rqr�r}rUrXrYrarcr^�
__classcell__r?r?)rRr@r�@s



r�c@sveZdZdZefdd�Zdd�Zdd�Zdd	d
�Zddd�Z	ddd�Z
ddd�Zdd�Zdd�Z
dd�Zddd�ZdS)r0aBufferedReader(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|j�std��tj||�|dkr,td��||_|j�t�|_dS)zMCreate a new buffered reader using the given readable raw IO object.
        z "raw" argument must be readable.rzinvalid buffer sizeN)	rar,r�r�r"�buffer_size�_reset_read_buf�Lock�
_read_lock)rDr;r�r?r?r@r��szBufferedReader.__init__cCs
|jj�S)N)r;ra)rDr?r?r@ra�szBufferedReader.readablecCsd|_d|_dS)Nr�r)�	_read_buf�	_read_pos)rDr?r?r@r��szBufferedReader._reset_read_bufNc	Cs4|dk	r|dkrtd��|j�|j|�SQRXdS)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 readr)r"r��_read_unlocked)rDrmr?r?r@rq�szBufferedReader.readcCs�d}d}|j}|j}|dks$|dkr�|j�t|jd�rj|jj�}|dkrZ||d�pXdS||d�|S||d�g}d}x2|jj�}||kr�|}P|t|�7}|j|�q~Wdj	|�p�|St|�|}	||	kr�|j|7_||||�S||d�g}t
|j|�}
xB|	|k�rL|jj|
�}||k�r2|}P|	t|�7}	|j|��qWt||	�}dj	|�}||d�|_d|_|�r�|d|�S|S)Nr�r
r�r)r�Nr)
r�r�r�ror;r�rqr!rz�joinr�r�rk)rDrlZ
nodata_valZempty_valuesr�rV�chunkZchunksZcurrent_size�availZwanted�outr?r?r@r��sN




zBufferedReader._read_unlockedrc	Cs|j�|j|�SQRXdS)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_unlocked)rDrmr?r?r@rhszBufferedReader.peekcCsrt||j�}t|j�|j}||ks,|dkrb|j|}|jj|�}|rb|j|jd�||_d|_|j|jd�S)Nr)rkr�r!r�r�r;rq)rDrlZwantZhaveZto_readZcurrentr?r?r@r�)s
zBufferedReader._peek_unlockedcCsT|dkrtd��|dkrdS|j�(|jd�|jt|t|j�|j��SQRXdS)z<Reads up to size bytes, with at most one read() system call.rz(number of bytes to read must be positiver�r
N)r"r�r�r�rkr!r�r�)rDrmr?r?r@r�4s
zBufferedReader.read1cCst|t�st|�}|jdkr dS|jd�}d}|j��x�|t|�k�rtt|j�|jt|��}|r�|j|j|j|�||||�<|j|7_||7}|t|�kr�Pt|�||j	kr�|j
j||d��}|s�P||7}n|o�|s�|jd�s�P|r8|r8Pq8WWdQRX|S)z2Read data into *buf* with at most one system call.rr�Nr
)
rr�r�r�r�r!rkr�r�r�r;r�r�)rDr�r��writtenr�rlr?r?r@r�Fs4


"

zBufferedReader._readintocCstj|�t|j�|jS)N)r�rXr!r�r�)rDr?r?r@rXtszBufferedReader.tellcCsX|tkrtd��|j�8|dkr4|t|j�|j8}tj|||�}|j�|SQRXdS)Nzinvalid whence valuer
)	�valid_seek_flagsr"r�r!r�r�r�rUr�)rDrVrWr?r?r@rUwszBufferedReader.seek)N)N)r)r)r)rHrIrJrCr(r�rar�rqr�rhr�r�r�rXrUr?r?r?r@r0�s	


4


.r0c@sXeZdZdZefdd�Zdd�Zdd�Zdd	d
�Zdd�Z	d
d�Z
dd�Zddd�ZdS)r/z�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|j�std��tj||�|dkr,td��||_t�|_t�|_	dS)Nz "raw" argument must be writable.rzinvalid buffer size)
rcr,r�r�r"r�rp�
_write_bufr��_write_lock)rDr;r�r?r?r@r��szBufferedWriter.__init__cCs
|jj�S)N)r;rc)rDr?r?r@rc�szBufferedWriter.writablecCs�|jrtd��t|t�r td��|j��t|j�|jkr@|j	�t|j�}|jj
|�t|j�|}t|j�|jkr�y|j	�Wnltk
r�}zPt|j�|jkr�t|j�|j}||8}|jd|j�|_t|j|j
|��WYdd}~XnX|SQRXdS)Nzwrite to closed filez can't write str to binary stream)rer"rrrr�r!r�r��_flush_unlocked�extend�BlockingIOError�errno�strerror)rDrZbeforer��eZoverager?r?r@r}�s(

"zBufferedWriter.writeNc	Cs8|j�(|j�|dkr"|jj�}|jj|�SQRXdS)N)r�r�r;rXrY)rDrVr?r?r@rY�s

zBufferedWriter.truncatec	Cs|j�|j�WdQRXdS)N)r�r�)rDr?r?r@r[�szBufferedWriter.flushcCs�|jrtd��xz|jr�y|jj|j�}Wntk
rDtd��YnX|dkr\ttjdd��|t	|j�ksr|dkrzt
d��|jd|�=qWdS)Nzflush of closed filezHself.raw should implement RawIOBase: it should not raise BlockingIOErrorz)write could not complete without blockingrz*write() returned incorrect number of bytes)rer"r�r;r}r��RuntimeErrorr�ZEAGAINr!r,)rDrlr?r?r@r��szBufferedWriter._flush_unlockedcCstj|�t|j�S)N)r�rXr!r�)rDr?r?r@rX�szBufferedWriter.tellrcCs8|tkrtd��|j�|j�tj|||�SQRXdS)Nzinvalid whence value)r�r"r�r�r�rU)rDrVrWr?r?r@rU�s
zBufferedWriter.seek)N)r)
rHrIrJrCr(r�rcr}rYr[r�rXrUr?r?r?r@r/�s
r/c@s�eZdZdZefdd�Zddd�Zdd�Zd	d
�Zddd
�Z	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<|j�std��|j�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)rar,rcr0�readerr/�writer)rDr�r�r�r?r?r@r��szBufferedRWPair.__init__NcCs|dkrd}|jj|�S)Nr
r)r�rq)rDrmr?r?r@rq�szBufferedRWPair.readcCs|jj|�S)N)r�r�)rDrr?r?r@r��szBufferedRWPair.readintocCs|jj|�S)N)r�r})rDrr?r?r@r}szBufferedRWPair.writercCs|jj|�S)N)r�rh)rDrmr?r?r@rhszBufferedRWPair.peekcCs|jj|�S)N)r�r�)rDrmr?r?r@r�szBufferedRWPair.read1cCs|jj|�S)N)r�r�)rDrr?r?r@r�
szBufferedRWPair.readinto1cCs
|jj�S)N)r�ra)rDr?r?r@ra
szBufferedRWPair.readablecCs
|jj�S)N)r�rc)rDr?r?r@rcszBufferedRWPair.writablecCs
|jj�S)N)r�r[)rDr?r?r@r[szBufferedRWPair.flushc
Cs z|jj�Wd|jj�XdS)N)r�r3r�)rDr?r?r@r3szBufferedRWPair.closecCs|jj�p|jj�S)N)r�r'r�)rDr?r?r@r'szBufferedRWPair.isattycCs|jjS)N)r�re)rDr?r?r@reszBufferedRWPair.closed)N)r)rHrIrJrCr(r�rqr�r}rhr�r�rarcr[r3r'rrer?r?r?r@r��s

r�c@sleZdZdZefdd�Zddd�Zdd�Zdd
d�Zddd
�Z	dd�Z
ddd�Zdd�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(|j�tj|||�tj|||�dS)N)r`r0r�r/)rDr;r�r?r?r@r�-szBufferedRandom.__init__rcCs�|tkrtd��|j�|jrJ|j� |jj|jt|j�d�WdQRX|jj||�}|j�|j	�WdQRX|dkr�t
d��|S)Nzinvalid whence valuer
rz seek() returned invalid position)r�r"r[r�r�r;rUr�r!r�r,)rDrVrWr?r?r@rU2s$zBufferedRandom.seekcCs|jrtj|�Stj|�SdS)N)r�r/rXr0)rDr?r?r@rXCs
zBufferedRandom.tellNcCs|dkr|j�}tj||�S)N)rXr/rY)rDrVr?r?r@rYIszBufferedRandom.truncatecCs |dkrd}|j�tj||�S)Nr
r)r[r0rq)rDrmr?r?r@rqOszBufferedRandom.readcCs|j�tj||�S)N)r[r0r�)rDrr?r?r@r�UszBufferedRandom.readintocCs|j�tj||�S)N)r[r0rh)rDrmr?r?r@rhYszBufferedRandom.peekcCs|j�tj||�S)N)r[r0r�)rDrmr?r?r@r�]szBufferedRandom.read1cCs|j�tj||�S)N)r[r0r�)rDrr?r?r@r�aszBufferedRandom.readinto1cCsF|jr:|j�(|jj|jt|j�d�|j�WdQRXtj||�S)Nr
)	r�r�r;rUr�r!r�r/r})rDrr?r?r@r}es
zBufferedRandom.write)r)N)N)r)rHrIrJrCr(r�rUrXrYrqr�rhr�r�r}r?r?r?r@r.$s



r.cs�eZdZd0ZdZdZdZdZdZdZ	d1dd�Z
dd	�Zd
d�Zdd
�Z
dd�Zd2dd�Zd3dd�Zdd�Zdd�Zdd�Zefdd�Zdd�Zd4dd�Z�fd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zed,d-��Zed.d/��Z �Z!S)5r&r
FNTrc
Cs
|jdkr*z|jrtj|j�Wdd|_Xt|t�r<td��t|t�r\|}|dkr`td��nd}t|t	�sxtd|f��t
|�t
d�ks�td|f��tdd	�|D��dks�|jd
�dkr�td��d|kr�d
|_
d
|_tjtjB}nVd|k�r�d
|_d}n@d|k�rd
|_tjtjB}n"d|k�r:d
|_d
|_tjtjB}d
|k�rPd
|_d
|_|j�rl|j�rl|tjO}n|j�r�|tjO}n
|tjO}|ttdd�O}ttdd��p�ttdd�}||O}d}�y|dk�r<|�s�td��|dk�r�tj||d�}n0|||�}t|t��std��|dk�r&td��|}|�s<tj|d�||_tj|�}	y(tj|	j��rrt t!j"tj#t!j"�|��Wnt$k
�r�YnXt|	dd�|_%|j%dk�r�t&|_%t'�r�t'|tj(�||_)|j�r�tj*|dt+�Wn"|dk	�r�tj|��YnX||_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).
        rNr
z$integer argument expected, got floatznegative file descriptorzinvalid mode: %szxrwab+css|]}|dkVqdS)ZrwaxNr?)�.0�cr?r?r@�	<genexpr>�sz"FileIO.__init__.<locals>.<genexpr>rzKMust have exactly one of create/read/write/append mode and at most one plusrTrrr�O_BINARYZO_NOINHERIT�	O_CLOEXECz'Cannot use closefd=False with file namei�zexpected integer from openerzNegative file descriptorFr+rr),�_fd�_closefdrr3r�floatrrr"rr �sum�count�_created�	_writable�O_EXCL�O_CREAT�	_readable�O_TRUNC�
_appending�O_APPEND�O_RDWR�O_RDONLY�O_WRONLY�getattrrAr,�set_inheritabler)�stat�S_ISDIR�st_mode�IsADirectoryErrorr�ZEISDIRr�r-�_blksizer(�_setmoder�rS�lseekr	)
rDr4r2r9r�fd�flagsZnoinherit_flagZowned_fdZfdfstatr?r?r@r�ws�




$











zFileIO.__init__cCsD|jdkr@|jr@|jr@ddl}|jd|ftd|d�|j�dS)Nrzunclosed file %rr)�
stacklevel�source)r�r�rer#r$�ResourceWarningr3)rDr#r?r?r@r]�s

zFileIO.__del__cCstd|jj��dS)Nzcannot serialize '%s' object)rrRrH)rDr?r?r@r��szFileIO.__getstate__c
Csld|jj|jjf}|jr"d|Sy
|j}Wn&tk
rRd||j|j|jfSXd|||j|jfSdS)Nz%s.%sz
<%s [closed]>z<%s fd=%d mode=%r closefd=%r>z<%s name=%r mode=%r closefd=%r>)	rRrIrJrerSr-r�r2r�)rD�
class_namerSr?r?r@r��s
zFileIO.__repr__cCs|jstd��dS)NzFile not open for reading)r�rP)rDr?r?r@rbszFileIO._checkReadablecCs|jstd��dS)NzFile not open for writing)r�rP)rDr_r?r?r@rdszFileIO._checkWritablecCsP|j�|j�|dks |dkr(|j�Sytj|j|�Stk
rJdSXdS)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)rZrbr�rrqr�r�)rDrmr?r?r@rqszFileIO.readcCs�|j�|j�t}y6tj|jdt�}tj|j�j}||krH||d}Wnt	k
r^YnXt
�}xnt|�|kr�t|�}|t|t�7}|t|�}ytj
|j|�}Wntk
r�|r�PdSX|s�P||7}qhWt|�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)rZrbr(rr�r�rr)�st_sizer,rpr!r�rqr�r)rD�bufsizerV�endr<rlr�r?r?r@r�s4zFileIO.readallcCs4t|�jd�}|jt|��}t|�}||d|�<|S)zSame as RawIOBase.readinto().r�N)r�r�rqr!)rDr�mr�rlr?r?r@r�?s
zFileIO.readintocCs8|j�|j�ytj|j|�Stk
r2dSXdS)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)rZrdrr}r�r�)rDrr?r?r@r}GszFileIO.writecCs*t|t�rtd��|j�tj|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�rrZrr�r�)rDrVrWr?r?r@rUUs
zFileIO.seekcCs|j�tj|jdt�S)zYtell() -> int.  Current file position.

        Can raise OSError for non seekable files.r)rZrr�r�r)rDr?r?r@rXeszFileIO.tellcCs2|j�|j�|dkr |j�}tj|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)rZrdrXr�	ftruncater�)rDrmr?r?r@rYlszFileIO.truncatec
s.|js*z|jrtj|j�Wdt�j�XdS)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)rer�rr3r�r�)rD)rRr?r@r3ys
zFileIO.closecCsF|j�|jdkr@y|j�Wntk
r8d|_YnXd|_|jS)z$True if file supports random-access.NFT)rZ�	_seekablerXr,)rDr?r?r@r^�s
zFileIO.seekablecCs|j�|jS)z'True if file was opened in a read mode.)rZr�)rDr?r?r@ra�szFileIO.readablecCs|j�|jS)z(True if file was opened in a write mode.)rZr�)rDr?r?r@rc�szFileIO.writablecCs|j�|jS)z3Return the underlying file descriptor (an integer).)rZr�)rDr?r?r@r*�sz
FileIO.filenocCs|j�tj|j�S)z.True if the file is connected to a TTY device.)rZrr'r�)rDr?r?r@r'�sz
FileIO.isattycCs|jS)z6True if the file descriptor will be closed by close().)r�)rDr?r?r@r9�szFileIO.closefdcCsJ|jr|jrdSdSn0|jr,|jr&dSdSn|jrB|jr<dSdSndSdS)	zString giving the file modezxb+Zxbzab+Zabzrb+�rb�wbN)r�r�r�r�)rDr?r?r@r2�szFileIO.moder)rTN)N)N)N)"rHrIrJr�r�r�r�r�r�r�r�r]r�r�rbrdrqr�r�r}rrUrXrYr3r^rarcr*r'rr9r2r�r?r?)rRr@r&ns8
u

#

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

    This class provides a character and line based interface to stream
    I/O. There is no readinto method because Python's character strings
    are immutable. There is no public constructor.
    r
cCs|jd�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.
        rqN)rT)rDrmr?r?r@rq�szTextIOBase.readcCs|jd�dS)z.Write string s to stream and returning an int.r}N)rT)rD�sr?r?r@r}�szTextIOBase.writeNcCs|jd�dS)z*Truncate size to pos, where pos is an int.rYN)rT)rDrVr?r?r@rY�szTextIOBase.truncatecCs|jd�dS)z_Read until newline or EOF.

        Returns an empty string if EOF is hit immediately.
        rtN)rT)rDr?r?r@rt�szTextIOBase.readlinecCs|jd�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�N)rT)rDr?r?r@r��szTextIOBase.detachcCsdS)zSubclasses should override.Nr?)rDr?r?r@r6�szTextIOBase.encodingcCsdS)z�Line endings translated so far.

        Only line endings translated during reading are considered.

        Subclasses should override.
        Nr?)rDr?r?r@�newlines�szTextIOBase.newlinescCsdS)zMError setting of the decoder or encoder.

        Subclasses should override.Nr?)rDr?r?r@r7�szTextIOBase.errorsr)r)N)
rHrIrJrCrqr}rYrtr�rr6r�r7r?r?r?r@r��s


	
r�c@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)r7rF)�codecs�IncrementalDecoderr��	translate�decoder�seennl�	pendingcr)rDr�r�r7r?r?r@r�s
z"IncrementalNewlineDecoder.__init__FcCs�|jdkr|}n|jj||d�}|jr<|s.|r<d|}d|_|jd�r^|r^|dd�}d|_|jd�}|jd�|}|jd�|}|j|o�|j|o�|jB|o�|jBO_|j	r�|r�|j
dd�}|r�|j
dd�}|S)	N)�final�
Fr
Tz
�
r)r��decoder�rrr�r��_LF�_CR�_CRLFr��replace)rD�inputr��outputZcrlfZcrZlfr?r?r@r�s(

"z IncrementalNewlineDecoder.decodecCs@|jdkrd}d}n|jj�\}}|dK}|jr8|dO}||fS)Nr�rr
)r��getstater�)rDr��flagr?r?r@r2s
z"IncrementalNewlineDecoder.getstatecCs8|\}}t|d@�|_|jdk	r4|jj||d?f�dS)Nr
)�boolr�r��setstate)rD�stater�rr?r?r@r=s
z"IncrementalNewlineDecoder.setstatecCs$d|_d|_|jdk	r |jj�dS)NrF)r�r�r��reset)rDr?r?r@rCs
zIncrementalNewlineDecoder.resetr
r�c
Cs
d|jS)	Nr�r��
�r�r��r�r�r�r�r�r�r)Nr�r�r	rr
rr)r�)rDr?r?r@r�Msz"IncrementalNewlineDecoder.newlinesN)r�)F)rHrIrJrCr�r�rrrr�r�r�rr�r?r?r?r@r�s

r�c@s>eZdZdZdZdFdd�Zdd�Zed	d
��Zedd��Z	ed
d��Z
edd��Zdd�Zdd�Z
dd�Zdd�Zdd�Zedd��Zedd��Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�ZdGd+d,�Zd-d.�Zd/d0�ZdHd2d3�Zd4d5�Zd6d7�ZdId8d9�Zd:d;�Z dJd<d=�Z!dKd>d?�Z"d@dA�Z#dLdBdC�Z$edDdE��Z%dS)Mr1aCharacter 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�|dk	r&t|t�r&tdt|�f��|dkr<td|f��|dkr�ytj|j��}Wntt	fk
rnYnX|dkr�yddl
}Wntk
r�d}YnX|jd	�}t|t�s�td
|��t
j|�js�d}t||��|dkr�d}nt|t��std
|��||_||_||_||_||_|dk|_||_|dk|_|�pDtj|_d|_d|_d|_d|_d|_|j j!�|_"|_#t$|j d�|_%d|_&|j"�r�|j'��r�|j j(�}	|	dk�r�y|j)�j*d�Wntk
�r�YnXdS)Nzillegal newline type: %rrr�r��
zillegal newline value: %rr�asciiFzinvalid encoding: %rzG%r is not a text encoding; use codecs.open() to handle arbitrary codecsr�zinvalid errors: %rr�g)Nrr�r�r
)+rrr�typer"r�device_encodingr*r-rP�locale�ImportError�getpreferredencodingr��lookup�_is_text_encoding�LookupErrorr��_line_buffering�	_encoding�_errors�_readuniversal�_readtranslate�_readnl�_writetranslate�linesep�_writenl�_encoder�_decoder�_decoded_chars�_decoded_chars_used�	_snapshotr>r^r��_tellingro�
_has_read1�	_b2cratiorcrX�_get_encoderr)
rDr>r6r7r8r=�
write_throughrr_�positionr?r?r@r�ws`






zTextIOWrapper.__init__cCs�dj|jj|jj�}y
|j}Wntk
r2YnX|dj|�7}y
|j}Wntk
r`YnX|dj|�7}|dj|j�S)Nz<{}.{}z name={0!r}z mode={0!r}z encoding={0!r}>)r�rRrIrJrSr�r2r6)rDr<rSr2r?r?r@r��s



zTextIOWrapper.__repr__cCs|jS)N)r)rDr?r?r@r6�szTextIOWrapper.encodingcCs|jS)N)r)rDr?r?r@r7�szTextIOWrapper.errorscCs|jS)N)r)rDr?r?r@r=�szTextIOWrapper.line_bufferingcCs|jS)N)r�)rDr?r?r@r>�szTextIOWrapper.buffercCs|jrtd��|jS)NzI/O operation on closed file.)rer"r�)rDr?r?r@r^�szTextIOWrapper.seekablecCs
|jj�S)N)r>ra)rDr?r?r@ra�szTextIOWrapper.readablecCs
|jj�S)N)r>rc)rDr?r?r@rc�szTextIOWrapper.writablecCs|jj�|j|_dS)N)r>r[r�r%)rDr?r?r@r[�s
zTextIOWrapper.flushc
Cs0|jdk	r,|jr,z|j�Wd|jj�XdS)N)r>rer[r3)rDr?r?r@r3�szTextIOWrapper.closecCs|jjS)N)r>re)rDr?r?r@re�szTextIOWrapper.closedcCs|jjS)N)r>rS)rDr?r?r@rS�szTextIOWrapper.namecCs
|jj�S)N)r>r*)rDr?r?r@r*�szTextIOWrapper.filenocCs
|jj�S)N)r>r')rDr?r?r@r'�szTextIOWrapper.isattycCs�|jrtd��t|t�s(td|jj��t|�}|js<|j	oBd|k}|rf|jrf|j
dkrf|jd|j
�}|jpr|j
�}|j|�}|jj|�|j	r�|s�d|kr�|j�|jd�d|_|jr�|jj�|S)zWrite data, where s is a strzwrite to closed filezcan't write %s to text streamr�r�rN)rer"rrrrRrHr!rrrr�r r(�encoder>r}r[�_set_decoded_charsr$r!r)rDr�ZlengthZhaslf�encoderrr?r?r@r}s&



zTextIOWrapper.writecCstj|j�}||j�|_|jS)N)r��getincrementalencoderrrr )rDZmake_encoderr?r?r@r(szTextIOWrapper._get_encodercCs2tj|j�}||j�}|jr(t||j�}||_|S)N)r��getincrementaldecoderrrrr�rr!)rDZmake_decoderr�r?r?r@�_get_decoders
zTextIOWrapper._get_decodercCs||_d|_dS)zSet the _decoded_chars buffer.rN)r"r#)rD�charsr?r?r@r,)sz TextIOWrapper._set_decoded_charscCsF|j}|dkr|j|d�}n|j|||�}|jt|�7_|S)z'Advance into the _decoded_chars buffer.N)r#r"r!)rDrl�offsetr1r?r?r@�_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#�AssertionError)rDrlr?r?r@�_rewind_decoded_chars8s
z#TextIOWrapper._rewind_decoded_charscCs�|jdkrtd��|jr&|jj�\}}|jr<|jj|j�}n|jj|j�}|}|jj	||�}|j
|�|r�t|�t|j�|_
nd|_
|jr�|||f|_|S)zQ
        Read and decode the next chunk of data from the BufferedReader.
        Nz
no decoderg)r!r"r%rr&r>r��_CHUNK_SIZErqr�r,r!r"r'r$)rD�
dec_buffer�	dec_flags�input_chunk�eofZ
decoded_charsr?r?r@�_read_chunk>s 

zTextIOWrapper._read_chunkrcCs(||d>B|d>B|d>Bt|�d>BS)N�@���)r)rDr*r8�
bytes_to_feed�need_eof�
chars_to_skipr?r?r@�_pack_cookiehszTextIOWrapper._pack_cookiecCsFt|d�\}}t|d�\}}t|d�\}}t|d�\}}|||||fS)Nr
r<llll)�divmod)rDZbigint�restr*r8r@rArBr?r?r@�_unpack_cookiers
zTextIOWrapper._unpack_cookiecCsN|jstd��|jstd��|j�|jj�}|j}|dksF|jdkrX|j	rTt
d��|S|j\}}|t|�8}|j}|dkr�|j
||�S|j�}�z�t|j|�}d}|t|�ks�t
�x�|dk�r4|jd|f�t|j|d|���}	|	|k�r"|j�\}
}|
�s|}||	8}P|t|
�8}d}q�||8}|d}q�Wd}|jd|f�||}|}
|dk�rj|j
||
�Sd}d}d}x�t|t|��D]v}|d7}|t|j|||d���7}|j�\}}|�r�||k�r�||7}||8}|dd}
}}||k�r�P�q�W|t|jddd	��7}d}||k�r,td
��|j
||
|||�S|j|�XdS)Nz!underlying stream is not seekablez(telling position disabled by next() callzpending decoded textrr
r�rT)r�z'can't reconstruct logical file position)r�rPr%r,r[r>rXr!r$r"r4r!r#rCrrr'rr��range)rDr*r�r8Z
next_inputrBZsaved_stateZ
skip_bytesZ	skip_backrlr�d�	start_posZstart_flagsZ	bytes_fedrAZ
chars_decoded�ir7r?r?r@rXysx





zTextIOWrapper.tellcCs$|j�|dkr|j�}|jj|�S)N)r[rXr>rY)rDrVr?r?r@rY�szTextIOWrapper.truncatecCs*|jdkrtd��|j�|j}d|_|S)Nzbuffer is already detached)r>r"r[r�)rDr>r?r?r@r��s
zTextIOWrapper.detachcs��fdd�}�jrtd���js(td��|dkrL|dkr@td��d}�j�}|dkr�|dkrdtd	���j��jjdd�}�jd
�d�_	�j
r��j
j�||�|S|dkr�td|f��|dkr�td|f���j��j|�\}}}}}	�jj|��jd
�d�_	|dk�r(�j
�r(�j
j�n@�j
�s<|�s<|	�rh�j
�pJ�j
��_
�j
jd
|f�|d
f�_	|	�r��jj|�}
�j�j
j|
|��||
f�_	t�j�|	k�r�td��|	�_||�|S)NcsHy�jp�j�}Wntk
r&YnX|dkr<|jd�n|j�dS)z9Reset the encoder (merely useful for proper BOM handling)rN)r r(rrr)r*r-)rDr?r@�_reset_encoder�sz*TextIOWrapper.seek.<locals>._reset_encoderztell on closed filez!underlying stream is not seekabler
rz#can't do nonzero cur-relative seeksrz#can't do nonzero end-relative seeksrzunsupported whence (%r)znegative seek position %rr�z#can't restore logical file position)rer"r�rPrXr[r>rUr,r$r!rrFr0rrqr�r!r"r,r#)rDZcookierWrKr*rIr8r@rArBr9r?)rDr@rU�s\





zTextIOWrapper.seekcCs�|j�|dkrd}|jp |j�}y
|jWn,tk
rX}ztd�|�WYdd}~XnX|dkr�|j�|j|jj	�dd�}|j
d�d|_|Sd}|j|�}x6t|�|kr�|r�|j
�}||j|t|��7}q�W|SdS)	Nr
zan integer is requiredrT)r�rFr)rbr!r0r�r-rr3r�r>rqr,r$r!r;)rDrmr�r�r<r:r?r?r@rq5	s(



zTextIOWrapper.readcCs(d|_|j�}|s$d|_|j|_t�|S)NF)r%rtr$r�rv)rDrwr?r?r@rxN	szTextIOWrapper.__next__cCs�|jrtd��|dkrd	}nt|t�s.td��|j�}d}|jsH|j�d}}�xR|jr�|j	d|�}|dkrz|d}Pnt
|�}n�|j�r|j	d|�}|j	d|�}|d
kr�|dkr�t
|�}n
|d}PnL|dkr�|d}Pn8||kr�|d}Pn$||dk�r|d}Pn
|d}Pn&|j	|j�}|dk�r>|t
|j�}P|dk�r\t
|�|k�r\|}Px|j
��rv|j�r^P�q^W|j�r�||j�7}qT|jd�d|_|SqTW|dk�r�||k�r�|}|jt
|�|�|d|�S)
Nzread from closed filer
zsize must be an integerrr�r�rrrrrr)rer"rrrr3r!r0rrjr!rrr;r"r,r$r5)rDrmrw�startrV�endposZnlposZcrposr?r?r@rtW	sp




zTextIOWrapper.readlinecCs|jr|jjSdS)N)r!r�)rDr?r?r@r��	szTextIOWrapper.newlines)NNNFF)N)rrrr)N)r)N)N)&rHrIrJrCr6r�r�rr6r7r=r>r^rarcr[r3rerSr*r'r}r(r0r,r3r5r;rCrFrXrYr�rUrqrxrtr�r?r?r?r@r1ZsH
E

*
	c

K
	
Xr1csReZdZdZd�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�|dkr(d|_|dk	rbt|t�sNtdjt	|�j
���|j|�|jd�dS)Nzutf-8�
surrogatepass)r6r7r8Fz*initial_value must be str or None, not {0}r)
r�rNr�r�rrrrr�rrHr}rU)rDZ
initial_valuer8)rRr?r@r��	s

zStringIO.__init__cCsL|j�|jp|j�}|j�}|j�z|j|jj�dd�S|j|�XdS)NT)r�)	r[r!r0rrr�r>r�r)rDr�Z	old_stater?r?r@r��	szStringIO.getvaluecCs
tj|�S)N)�objectr�)rDr?r?r@r��	szStringIO.__repr__cCsdS)Nr?)rDr?r?r@r7�	szStringIO.errorscCsdS)Nr?)rDr?r?r@r6�	szStringIO.encodingcCs|jd�dS)Nr�)rT)rDr?r?r@r��	szStringIO.detach)rr�)rHrIrJrCr�r�r�rr7r6r�r�r?r?)rRr@rN�	s
rN>rri r)rrNNNTN)5rCr�abcr�r�r��sys�_threadrr�rZ
_dummy_thread�platformZmsvcrtrr��iorrrr	r�ro�addr�	SEEK_DATAr(r�rArBrKrPr-r,r"�ABCMetarQ�registerr��_ior&r�r�r�r0r/r�r.r�r�r�r1rNr?r?r?r@�<module>sv



T	
=
giCZIJUAU^