%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core20/2318/lib/python3.8/__pycache__/
Upload File :
Create Path :
Current File : //snap/core20/2318/lib/python3.8/__pycache__/_pyio.cpython-38.pyc

U

k�]e�k�@s|dZddlZddlZddlZddlZddlZddlZddlmZ	ej
dkrXddlmZ
ndZ
ddlZddlmZmZmZmZdddhZeed	�r�e�ej�e�ej�d
ZeZeed�p�ejjZd7dd�Zdd�Zz
ejZWne k
�r�eZYnXGdd�d�Z!Gdd�d�Z"z
ej#Z#Wn(e k
�rHGdd�de$e%�Z#YnXGdd�dej&d�Z'ej'�(e'�Gdd�de'�Z)ej)�(e)�ddl*m+Z+e)�(e+�Gdd �d e'�Z,ej,�(e,�Gd!d"�d"e,�Z-Gd#d$�d$e,�Z.Gd%d&�d&e-�Z/Gd'd(�d(e-�Z0Gd)d*�d*e,�Z1Gd+d,�d,e0e/�Z2Gd-d.�d.e)�Z+Gd/d0�d0e'�Z3ej3�(e3�Gd1d2�d2ej4�Z5Gd3d4�d4e3�Z6Gd5d6�d6e6�Z7dS)8z)
Python implementation of the io module.
�N)�
allocate_lock>�win32�cygwin)�setmode)�__all__�SEEK_SET�SEEK_CUR�SEEK_END���	SEEK_HOLEi Zgettotalrefcount�r���Tc	Cs�t|t�st�|�}t|tttf�s0td|��t|t�sFtd|��t|t�s\td|��|dk	rzt|t�sztd|��|dk	r�t|t�s�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�rD|	�s"|�s"|�s"|
�r*t	d��ddl
}|�dtd�d}
|�rX|�rXt	d��|	|
||dk�rvt	d��|	�s�|
�s�|�s�|�s�t	d��|�r�|dk	�r�t	d��|�r�|dk	�r�t	d��|�r�|dk	�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}Wnttfk
�r�YnX|dk�r�|}|dk�r�t	d!��|dk�r|�r|WSt	d"��|
�r t||�}n<|	�s2|�s2|�r>t||�}n|
�rPt||�}nt	d#|��|}|�rl|WSt|||||�}|}||_|WS|���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: %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 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 argumentzaline buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used�)�openerFrzinvalid buffering sizezcan't have unbuffered text I/Ozunknown mode: %r)�
isinstance�int�os�fspath�str�bytes�	TypeError�set�len�
ValueError�warnings�warn�DeprecationWarning�RuntimeWarning�FileIO�isatty�DEFAULT_BUFFER_SIZE�fstat�fileno�
st_blksize�OSError�AttributeError�BufferedRandom�BufferedWriter�BufferedReader�
TextIOWrapper�mode�close)�filer4�	buffering�encoding�errors�newline�closefdrZmodesZcreatingZreadingZwritingZ	appendingZupdating�textZbinaryr$�raw�result�line_bufferingZbs�buffer�rA�/usr/lib/python3.8/_pyio.py�open)s�{




�������



rCcCs 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'rC)�pathr$rArArB�_open_code_with_warnings�rFc@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)

)rC�__doc__)�self�obj�typrArArB�__get__s��zDocDescriptor.__get__)N)�__name__�
__module__�__qualname__rHrLrArArArBrGsrGc@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)rC)�cls�args�kwargsrArArB�__new__,szOpenWrapper.__new__N)rMrNrOrHrGrUrArArArBrP"srPc@seZdZdS)�UnsupportedOperationN)rMrNrOrArArArBrV5srVc@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)>�IOBaseaThe 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 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)rV�	__class__rM)rI�namerArArB�_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�rZ�rI�pos�whencerArArBr[cszIOBase.seekcCs|�dd�S)z5Return an int indicating the current stream position.rr
)r[�rIrArArB�tellsszIOBase.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\�rIr^rArArBrbwszIOBase.truncatecCs|��dS)zuFlush write buffers, if applicable.

        This is not implemented for read-only and non-blocking streams.
        N��_checkClosedr`rArArB�flush�szIOBase.flushFcCs |jsz|��W5d|_XdS)ziFlush and close the IO object.

        This method has no effect if the file is already closed.
        TN)�_IOBase__closedrfr`rArArBr5�szIOBase.closecCsVz
|j}Wntk
r YdSX|r*dStr8|��nz|��WnYnXdS)zDestructor.  Calls close().N)�closedr/�_IOBASE_EMITS_UNRAISABLEr5)rIrhrArArB�__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().
        FrAr`rArArB�seekable�szIOBase.seekablecCs |��st|dkrdn|��dS)zEInternal: raise UnsupportedOperation if file is not seekable
        NzFile or stream is not seekable.)rkrV�rI�msgrArArB�_checkSeekable�s��zIOBase._checkSeekablecCsdS)zvReturn a bool indicating whether object was opened for reading.

        If False, read() will raise OSError.
        FrAr`rArArB�readable�szIOBase.readablecCs |��st|dkrdn|��dS)zEInternal: raise UnsupportedOperation if file is not readable
        NzFile or stream is not readable.)rorVrlrArArB�_checkReadable�s��zIOBase._checkReadablecCsdS)z�Return a bool indicating whether object was opened for writing.

        If False, write() and truncate() will raise OSError.
        FrAr`rArArB�writable�szIOBase.writablecCs |��st|dkrdn|��dS)zEInternal: raise UnsupportedOperation if file is not writable
        NzFile or stream is not writable.)rqrVrlrArArB�_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.
        )rgr`rArArBrh�sz
IOBase.closedcCs|jrt|dkrdn|��dS)z7Internal: raise a ValueError if file is closed
        N�I/O operation on closed file.�rhr#rlrArArBre�s��zIOBase._checkClosedcCs|��|S)zCContext management protocol.  Returns self (an instance of IOBase).rdr`rArArB�	__enter__�szIOBase.__enter__cGs|��dS)z+Context management protocol.  Calls close()N)r5)rIrSrArArB�__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`rArArBr,�sz
IOBase.filenocCs|��dS)z{Return a bool indicating whether this is an 'interactive' stream.

        Return False if it can't be determined.
        Frdr`rArArBr)sz
IOBase.isattyrcs�t�d�r��fdd�}ndd�}�dkr0d�n4z
�j}Wn"tk
r\t��d���YnX|��t�}�dks~t|��kr���|��}|s�q�||7}|�d	�rjq�qjt|�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)rw�findr"�min)Z	readahead�n�rI�sizerArB�
nreadaheads

z#IOBase.readline.<locals>.nreadaheadcSsdS�Nr
rArArArArBr~ sNr� is not an integerrrx)	�hasattr�	__index__r/r �	bytearrayr"�read�endswithr)rIr}r~�
size_index�resrrAr|rB�readlines&
	

zIOBase.readlinecCs|��|SrQrdr`rArArB�__iter__5szIOBase.__iter__cCs|��}|st�|SrQ)r��
StopIteration�rI�linerArArB�__next__9szIOBase.__next__cCsP|dks|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")rIZhintr{�linesr�rArArB�	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)re�write)rIr�r�rArArB�
writelinesQszIOBase.writelines)r)N)N)N)N)N)r)N)rMrNrOrHrZr[rarbrfrgr5rjrkrnrorprqrr�propertyrhrerurvr,r)r�r�r�r�r�rArArArBrW9s6!







	

*
rW)�	metaclassc@s2eZdZdZddd�Zdd�Zdd�Zd	d
�ZdS)
�	RawIOBasezBase class for raw binary I/O.rcCsP|dkrd}|dkr|��St|���}|�|�}|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.
        Nrr)�readallr�r��readintor)rIr}rr{rArArBr�ls

zRawIOBase.readcCs4t�}|�t�}|sq ||7}q|r,t|�S|SdS)z+Read until EOF, using multiple read() call.N)r�r�r*r)rIr��datarArArBr�}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\�rIrrArArBr��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�rArArBr��szRawIOBase.writeN)r)rMrNrOrHr�r�r�r�rArArArBr�^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.
    rcCs|�d�dS)a�Read and return up to size bytes, where size is an int.

        If the argument is omitted, None, or negative, reads and
        returns all data until EOF.

        If the argument is positive, and the underlying raw stream is
        not 'interactive', multiple raw reads may be issued to satisfy
        the byte count (unless EOF is reached first).  But for
        interactive raw streams (XXX and for pipes?), at most one raw
        read will be issued, and a short result does not imply that
        EOF is imminent.

        Returns an empty bytes array on EOF.

        Raises BlockingIOError if the underlying raw stream has no
        data at the moment.
        r�Nr\r|rArArBr��szBufferedIOBase.readcCs|�d�dS)zaRead up to size bytes with at most one read() system call,
        where size is an int.
        �read1Nr\r|rArArBr��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�rArArBr��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�rArArB�	readinto1�s	zBufferedIOBase.readinto1cCsVt|t�st|�}|�d�}|r0|�t|��}n|�t|��}t|�}||d|�<|S)N�B)r�
memoryview�castr�r"r�)rIrr�r�r{rArArBr��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�rArArBr��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`rArArBr��szBufferedIOBase.detachN)r)r)rMrNrOrHr�r�r�r�r�r�r�rArArArBr��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
||_dSrQ��_raw�rIr=rArArB�__init__sz_BufferedIOMixin.__init__rcCs"|j�||�}|dkrtd��|S)Nrz#seek() returned an invalid position)r=r[r.)rIr^r_Znew_positionrArArBr[sz_BufferedIOMixin.seekcCs|j��}|dkrtd��|S)Nrz#tell() returned an invalid position)r=rar.rcrArArBras
z_BufferedIOMixin.tellNcCs$|��|dkr|��}|j�|�SrQ)rfrar=rbrcrArArBrb$sz_BufferedIOMixin.truncatecCs|jrtd��|j��dS)N�flush on closed file)rhr#r=rfr`rArArBrf2sz_BufferedIOMixin.flushcCs.|jdk	r*|js*z|��W5|j��XdSrQ)r=rhr5rfr`rArArBr57sz_BufferedIOMixin.closecCs*|jdkrtd��|��|j}d|_|S)Nzraw stream already detached)r=r#rfr�r�rArArBr�?s
z_BufferedIOMixin.detachcCs
|j��SrQ)r=rkr`rArArBrkIsz_BufferedIOMixin.seekablecCs|jSrQr�r`rArArBr=Lsz_BufferedIOMixin.rawcCs|jjSrQ)r=rhr`rArArBrhPsz_BufferedIOMixin.closedcCs|jjSrQ)r=rYr`rArArBrYTsz_BufferedIOMixin.namecCs|jjSrQ)r=r4r`rArArBr4Xsz_BufferedIOMixin.modecCstd|jj�d���dS�Nzcannot pickle z object�r rXrMr`rArArB�__getstate__\sz_BufferedIOMixin.__getstate__cCsN|jj}|jj}z
|j}Wn tk
r:d�||�YSXd�|||�SdS)Nz<{}.{}>z<{}.{} name={!r}>)rXrNrOrYr/�format)rI�modnameZclsnamerYrArArB�__repr___s
z_BufferedIOMixin.__repr__cCs
|j��SrQ)r=r,r`rArArBr,ksz_BufferedIOMixin.filenocCs
|j��SrQ)r=r)r`rArArBr)nsz_BufferedIOMixin.isatty)r)N)rMrNrOrHr�r[rarbrfr5r�rkr�r=rhrYr4r�r�r,r)rArArArBr�
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�}|dk	r||7}||_d|_dS�Nr)r��_buffer�_pos)rIZ
initial_bytes�bufrArArBr�zs
zBytesIO.__init__cCs|jrtd��|j��S)Nz__getstate__ on closed file)rhr#�__dict__�copyr`rArArBr��szBytesIO.__getstate__cCs|jrtd��t|j�S)z8Return the bytes value (contents) of the buffer
        zgetvalue on closed file)rhr#rr�r`rArArB�getvalue�szBytesIO.getvaluecCs|jrtd��t|j�S)z;Return a readable and writable view of the buffer.
        zgetbuffer on closed file)rhr#r�r�r`rArArB�	getbuffer�szBytesIO.getbuffercs"|jdk	r|j��t���dSrQ)r��clear�superr5r`�rXrArBr5�s

z
BytesIO.closercCs�|jrtd��|dkrd}n4z
|j}Wn"tk
rHt|�d���YnX|�}|dkrbt|j�}t|j�|jkrvdStt|j�|j|�}|j|j|�}||_t	|�S)N�read from closed filerr�r�)
rhr#r�r/r r"r�r�rzr)rIr}r�ZnewposrrArArBr��s"

zBytesIO.readcCs
|�|�S)z"This is the same as read.
        )r�r|rArArBr��sz
BytesIO.read1c	Cs�|jrtd��t|t�r td��t|��}|j}W5QRX|dkrFdS|j}|t|j	�krzd|t|j	�}|j	|7_	||j	|||�<|j|7_|S)N�write to closed file� can't write str to binary streamr�)
rhr#rrr r��nbytesr�r"r�)rIrZviewr{r^ZpaddingrArArBr��s

z
BytesIO.writercCs�|jrtd��z
|j}Wn"tk
r:t|�d���YnX|�}|dkrh|dkr`td|f��||_nD|dkr�td|j|�|_n(|dkr�tdt|j�|�|_ntd��|jS)Nzseek on closed filer�r�negative seek position %rr
rzunsupported whence value)	rhr#r�r/r r��maxr"r�)rIr^r_�	pos_indexrArArBr[�s"
zBytesIO.seekcCs|jrtd��|jS)N�tell on closed file)rhr#r�r`rArArBra�szBytesIO.tellcCsx|jrtd��|dkr|j}nJz
|j}Wn"tk
rJt|�d���YnX|�}|dkrhtd|f��|j|d�=|S)Nztruncate on closed filer�rznegative truncate position %r)rhr#r�r�r/r r�)rIr^r�rArArBrb�s
zBytesIO.truncatecCs|jrtd��dS�NrsTrtr`rArArBro�szBytesIO.readablecCs|jrtd��dSr�rtr`rArArBrq�szBytesIO.writablecCs|jrtd��dSr�rtr`rArArBrk�szBytesIO.seekable)N)r)r)r)N)rMrNrOrHr�r�r�r�r�r5r�r�r�r[rarbrorqrk�
__classcell__rArAr�rBr�rs 




r�c@sxeZdZdZefdd�Zdd�Zdd�Zdd	d
�Zddd�Z	ddd�Z
ddd�Zddd�Zdd�Z
dd�Zd dd�ZdS)!r2aBufferedReader(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)	ror.r�r�r#�buffer_size�_reset_read_buf�Lock�
_read_lock�rIr=r�rArArBr�szBufferedReader.__init__cCs
|j��SrQ)r=ror`rArArBroszBufferedReader.readablecCsd|_d|_dS)Nr�r)�	_read_buf�	_read_posr`rArArBr�szBufferedReader._reset_read_bufNc
Cs@|dk	r|dkrtd��|j�|�|�W5QR�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.
        Nrzinvalid number of bytes to read)r#r��_read_unlockedr|rArArBr� szBufferedReader.readcCs�d}d}|j}|j}|dks$|dkr�|��t|jd�rj|j��}|dkrZ||d�pXdS||d�|S||d�g}d}|j��}||kr�|}q�|t|�7}|�|�q|d�	|�p�|St|�|}	||	kr�|j|7_||||�S||d�g}t
|j|�}
|	|k�rH|j�|
�}||k�r.|}�qH|	t|�7}	|�|��qt||	�}d�	|�}||d�|_d|_|�r�|d|�S|S)Nr�)r�Nrr�r)
r�r�r�r�r=r�r�r"r��joinr�r�rz)rIr{Z
nodata_valZempty_valuesr�r^�chunkZchunksZcurrent_size�availZwanted�outrArArBr�-sL





zBufferedReader._read_unlockedrc
Cs(|j�|�|�W5QR�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_unlockedr|rArArBrwaszBufferedReader.peekcCsrt||j�}t|j�|j}||ks,|dkrb|j|}|j�|�}|rb|j|jd�||_d|_|j|jd�Sr�)rzr�r"r�r�r=r�)rIr{ZwantZhaveZto_readZcurrentrArArBr�ks
zBufferedReader._peek_unlockedrc
Cs^|dkr|j}|dkrdS|j�4|�d�|�t|t|j�|j��W5QR�SQRXdS)z<Reads up to size bytes, with at most one read() system call.rr�r
N)r�r�r�r�rzr"r�r�r|rArArBr�vs
�zBufferedReader.read1c	Cs
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�q6W5QRX|S)z2Read data into *buf* with at most one system call.rr�Nr
)
rr�r�r�r�r"rzr�r�r�r=r�r�)rIr�r��writtenr�r{rArArBr��s6


�

zBufferedReader._readintocCst�|�t|j�|jSrQ)r�rar"r�r�r`rArArBra�szBufferedReader.tellc
Csd|tkrtd��|j�D|dkr4|t|j�|j8}t�|||�}|��|W5QR�SQRXdS)N�invalid whence valuer
)	�valid_seek_flagsr#r�r"r�r�r�r[r�r]rArArBr[�szBufferedReader.seek)N)N)r)r)r)r)rMrNrOrHr*r�ror�r�r�rwr�r�r�rar[rArArArBr2s	


4



.r2c@s`eZdZdZefdd�Zdd�Zdd�Zdd	d
�Zdd�Z	d
d�Z
dd�Zddd�Zdd�Z
dS)r1z�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�)
rqr.r�r�r#r�r��
_write_bufr��_write_lockr�rArArBr��szBufferedWriter.__init__cCs
|j��SrQ)r=rqr`rArArBrq�szBufferedWriter.writablecCst|t�rtd��|j��|jr(td��t|j�|jkr@|�	�t|j�}|j�
|�t|j�|}t|j�|jkr�z|�	�Wnltk
r�}zNt|j�|jkr�t|j�|j}||8}|jd|j�|_t|j|j
|��W5d}~XYnX|W5QR�SQRXdS)Nr�r�)rrr r�rhr#r"r�r��_flush_unlocked�extend�BlockingIOError�errno�strerror)rIrZbeforer��eZoveragerArArBr��s(

"zBufferedWriter.writeNc
CsD|j�4|��|dkr"|j��}|j�|�W5QR�SQRXdSrQ)r�r�r=rarbrcrArArBrb�s

zBufferedWriter.truncatec	Cs|j�|��W5QRXdSrQ)r�r�r`rArArBrf�szBufferedWriter.flushcCs�|jrtd��|jr�z|j�|j�}Wntk
rBtd��YnX|dkrZttjdd��|t	|j�ksp|dkrxt
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)rhr#r�r=r�r��RuntimeErrorr�ZEAGAINr"r.�rIr{rArArBr�s �zBufferedWriter._flush_unlockedcCst�|�t|j�SrQ)r�rar"r�r`rArArBraszBufferedWriter.tellrc
CsD|tkrtd��|j�$|��t�|||�W5QR�SQRXdS)Nr�)r�r#r�r�r�r[r]rArArBr[s
zBufferedWriter.seekcCs`|j�$|jdks|jr&W5QR�dSW5QRXz|��W5|j�|j��W5QRXXdSrQ)r�r=rhr5rfr`rArArBr5szBufferedWriter.close)N)r)rMrNrOrHr*r�rqr�rbrfr�rar[r5rArArArBr1�s

r1c@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)ror.rqr2�readerr1�writer)rIr�r�r�rArArBr�<szBufferedRWPair.__init__rcCs|dkrd}|j�|�S�Nr)r�r�r|rArArBr�JszBufferedRWPair.readcCs|j�|�SrQ)r�r�r�rArArBr�OszBufferedRWPair.readintocCs|j�|�SrQ)r�r�r�rArArBr�RszBufferedRWPair.writercCs|j�|�SrQ)r�rwr|rArArBrwUszBufferedRWPair.peekcCs|j�|�SrQ)r�r�r|rArArBr�XszBufferedRWPair.read1cCs|j�|�SrQ)r�r�r�rArArBr�[szBufferedRWPair.readinto1cCs
|j��SrQ)r�ror`rArArBro^szBufferedRWPair.readablecCs
|j��SrQ)r�rqr`rArArBrqaszBufferedRWPair.writablecCs
|j��SrQ)r�rfr`rArArBrfdszBufferedRWPair.flushcCs z|j��W5|j��XdSrQ)r�r5r�r`rArArBr5gszBufferedRWPair.closecCs|j��p|j��SrQ)r�r)r�r`rArArBr)mszBufferedRWPair.isattycCs|jjSrQ)r�rhr`rArArBrhpszBufferedRWPair.closedN)r)r)r)rMrNrOrHr*r�r�r�r�rwr�r�rorqrfr5r)r�rhrArArArBr�,s


r�c@sneZdZdZefdd�Zddd�Zdd�Zdd
d�Zddd
�Z	dd�Z
ddd�Zddd�Zdd�Z
dd�Zd	S)r0z�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�|||�dSrQ)rnr2r�r1r�rArArBr�~szBufferedRandom.__init__rc	Cs�|tkrtd��|��|jrJ|j� |j�|jt|j�d�W5QRX|j�||�}|j�|�	�W5QRX|dkr�t
d��|S)Nr�r
rz seek() returned invalid position)r�r#rfr�r�r=r[r�r"r�r.r]rArArBr[�s$zBufferedRandom.seekcCs|jrt�|�St�|�SdSrQ)r�r1rar2r`rArArBra�s
zBufferedRandom.tellNcCs|dkr|��}t�||�SrQ)rar1rbrcrArArBrb�szBufferedRandom.truncatecCs |dkrd}|��t�||�Sr�)rfr2r�r|rArArBr��szBufferedRandom.readcCs|��t�||�SrQ)rfr2r�r�rArArBr��szBufferedRandom.readintocCs|��t�||�SrQ)rfr2rwr|rArArBrw�szBufferedRandom.peekrcCs|��t�||�SrQ)rfr2r�r|rArArBr��szBufferedRandom.read1cCs|��t�||�SrQ)rfr2r�r�rArArBr��szBufferedRandom.readinto1c	CsF|jr:|j�(|j�|jt|j�d�|��W5QRXt�||�Sr)	r�r�r=r[r�r"r�r1r�r�rArArBr��s
zBufferedRandom.write)r)N)N)r)r)rMrNrOrHr*r�r[rarbr�r�rwr�r�r�rArArArBr0us




r0cs�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(rFNTr
c
CsB|jdkr*z|jrt�|j�W5d|_Xt|t�r<td��t|t�r\|}|dkr`td��nd}t|t	�sxtd|f��t
|�t
d�ks�td|f��tdd�|D��d	ks�|�d
�d	kr�td��d|kr�d
|_
d
|_tjtjB}nTd|kr�d
|_d}n@d|k�rd
|_tjtjB}n"d|k�r8d
|_d
|_tjtjB}d
|k�rNd
|_d
|_|j�rj|j�rj|tjO}n|j�r~|tjO}n
|tjO}|ttdd�O}ttdd��p�ttdd�}||O}d}�zT|dk�r:|�s�td��|dk�r�t�||d�}n0|||�}t|t��std��|dk�r$td��|}|�s:t�|d�||_t�|�}	z(t�|	j��rpt t!j"t�#t!j"�|��Wnt$k
�r�YnXt|	dd�|_%|j%d	k�r�t&|_%t'�r�t'|tj(�||_)|j�rzt�*|dt+�Wn4tk
�r}
z|
j!t!j,k�r�W5d}
~
XYnXWn"|dk	�r0t�|��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).
        rrz$integer argument expected, got floatznegative file descriptorzinvalid mode: %szxrwab+css|]}|dkVqdS)ZrwaxNrA)�.0�crArArB�	<genexpr>�sz"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�_closefdrr5r�floatr rr#rr!�sum�count�_created�	_writable�O_EXCL�O_CREAT�	_readable�O_TRUNC�
_appending�O_APPEND�O_RDWR�O_RDONLY�O_WRONLY�getattrrCr.�set_inheritabler+�stat�S_ISDIR�st_mode�IsADirectoryErrorr�ZEISDIRr�r/�_blksizer*�_setmoder�rY�lseekr	ZESPIPE)rIr6r4r;r�fd�flagsZnoinherit_flagZowned_fdZfdfstatr�rArArBr��s�




$




�





�

zFileIO.__init__cCsB|jdkr>|jr>|js>ddl}|jd|ftd|d�|��dS)Nrzunclosed file %rr)�
stacklevel�source)r�r�rhr$r%�ResourceWarningr5)rIr$rArArBrjAs�zFileIO.__del__cCstd|jj�d���dSr�r�r`rArArBr�HszFileIO.__getstate__cCspd|jj|jjf}|jr"d|Sz
|j}Wn*tk
rVd||j|j|jfYSXd|||j|jfSdS)Nz%s.%sz
<%s [closed]>z<%s fd=%d mode=%r closefd=%r>z<%s name=%r mode=%r closefd=%r>)	rXrNrOrhrYr/r�r4r�)rI�
class_namerYrArArBr�Ks�
�
�zFileIO.__repr__cCs|jstd��dS)NzFile not open for reading)r�rVr`rArArBrpYszFileIO._checkReadablecCs|jstd��dS)NzFile not open for writing)r�rVrlrArArBrr]szFileIO._checkWritablecCsT|��|��|dks |dkr(|��Szt�|j|�WStk
rNYdSXdS)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)rerpr�rr�r�r�r|rArArBr�aszFileIO.readcCs�|��|��t}z6t�|jdt�}t�|j�j}||krH||d}Wnt	k
r^YnXt
�}t|�|kr�t|�}|t|t�7}|t|�}zt�
|j|�}Wntk
r�|r�Yq�YdSX|s�q�||7}qft|�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)rerpr*rrr�rr+�st_sizer.r�r"r�r�r�r)rI�bufsizer^�endr>r{r�rArArBr�qs2
zFileIO.readallcCs4t|��d�}|�t|��}t|�}||d|�<|S)zSame as RawIOBase.readinto().r�N)r�r�r�r")rIr�mr�r{rArArBr��s
zFileIO.readintocCs<|��|��zt�|j|�WStk
r6YdSXdS)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)rerrrr�r�r�r�rArArBr��szFileIO.writecCs*t|t�rtd��|��t�|j||�S)a�Move to new file position.

        Argument offset is a byte count.  Optional argument whence defaults to
        SEEK_SET or 0 (offset from start of file, offset should be >= 0); other values
        are SEEK_CUR or 1 (move relative to current position, positive or negative),
        and SEEK_END or 2 (move relative to end of file, usually negative, although
        many platforms allow seeking beyond the end of a file).

        Note that not all file objects are seekable.
        zan integer is required)rr�r rerrr�r]rArArBr[�s
zFileIO.seekcCs|��t�|jdt�S)zYtell() -> int.  Current file position.

        Can raise OSError for non seekable files.r)rerrr�rr`rArArBra�szFileIO.tellcCs2|��|��|dkr |��}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)rerrrar�	ftruncater�r|rArArBrb�szFileIO.truncatecs.|js*z|jrt�|j�W5t���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)rhr�r5r�rr�r`r�rArBr5�s
zFileIO.closecCsF|��|jdkr@z|��Wntk
r8d|_YnXd|_|jS)z$True if file supports random-access.NFT)re�	_seekablerar.r`rArArBrk�s
zFileIO.seekablecCs|��|jS)z'True if file was opened in a read mode.)rer�r`rArArBro�szFileIO.readablecCs|��|jS)z(True if file was opened in a write mode.)rer�r`rArArBrq�szFileIO.writablecCs|��|jS)z3Return the underlying file descriptor (an integer).)rer�r`rArArBr,�sz
FileIO.filenocCs|��t�|j�S)z.True if the file is connected to a TTY device.)rerr)r�r`rArArBr)�sz
FileIO.isattycCs|jS)z6True if the file descriptor will be closed by close().)r�r`rArArBr;�szFileIO.closefdcCsJ|jr|jrdSdSn0|jr,|jr&dSdSn|jrB|jr<dSdSndSdS)	zString giving the file modezxb+Zxbzab+Zabzrb+rD�wbN)r�r�r�r�r`rArArBr4szFileIO.mode)r
TN)N)N)N)"rMrNrOr�r�r�r�r�rr�r�rjr�r�rprrr�r�r�r�rr[rarbr5rkrorqr,r)r�r;r4r�rArAr�rBr(�s<
y

#



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 public constructor.
    rcCs|�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|rArArBr�szTextIOBase.readcCs|�d�dS)z.Write string s to stream and returning an int.r�Nr\)rI�srArArBr�(szTextIOBase.writeNcCs|�d�dS)z*Truncate size to pos, where pos is an int.rbNr\rcrArArBrb,szTextIOBase.truncatecCs|�d�dS)z_Read until newline or EOF.

        Returns an empty string if EOF is hit immediately.
        r�Nr\r`rArArBr�0szTextIOBase.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`rArArBr�7szTextIOBase.detachcCsdS)zSubclasses should override.NrAr`rArArBr8@szTextIOBase.encodingcCsdS)z�Line endings translated so far.

        Only line endings translated during reading are considered.

        Subclasses should override.
        NrAr`rArArB�newlinesEszTextIOBase.newlinescCsdS)zMError setting of the decoder or encoder.

        Subclasses should override.NrAr`rArArBr9OszTextIOBase.errors)r)N)
rMrNrOrHr�r�rbr�r�r�r8rr9rArArArBrs


	

	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)r9rF)�codecs�IncrementalDecoderr��	translate�decoder�seennl�	pendingcr)rIrrr9rArArBr�`s
z"IncrementalNewlineDecoder.__init__FcCs�|jdkr|}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�
FrT�
�
)r�decoderr�r�r�_LF�_CR�_CRLFr�replace)rI�inputr�outputZcrlfZcrZlfrArArBr#gs*

�z IncrementalNewlineDecoder.decodecCs@|jdkrd}d}n|j��\}}|dK}|jr8|dO}||fS)Nr�rr
)r�getstater)rIr��flagrArArBr*�s
z"IncrementalNewlineDecoder.getstatecCs8|\}}t|d@�|_|jdk	r4|j�||d?f�dSr)�boolrr�setstate)rI�stater�r+rArArBr-�s
z"IncrementalNewlineDecoder.setstatecCs$d|_d|_|jdk	r |j��dS)NrF)rrr�resetr`rArArBr/�s
zIncrementalNewlineDecoder.resetr
r�cCs
d|jS)N)Nr"r )r r"r!)r"r!)r r!)r r"r!)rr`rArArBr�s�z"IncrementalNewlineDecoder.newlinesN)r)F)rMrNrOrHr�r#r*r-r/r$r%r&r�rrArArArBrYs

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)Wr3aCharacter and line based layer over a BufferedIOBase object, buffer.

    encoding gives the name of the encoding that the stream will be
    decoded or encoded with. It defaults to locale.getpreferredencoding(False).

    errors determines the strictness of encoding and decoding (see the
    codecs.register) and defaults to "strict".

    newline can be None, '', '\n', '\r', or '\r\n'.  It controls the
    handling of line endings. If it is None, universal newlines is
    enabled.  With this enabled, on input, the lines endings '\n', '\r',
    or '\r\n' are translated to '\n' before being returned to the
    caller. Conversely, on output, '\n' is translated to the system
    default line separator, os.linesep. If newline is any other of its
    legal values, that newline becomes the newline when the file is read
    and it is returned untranslated. On output, '\n' is converted to the
    newline.

    If line_buffering is True, a call to flush is implied when a call to
    write contains a newline character.
    iNFc		Cs|�|�|dkrvzt�|���}Wnttfk
r<YnX|dkrvzddl}Wntk
rjd}YnX|�d�}t	|t
�s�td|��t�
|�js�d}t||��|dkr�d}nt	|t
�s�td|��||_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/rV�locale�ImportErrorZgetpreferredencodingrrr#r�lookup�_is_text_encoding�LookupErrorr��_decoded_chars�_decoded_chars_used�	_snapshotr@rkr�_tellingr��
_has_read1�
_configure)	rIr@r8r9r:r?�
write_throughr4rmrArArBr��s>





�zTextIOWrapper.__init__cCs>|dk	r$t|t�s$tdt|�f��|dkr:td|f��dS)Nzillegal newline type: %r)Nrr"r r!zillegal newline value: %r)rrr �typer#)rIr:rArArBr2�szTextIOWrapper._check_newlinecCs�||_||_d|_d|_d|_||_|dk|_||_|dk|_|pHt	j
|_||_||_
|jr�|��r�|j��}|dkr�z|���d�Wntk
r�YnXdS)N�rr)�	_encoding�_errors�_encoder�_decoder�	_b2cratio�_readuniversal�_readtranslate�_readnl�_writetranslater�linesep�_writenl�_line_buffering�_write_throughrrqr@ra�_get_encoderr-r8)rIr8r9r:r?r?�positionrArArBr>�s&


zTextIOWrapper._configurecCs�d�|jj|jj�}z
|j}Wntk
r2YnX|d�|�7}z
|j}Wntk
r`YnX|d�|�7}|d�|j�S)Nz<{}.{}z name={0!r}z mode={0!r}z encoding={0!r}>)r�rXrNrOrYr/r4r8)rIr>rYr4rArArBr�!s
�

zTextIOWrapper.__repr__cCs|jSrQ)rBr`rArArBr82szTextIOWrapper.encodingcCs|jSrQ)rCr`rArArBr96szTextIOWrapper.errorscCs|jSrQ)rMr`rArArBr?:szTextIOWrapper.line_bufferingcCs|jSrQ)rNr`rArArBr?>szTextIOWrapper.write_throughcCs|jSrQ)r�r`rArArBr@BszTextIOWrapper.buffer)r8r9r:r?r?cCs�|jdk	r*|dk	s"|dk	s"|tk	r*td��|dkrH|dkrB|j}q^d}nt|t�s^td|��|dkrn|j}nt|t�s�td|��|tkr�|j}|�	|�|dkr�|j
}|dkr�|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)rE�EllipsisrVrCrrr rBrIr2r?r?rfr>)rIr8r9r:r?r?rArArB�reconfigureFs@
����



�zTextIOWrapper.reconfigurecCs|jrtd��|jS)Nrs)rhr#rr`rArArBrkoszTextIOWrapper.seekablecCs
|j��SrQ)r@ror`rArArBrotszTextIOWrapper.readablecCs
|j��SrQ)r@rqr`rArArBrqwszTextIOWrapper.writablecCs|j��|j|_dSrQ)r@rfrr<r`rArArBrfzs
zTextIOWrapper.flushcCs.|jdk	r*|js*z|��W5|j��XdSrQ)r@rhr5rfr`rArArBr5~szTextIOWrapper.closecCs|jjSrQ)r@rhr`rArArBrh�szTextIOWrapper.closedcCs|jjSrQ)r@rYr`rArArBrY�szTextIOWrapper.namecCs
|j��SrQ)r@r,r`rArArBr,�szTextIOWrapper.filenocCs
|j��SrQ)r@r)r`rArArBr)�szTextIOWrapper.isattycCs�|jrtd��t|t�s(td|jj��t|�}|js<|j	oBd|k}|rf|jrf|j
dkrf|�d|j
�}|jpr|�
�}|�|�}|j�|�|j	r�|s�d|kr�|��|�d�d|_|jr�|j��|S)zWrite data, where s is a strr�zcan't write %s to text streamr"r rN)rhr#rrr rXrMr"rJrMrLr'rDrO�encoder@r�rf�_set_decoded_charsr;rEr/)rIrZlengthZhaslf�encoderrrArArBr��s(
�


zTextIOWrapper.writecCst�|j�}||j�|_|jSrQ)r�getincrementalencoderrBrCrD)rIZmake_encoderrArArBrO�szTextIOWrapper._get_encodercCs2t�|j�}||j�}|jr(t||j�}||_|SrQ)r�getincrementaldecoderrBrCrGrrHrE)rIZmake_decoderrrArArB�_get_decoder�s
zTextIOWrapper._get_decodercCs||_d|_dS)zSet the _decoded_chars buffer.rN)r9r:)rI�charsrArArBrT�sz TextIOWrapper._set_decoded_charscCsF|j}|dkr|j|d�}n|j|||�}|jt|�7_|S)z'Advance into the _decoded_chars buffer.N)r:r9r")rIr{�offsetrYrArArB�_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�rArArB�_rewind_decoded_chars�s
z#TextIOWrapper._rewind_decoded_charscCs�|jdkrtd��|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 decoderrA)rEr#r<r*r=r@r��_CHUNK_SIZEr�r#rTr"r9rFr;)rI�
dec_buffer�	dec_flags�input_chunk�eofZ
decoded_charsrArArB�_read_chunk�s 

zTextIOWrapper._read_chunkrcCs(||d>B|d>B|d>Bt|�d>BS)N�@���)r,)rIrPr`�
bytes_to_feed�need_eof�
chars_to_skiprArArB�_pack_cookie�s
�
�zTextIOWrapper._pack_cookiecCsFt|d�\}}t|d�\}}t|d�\}}t|d�\}}|||||fS)Nl)�divmod)rIZbigint�restrPr`rhrirjrArArB�_unpack_cookie	s
zTextIOWrapper._unpack_cookiec	CsR|jstd��|jstd��|��|j��}|j}|dksF|jdkrX|j	rTt
d��|S|j\}}|t|�8}|j}|dkr�|�
||�S|��}�z�t|j|�}d}|t|�ks�t
�|dk�r4|�d|f�t|�|d|���}	|	|k�r"|��\}
}|
�s|}||	8}�qF|t|
�8}d}q�||8}|d}q�d}|�d|f�||}|}
|dk�rl|�
||
�W��Sd}d}d}t|t|��D]x}|d7}|t|�|||d���7}|��\}}|�s�||k�r�||7}||8}|dd}
}}||k�r��q,�q�|t|jddd	��7}d}||k�r,td
��|�
||
|||�W�S|�|�XdS)N�!underlying stream is not seekablez(telling position disabled by next() callzpending decoded textrr
r�rTrz'can't reconstruct logical file position)rrVr<r.rfr@rarEr;r9r\r"r:rkr*r-rrFr#�range)rIrPrr`Z
next_inputrjZsaved_stateZ
skip_bytesZ	skip_backr{r�d�	start_posZstart_flagsZ	bytes_fedriZ
chars_decoded�ir_rArArBra
	s�








�zTextIOWrapper.tellcCs$|��|dkr|��}|j�|�SrQ)rfrar@rbrcrArArBrbm	szTextIOWrapper.truncatecCs*|jdkrtd��|��|j}d|_|S)Nzbuffer is already detached)r@r#rfr�)rIr@rArArBr�s	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)
NcsHz�jp���}Wntk
r&YnX|dkr<|�d�n|��dS)z9Reset the encoder (merely useful for proper BOM handling)rN)rDrOr8r-r/)rPrUr`rArB�_reset_encoder|	sz*TextIOWrapper.seek.<locals>._reset_encoderr�rorz#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)rhr#rrVrrar	rfr@r[rTr;rEr/rnrXr-r�r#r"r9r.r:)rIZcookier_rtrPrrr`rhrirjrarAr`rBr[{	s`



�

�
zTextIOWrapper.seekcCs�|��|dkrd}n4z
|j}Wn"tk
rBt|�d���YnX|�}|jpV|��}|dkr�|��|j|j�	�dd�}|�
d�d|_|Sd}|�|�}t|�|kr�|s�|�
�}||�|t|��7}q�|SdS)Nrr�rTrrF)rpr�r/r rErXr[r#r@r�rTr;r"rc)rIr}r�rr>rbrArArBr��	s,
�


zTextIOWrapper.readcCs(d|_|��}|s$d|_|j|_t�|S)NF)r<r�r;rr�r�rArArBr��	szTextIOWrapper.__next__c	Cs
|jrtd��|dkrd}n4z
|j}Wn"tk
rHt|�d���YnX|�}|��}d}|jsj|��d}}|jr�|�	d|�}|dkr�|d}�q�nt
|�}n�|j�rF|�	d|�}|�	d|�}|dkr�|dkr�t
|�}n|d}�q�nX|dk�r|d}�q�n@||k�r|d}�q�n(||dk�r8|d}�q�n|d}�q�n(|�	|j�}|dk�rn|t
|j�}�q�|dk�r�t
|�|k�r�|}�q�|�
��r�|j�r��q��q�|j�r�||��7}qr|�d	�d|_|Sqr|dk�r�||k�r�|}|�t
|�|�|d|�S)
Nr�rr�rr"r
r rr)rhr#r�r/r r[rErXrHryr"rGrIrcr9rTr;r])	rIr}r�r��startr^�endposZnlposZcrposrArArBr��	st







zTextIOWrapper.readlinecCs|jr|jjSdSrQ)rErr`rArArBrH
szTextIOWrapper.newlines)NNNFF)NNNFF)N)rrrr)N)r)N)N),rMrNrOrHr^r�r�r2r>r�r�r8r9r?r?r@rQrRrkrorqrfr5rhrYr,r)r�rOrXrTr[r]rcrkrnrarbr�r[r�r�r�rrArArArBr3�s|�
(�
$




�)



*�

c

K
	
]r3csReZdZdZd�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�sNtd�t	|�j
���|�|�|�d�dS)Nzutf-8�
surrogatepass)r8r9r:Fz*initial_value must be str or None, not {0}r)
r�rwr�r�rJrrr r�r@rMr�r[)rIZ
initial_valuer:r�rArBr�T
s�
�
zStringIO.__init__c	CsP|��|jp|��}|��}|��z|j|j��dd�W�S|�|�XdS)NTr)	rfrErXr*r/r-r#r@r�)rIrZ	old_staterArArBr�d
szStringIO.getvaluecCs
t�|�SrQ)�objectr�r`rArArBr�n
szStringIO.__repr__cCsdSrQrAr`rArArBr9s
szStringIO.errorscCsdSrQrAr`rArArBr8w
szStringIO.encodingcCs|�d�dS)Nr�r\r`rArArBr�{
szStringIO.detach)rr")rMrNrOrHr�r�r�r�r9r8r�r�rArAr�rBrwM
s


rw)r
rNNNTN)8rHr�abcrr�r��sys�_threadrr��platformZmsvcrtrr�iorrrr	r�r��addr�	SEEK_DATAr*r�r�dev_moderirCrF�	open_coder/rGrPrVr.r#�ABCMetarW�registerr��_ior(r�r�r�r2r1r�r0rrrr3rwrArArArB�<module>s�


�
[

	
$=
ghCiIJY@U$

Zerion Mini Shell 1.0