eaiovnaovbqoebvqoeavibavo B  fe@s<dZddlZddlZddlZddlZddlZddlZddlmZ ej dkrXddl m Z ndZ ddlZddlmZmZmZmZdddhZeed reejeejd ZeZd4ddZGdddZGdddZy ejZWn(ek rGdddee ZYnXGdddej!dZ"ej"#e"Gddde"Z$ej$#e$ddl%m&Z&e$#e&Gddde"Z'ej'#e'Gddde'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"Z.ej.#e.Gd.d/d/ej/Z0Gd0d1d1e.Z1Gd2d3d3e1Z2dS)5z) Python implementation of the io module. N) allocate_lock>win32cygwin)setmode)__all__SEEK_SETSEEK_CURSEEK_END SEEK_HOLEi rTc Cszt|tst|}t|tttfs0td|t|tsFtd|t|ts\td||dk rzt|tsztd||dk rt|tstd|t|}|tdst|t|krt d|d|k} d |k} d |k} d |k} d |k} d |k}d|k}d|krD| s"| s"| s"| r*t dddl }| dt dd} |rX|rXt d| | | | dkrvt d| s| s| s| st d|r|dk rt d|r|dk rt d|r|dk rt dt || rdpd| rd pd| r d pd| rd pd| r,d p.d||d}|}yd}|dksd|dkrl|rld}d}|dkrt}yt|j}Wnttfk rYnX|dkr|}|dkrt d |dkr|r|St d!| rt||}n<| s | s | rt||}n| r(t||}n t d"||}|rB|St|||||}|}||_|S|YnXdS)#aOpen 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+tUxr wa+tbUz4mode U cannot be combined with 'x', 'w', 'a', or '+'rz'U' mode is deprecatedr Tz'can't have text and binary mode at oncer z)can't have read/write/append mode at oncez/must have exactly one of read/write/append modez-binary mode doesn't take an encoding argumentz+binary mode doesn't take an errors argumentz+binary mode doesn't take a newline argument)openerFrzinvalid buffering sizezcan't have unbuffered text I/Ozunknown mode: %r) isinstanceintosfspathstrbytes TypeErrorsetlen ValueErrorwarningswarnDeprecationWarningFileIOisattyDEFAULT_BUFFER_SIZEfstatfileno st_blksizeOSErrorAttributeErrorBufferedRandomBufferedWriterBufferedReader TextIOWrappermodeclose)filer1 bufferingencodingerrorsnewlineclosefdrZmodesZcreatingZreadingZwritingZ appendingZupdatingtextZbinaryr"rawresultline_bufferingZbsbufferr>*/opt/alt/python37/lib64/python3.7/_pyio.pyopen%s{            >         r@c@seZdZdZddZdS) DocDescriptorz%Helper for builtins.open.__doc__ cCs dtjS)Nz\open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True) )r@__doc__)selfobjtypr>r>r?__get__szDocDescriptor.__get__N)__name__ __module__ __qualname__rBrFr>r>r>r?rAsrAc@seZdZdZeZddZdS) OpenWrapperzWrapper 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)r@)clsargskwargsr>r>r?__new__ szOpenWrapper.__new__N)rGrHrIrBrArNr>r>r>r?rJsrJc@s eZdZdS)UnsupportedOperationN)rGrHrIr>r>r>r?rOsrOc@seZdZdZddZd6ddZddZd7d d Zd d ZdZ ddZ ddZ ddZ d8ddZ ddZd9ddZddZd:ddZedd Zd;d!d"Zd#d$Zd%d&Zd'd(Zd)d*ZdIOBaseaThe 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|fdS)z@Internal: raise an OSError exception for unsupported operations.z%s.%s() not supportedN)rO __class__rG)rCnamer>r>r? _unsupported<szIOBase._unsupportedrcCs|ddS)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)rS)rCposwhencer>r>r?rTCsz IOBase.seekcCs |ddS)z5Return an int indicating the current stream position.rr )rT)rCr>r>r?tellSsz IOBase.tellNcCs|ddS)zTruncate file to size bytes. Size defaults to the current IO position as reported by tell(). Return the new size. truncateN)rS)rCrUr>r>r?rXWszIOBase.truncatecCs |dS)zuFlush write buffers, if applicable. This is not implemented for read-only and non-blocking streams. N) _checkClosed)rCr>r>r?flushasz IOBase.flushFcCs |jsz |Wdd|_XdS)ziFlush and close the IO object. This method has no effect if the file is already closed. NT)_IOBase__closedrZ)rCr>r>r?r2ks z IOBase.closecCsy |Wn YnXdS)zDestructor. Calls close().N)r2)rCr>r>r?__del__vs zIOBase.__del__cCsdS)zReturn 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>)rCr>r>r?seekableszIOBase.seekablecCs |st|dkrdn|dS)zEInternal: raise UnsupportedOperation if file is not seekable NzFile or stream is not seekable.)r]rO)rCmsgr>r>r?_checkSeekableszIOBase._checkSeekablecCsdS)zvReturn a bool indicating whether object was opened for reading. If False, read() will raise OSError. Fr>)rCr>r>r?readableszIOBase.readablecCs |st|dkrdn|dS)zEInternal: raise UnsupportedOperation if file is not readable NzFile or stream is not readable.)r`rO)rCr^r>r>r?_checkReadableszIOBase._checkReadablecCsdS)zReturn a bool indicating whether object was opened for writing. If False, write() and truncate() will raise OSError. Fr>)rCr>r>r?writableszIOBase.writablecCs |st|dkrdn|dS)zEInternal: raise UnsupportedOperation if file is not writable NzFile or stream is not writable.)rbrO)rCr^r>r>r?_checkWritableszIOBase._checkWritablecCs|jS)zclosed: bool. True iff the file has been closed. For backwards compatibility, this is a property, not a predicate. )r[)rCr>r>r?closedsz IOBase.closedcCs|jrt|dkrdn|dS)z7Internal: raise a ValueError if file is closed NzI/O operation on closed file.)rdr!)rCr^r>r>r?rYszIOBase._checkClosedcCs ||S)zCContext management protocol. Returns self (an instance of IOBase).)rY)rCr>r>r? __enter__szIOBase.__enter__cGs |dS)z+Context management protocol. Calls close()N)r2)rCrLr>r>r?__exit__szIOBase.__exit__cCs|ddS)zReturns underlying file descriptor (an int) if one exists. An OSError is raised if the IO object does not use a file descriptor. r)N)rS)rCr>r>r?r)sz IOBase.filenocCs |dS)z{Return a bool indicating whether this is an 'interactive' stream. Return False if it can't be determined. F)rY)rCr>r>r?r&sz IOBase.isattyrcstdrfdd}ndd}dkr0dn4y j}Wn"tk r\tdYnX|t}x>dkst|kr|}|sP||7}|d rlPqlWt|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|ddp&t|}dkr:t|}|S)Nr  r)rgfindr min)Z readaheadn)rCsizer>r? nreadaheads  z#IOBase.readline..nreadaheadcSsdS)Nr r>r>r>r>r?rmsNrz is not an integerrrh) hasattr __index__r,r bytearrayr readendswithr)rCrlrm size_indexresrr>)rCrlr?readlines&     zIOBase.readlinecCs ||S)N)rY)rCr>r>r?__iter__szIOBase.__iter__cCs|}|st|S)N)ru StopIteration)rCliner>r>r?__next__ szIOBase.__next__cCsR|dks|dkrt|Sd}g}x,|D]$}|||t|7}||kr&Pq&W|S)zReturn 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)listappendr )rCZhintrklinesrxr>r>r? readliness   zIOBase.readlinescCs$|x|D]}||qWdS)zWrite 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)rYwrite)rCr|rxr>r>r? writelines$s zIOBase.writelines)r)N)N)N)N)N)r)N)rGrHrIrBrSrTrWrXrZr[r2r\r]r_r`rarbrcpropertyrdrYrerfr)r&rurvryr}rr>r>r>r?rPs4         * rP) metaclassc@s2eZdZdZd ddZddZddZd d Zd S) RawIOBasezBase class for raw binary I/O.rcCsP|dkr d}|dkr|St|}||}|dkr>dS||d=t|S)zRead 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)readallrproreadintor)rCrlrrkr>r>r?rq?s   zRawIOBase.readcCs8t}x|t}|sP||7}qW|r0t|S|SdS)z+Read until EOF, using multiple read() call.N)rprqr'r)rCrtdatar>r>r?rPs  zRawIOBase.readallcCs|ddS)zRead 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. rN)rS)rCrr>r>r?r^szRawIOBase.readintocCs|ddS)zWrite 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)rS)rCrr>r>r?r~fszRawIOBase.writeN)r)rGrHrIrBrqrrr~r>r>r>r?r1s  r)r%c@sLeZdZdZdddZdddZddZd d Zd d Zd dZ ddZ 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|ddS)aRead 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)rS)rCrlr>r>r?rqszBufferedIOBase.readcCs|ddS)zaRead up to size bytes with at most one read() system call, where size is an int. read1N)rS)rCrlr>r>r?rszBufferedIOBase.read1cCs|j|ddS)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)rCrr>r>r?rs zBufferedIOBase.readintocCs|j|ddS)zRead 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)rCrr>r>r? readinto1s zBufferedIOBase.readinto1cCsVt|tst|}|d}|r0|t|}n|t|}t|}||d|<|S)NB)r memoryviewcastrr rq)rCrrrrkr>r>r?rs   zBufferedIOBase._readintocCs|ddS)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)rS)rCrr>r>r?r~s zBufferedIOBase.writecCs|ddS)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)rS)rCr>r>r?rszBufferedIOBase.detachN)r)r) rGrHrIrBrqrrrrr~rr>r>r>r?rss    rc@seZdZdZddZd$ddZddZd%d d Zd d ZddZ ddZ ddZ e ddZ e ddZe ddZe ddZddZddZd d!Zd"d#Zd S)&_BufferedIOMixinzA 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)rCr:r>r>r?__init__sz_BufferedIOMixin.__init__rcCs"|j||}|dkrtd|S)Nrz#seek() returned an invalid position)r:rTr+)rCrUrVZ new_positionr>r>r?rTsz_BufferedIOMixin.seekcCs|j}|dkrtd|S)Nrz#tell() returned an invalid position)r:rWr+)rCrUr>r>r?rWs z_BufferedIOMixin.tellNcCs$||dkr|}|j|S)N)rZrWr:rX)rCrUr>r>r?rXsz_BufferedIOMixin.truncatecCs|jrtd|jdS)Nzflush on closed file)rdr!r:rZ)rCr>r>r?rZsz_BufferedIOMixin.flushcCs.|jdk r*|js*z |Wd|jXdS)N)r:rdrZr2)rCr>r>r?r2 s z_BufferedIOMixin.closecCs*|jdkrtd||j}d|_|S)Nzraw stream already detached)r:r!rZr)rCr:r>r>r?rs  z_BufferedIOMixin.detachcCs |jS)N)r:r])rCr>r>r?r]sz_BufferedIOMixin.seekablecCs|jS)N)r)rCr>r>r?r:sz_BufferedIOMixin.rawcCs|jjS)N)r:rd)rCr>r>r?rd#sz_BufferedIOMixin.closedcCs|jjS)N)r:rR)rCr>r>r?rR'sz_BufferedIOMixin.namecCs|jjS)N)r:r1)rCr>r>r?r1+sz_BufferedIOMixin.modecCstd|jjdS)Nz can not serialize a '{0}' object)rformatrQrG)rCr>r>r? __getstate__/sz_BufferedIOMixin.__getstate__cCsJ|jj}|jj}y |j}Wntk r6d||SXd|||SdS)Nz<{}.{}>z<{}.{} name={!r}>)rQrHrIrR Exceptionr)rCmodnameZclsnamerRr>r>r?__repr__3s z_BufferedIOMixin.__repr__cCs |jS)N)r:r))rCr>r>r?r)?sz_BufferedIOMixin.filenocCs |jS)N)r:r&)rCr>r>r?r&Bsz_BufferedIOMixin.isatty)r)N)rGrHrIrBrrTrWrXrZr2rr]rr:rdrRr1rrr)r&r>r>r>r?rs"        rcseZdZdZdZd!ddZddZddZd d Zfd d Z d"ddZ d#ddZ ddZ d$ddZ ddZd%ddZddZddZdd ZZS)&BytesIOzr>r?rNs zBytesIO.__init__cCs|jrtd|jS)Nz__getstate__ on closed file)rdr!__dict__copy)rCr>r>r?rUszBytesIO.__getstate__cCs|jrtdt|jS)z8Return the bytes value (contents) of the buffer zgetvalue on closed file)rdr!rr)rCr>r>r?getvalueZszBytesIO.getvaluecCs|jrtdt|jS)z;Return a readable and writable view of the buffer. zgetbuffer on closed file)rdr!rr)rCr>r>r? getbufferaszBytesIO.getbuffercs"|jdk r|jtdS)N)rclearsuperr2)rC)rQr>r?r2hs  z BytesIO.closercCs|jrtd|dkrd}n4y |j}Wn"tk rHt|dYnX|}|dkrbt|j}t|j|jkrvdStt|j|j|}|j|j|}||_t |S)Nzread from closed filerz is not an integerr) rdr!ror,rr rrrjr)rCrlrsZnewposrr>r>r?rqms"  z BytesIO.readcCs ||S)z"This is the same as read. )rq)rCrlr>r>r?rsz BytesIO.read1c Cs|jrtdt|tr tdt| }|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) rdr!rrrrnbytesrr r)rCrZviewrkrUZpaddingr>r>r?r~s  z BytesIO.writercCs|jrtdy |j}Wn"tk r:t|dYnX|}|dkrh|dkr`td|f||_nD|dkrtd|j||_n(|dkrtdt|j||_ntd|jS)Nzseek on closed filez is not an integerrznegative seek position %rr r zunsupported whence value) rdr!ror,rrmaxr r)rCrUrV pos_indexr>r>r?rTs" z BytesIO.seekcCs|jrtd|jS)Nztell on closed file)rdr!r)rCr>r>r?rWsz BytesIO.tellcCsx|jrtd|dkr|j}nJy |j}Wn"tk rJt|dYnX|}|dkrhtd|f|j|d=|S)Nztruncate on closed filez is not an integerrznegative truncate position %r)rdr!rror,rr)rCrUrr>r>r?rXs  zBytesIO.truncatecCs|jrtddS)NzI/O operation on closed file.T)rdr!)rCr>r>r?r`szBytesIO.readablecCs|jrtddS)NzI/O operation on closed file.T)rdr!)rCr>r>r?rbszBytesIO.writablecCs|jrtddS)NzI/O operation on closed file.T)rdr!)rCr>r>r?r]szBytesIO.seekable)N)r)r)r)N)rGrHrIrBrrrrrr2rqrr~rTrWrXr`rbr] __classcell__r>r>)rQr?rFs       rc@sxeZdZdZefddZddZddZdd d Zdd d Z dddZ dddZ dddZ ddZ ddZd ddZdS)!r/aBufferedReader(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|stdt|||dkr,td||_|t|_dS)zMCreate a new buffered reader using the given readable raw IO object. z "raw" argument must be readable.rzinvalid buffer sizeN) r`r+rrr! buffer_size_reset_read_bufLock _read_lock)rCr:rr>r>r?rs zBufferedReader.__init__cCs |jS)N)r:r`)rCr>r>r?r`szBufferedReader.readablecCsd|_d|_dS)Nrr) _read_buf _read_pos)rCr>r>r?rszBufferedReader._reset_read_bufNc Cs4|dk r|dkrtd|j ||SQRXdS)zRead 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_unlocked)rCrlr>r>r?rqszBufferedReader.readc Csd}d}|j}|j}|dks$|dkr|t|jdrj|j}|dkrZ||dpXdS||d|S||dg}d}x2|j}||kr|}P|t|7}||q~Wd |p|St||} || kr|j|7_||||S||dg}t |j |} xB| |krL|j| }||kr2|}P| t|7} ||q Wt || }d |} | |d|_d|_| r| d|S|S)Nr)rNrrr) rrrrnr:rrqr r{joinrrrj) rCrkZ nodata_valZ empty_valuesrrUchunkZchunksZ current_sizeavailZwantedoutr>r>r?rsN            zBufferedReader._read_unlockedrc Cs|j ||SQRXdS)zReturns 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)rCrlr>r>r?rg5szBufferedReader.peekcCsrt||j}t|j|j}||ks,|dkrb|j|}|j|}|rb|j|jd||_d|_|j|jdS)Nr)rjrr rrr:rq)rCrkZwantZhaveZto_readZcurrentr>r>r?r?s   zBufferedReader._peek_unlockedrc CsR|dkr|j}|dkrdS|j(|d|t|t|j|jSQRXdS)zr>r?rJs zBufferedReader.read1c Cst|tst|}|jdkr dS|d}d}|jx|t|krtt|j|jt|}|r|j|j|j|||||<|j|7_||7}|t|krPt|||j kr|j ||d}|sP||7}n|r|s| dsP|r8|r8Pq8WWdQRX|S)z2Read data into *buf* with at most one system call.rrNr ) rrrrrr rjrrrr:rr)rCrrwrittenrrkr>r>r?r\s4   "   zBufferedReader._readintocCst|t|j|jS)N)rrWr rr)rCr>r>r?rWszBufferedReader.tellc CsX|tkrtd|j8|dkr4|t|j|j8}t|||}||SQRXdS)Nzinvalid whence valuer ) valid_seek_flagsr!rr rrrrTr)rCrUrVr>r>r?rTszBufferedReader.seek)N)N)r)r)r)r)rGrHrIrBr'rr`rrqrrgrrrrWrTr>r>r>r?r/s   4 .r/c@s`eZdZdZefddZddZddZdd d Zd d Z d dZ ddZ dddZ ddZ dS)r.zA 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|stdt|||dkr,td||_t|_t|_ dS)Nz "raw" argument must be writable.rzinvalid buffer size) rbr+rrr!rrp _write_bufr _write_lock)rCr:rr>r>r?rs zBufferedWriter.__init__cCs |jS)N)r:rb)rCr>r>r?rbszBufferedWriter.writablec Cst|trtd|j|jr(tdt|j|jkr@| t|j}|j |t|j|}t|j|jkry | Wnlt k r}zNt|j|jkrt|j|j}||8}|jd|j|_t |j |j |Wdd}~XYnX|SQRXdS)Nz can't write str to binary streamzwrite to closed file)rrrrrdr!r rr_flush_unlockedextendBlockingIOErrorerrnostrerror)rCrZbeforereZoverager>r>r?r~s(    "zBufferedWriter.writeNc Cs8|j(||dkr"|j}|j|SQRXdS)N)rrr:rWrX)rCrUr>r>r?rXs  zBufferedWriter.truncatec Cs|j|WdQRXdS)N)rr)rCr>r>r?rZszBufferedWriter.flushcCs|jrtdxz|jry|j|j}Wntk rDtdYnX|dkr\ttjdd|t |jksr|dkrzt d|jd|=qWdS)Nzflush on closed filezHself.raw should implement RawIOBase: it should not raise BlockingIOErrorz)write could not complete without blockingrz*write() returned incorrect number of bytes) rdr!rr:r~r RuntimeErrorrZEAGAINr r+)rCrkr>r>r?rszBufferedWriter._flush_unlockedcCst|t|jS)N)rrWr r)rCr>r>r?rWszBufferedWriter.tellrc Cs8|tkrtd|j|t|||SQRXdS)Nzinvalid whence value)rr!rrrrT)rCrUrVr>r>r?rTs zBufferedWriter.seekcCsV|j|jdks|jrdSWdQRXz |Wd|j|jWdQRXXdS)N)rr:rdrZr2)rCr>r>r?r2s zBufferedWriter.close)N)r)rGrHrIrBr'rrbr~rXrZrrWrTr2r>r>r>r?r.s   r.c@seZdZdZefddZdddZddZd d Zd d d Z d!ddZ ddZ ddZ ddZ ddZddZddZeddZdS)"BufferedRWPairaA 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 tdt|||_t|||_dS)zEConstructor. The arguments are two RawIO instances. z#"reader" argument must be readable.z#"writer" argument must be writable.N)r`r+rbr/readerr.writer)rCrrrr>r>r?rs  zBufferedRWPair.__init__rcCs|dkr d}|j|S)Nr)rrq)rCrlr>r>r?rqszBufferedRWPair.readcCs |j|S)N)rr)rCrr>r>r?r#szBufferedRWPair.readintocCs |j|S)N)rr~)rCrr>r>r?r~&szBufferedRWPair.writercCs |j|S)N)rrg)rCrlr>r>r?rg)szBufferedRWPair.peekcCs |j|S)N)rr)rCrlr>r>r?r,szBufferedRWPair.read1cCs |j|S)N)rr)rCrr>r>r?r/szBufferedRWPair.readinto1cCs |jS)N)rr`)rCr>r>r?r`2szBufferedRWPair.readablecCs |jS)N)rrb)rCr>r>r?rb5szBufferedRWPair.writablecCs |jS)N)rrZ)rCr>r>r?rZ8szBufferedRWPair.flushcCs z|jWd|jXdS)N)rr2r)rCr>r>r?r2;szBufferedRWPair.closecCs|jp|jS)N)rr&r)rCr>r>r?r&AszBufferedRWPair.isattycCs|jjS)N)rrd)rCr>r>r?rdDszBufferedRWPair.closedN)r)r)r)rGrHrIrBr'rrqrr~rgrrr`rbrZr2r&rrdr>r>r>r?rs     rc@sneZdZdZefddZdddZddZdd d Zdd d Z ddZ dddZ dddZ ddZ ddZd S)r-zA 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|||dS)N)r_r/rr.)rCr:rr>r>r?rRszBufferedRandom.__init__rc Cs|tkrtd||jrJ|j |j|jt|jdWdQRX|j||}|j| WdQRX|dkrt d|S)Nzinvalid whence valuer rz seek() returned invalid position) rr!rZrrr:rTrr rr+)rCrUrVr>r>r?rTWs$zBufferedRandom.seekcCs|jrt|St|SdS)N)rr.rWr/)rCr>r>r?rWhs zBufferedRandom.tellNcCs|dkr|}t||S)N)rWr.rX)rCrUr>r>r?rXnszBufferedRandom.truncatecCs |dkr d}|t||S)Nr)rZr/rq)rCrlr>r>r?rqtszBufferedRandom.readcCs|t||S)N)rZr/r)rCrr>r>r?rzszBufferedRandom.readintocCs|t||S)N)rZr/rg)rCrlr>r>r?rg~szBufferedRandom.peekrcCs|t||S)N)rZr/r)rCrlr>r>r?rszBufferedRandom.read1cCs|t||S)N)rZr/r)rCrr>r>r?rszBufferedRandom.readinto1c CsF|jr:|j(|j|jt|jd|WdQRXt||S)Nr ) rrr:rTrr rr.r~)rCrr>r>r?r~s zBufferedRandom.write)r)N)N)r)r)rGrHrIrBr'rrTrWrXrqrrgrrr~r>r>r>r?r-Is      r-cseZdZdZdZdZdZdZdZdZ d0ddZ dd Z d d Z d d Z ddZd1ddZd2ddZddZddZddZefddZddZd3ddZfd 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|jWdd|_Xt|tr).0cr>r>r? sz"FileIO.__init__..r rzKMust have exactly one of create/read/write/append mode and at most one plusrTr rrO_BINARYZ O_NOINHERIT O_CLOEXECz'Cannot use closefd=False with file nameizexpected integer from openerzNegative file descriptorFr*)-_fd_closefdrr2rfloatrrr!rrsumcount_created _writableO_EXCLO_CREAT _readableO_TRUNC _appendingO_APPENDO_RDWRO_RDONLYO_WRONLYgetattrr@r+set_inheritabler(statS_ISDIRst_modeIsADirectoryErrorrZEISDIRrr,_blksizer'_setmoderrRlseekr ZESPIPE) rCr3r1r8rfdflagsZnoinherit_flagZowned_fdZfdfstatrr>r>r?rs     $                   zFileIO.__init__cCsB|jdkr>|jr>|js>ddl}|jd|ftd|d|dS)Nrzunclosed file %rr ) stacklevelsource)rrrdr"r#ResourceWarningr2)rCr"r>r>r?r\s  zFileIO.__del__cCstd|jjdS)Nzcannot serialize '%s' object)rrQrG)rCr>r>r?rszFileIO.__getstate__cCsld|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>) rQrHrIrdrRr,rr1r)rC class_namerRr>r>r?rs  zFileIO.__repr__cCs|jstddS)NzFile not open for reading)rrO)rCr>r>r?ra-szFileIO._checkReadablecCs|jstddS)NzFile not open for writing)rrO)rCr^r>r>r?rc1szFileIO._checkWritablecCsP|||dks |dkr(|Syt|j|Stk rJdSXdS)zRead 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)rYrarrrqrr)rCrlr>r>r?rq5sz FileIO.readcCs||t}y6t|jdt}t|jj}||krH||d}Wnt k r^YnXt }xnt ||krt |}|t |t7}|t |}yt |j|}Wntk r|rPdSX|sP||7}qhWt|S)zRead 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)rYrar'rrrrr(st_sizer+rpr rrqrr)rCbufsizerUendr;rkrr>r>r?rEs4   zFileIO.readallcCs4t|d}|t|}t|}||d|<|S)zSame as RawIOBase.readinto().rN)rrrqr )rCrmrrkr>r>r?rhs  zFileIO.readintocCs8||yt|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)rYrcrr~rr)rCrr>r>r?r~ps z FileIO.writecCs*t|trtd|t|j||S)aMove 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)rrrrYrrr)rCrUrVr>r>r?rT~s z FileIO.seekcCs|t|jdtS)zYtell() -> int. Current file position. Can raise OSError for non seekable files.r)rYrrrr)rCr>r>r?rWsz FileIO.tellcCs2|||dkr |}t|j||S)zTruncate 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)rYrcrWr ftruncater)rCrlr>r>r?rXs zFileIO.truncatecs.|js*z|jrt|jWdtXdS)zClose the file. A closed file cannot be used for further I/O operations. close() may be called more than once without error. N)rdrrr2rr)rC)rQr>r?r2s z FileIO.closecCsF||jdkr@y |Wntk r8d|_YnXd|_|jS)z$True if file supports random-access.NFT)rY _seekablerWr+)rCr>r>r?r]s   zFileIO.seekablecCs||jS)z'True if file was opened in a read mode.)rYr)rCr>r>r?r`szFileIO.readablecCs||jS)z(True if file was opened in a write mode.)rYr)rCr>r>r?rbszFileIO.writablecCs||jS)z3Return the underlying file descriptor (an integer).)rYr)rCr>r>r?r)sz FileIO.filenocCs|t|jS)z.True if the file is connected to a TTY device.)rYrr&r)rCr>r>r?r&sz FileIO.isattycCs|jS)z6True if the file descriptor will be closed by close().)r)rCr>r>r?r8szFileIO.closefdcCsJ|jr|jrdSdSn0|jr,|jr&dSdSn|jrB|jrr>r?r1sz FileIO.mode)r TN)N)N)N)"rGrHrIrrrrrrrrr\rrrarcrqrrr~rrTrWrXr2r]r`rbr)r&rr8r1rr>r>)rQr?r%s8 y  #    r%c@s`eZdZdZdddZddZddd Zd d Zd d Ze ddZ e ddZ e ddZ dS) TextIOBasezBase class for text I/O. This class provides a character and line based interface to stream I/O. There is no public constructor. rcCs|ddS)zRead 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)rS)rCrlr>r>r?rqszTextIOBase.readcCs|ddS)z.Write string s to stream and returning an int.r~N)rS)rCsr>r>r?r~szTextIOBase.writeNcCs|ddS)z*Truncate size to pos, where pos is an int.rXN)rS)rCrUr>r>r?rXszTextIOBase.truncatecCs|ddS)z_Read until newline or EOF. Returns an empty string if EOF is hit immediately. ruN)rS)rCr>r>r?ruszTextIOBase.readlinecCs|ddS)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. rN)rS)rCr>r>r?r szTextIOBase.detachcCsdS)zSubclasses should override.Nr>)rCr>r>r?r5szTextIOBase.encodingcCsdS)zLine endings translated so far. Only line endings translated during reading are considered. Subclasses should override. Nr>)rCr>r>r?newlinesszTextIOBase.newlinescCsdS)zMError setting of the decoder or encoder. Subclasses should override.Nr>)rCr>r>r?r6#szTextIOBase.errors)r)N) rGrHrIrBrqr~rXrurrr5rr6r>r>r>r?rs    rc@sTeZdZdZdddZdddZdd Zd d Zd d ZdZ dZ dZ e ddZ 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)r6rF)codecsIncrementalDecoderr translatedecoderseennl pendingcr)rCrrr6r>r>r?r4s z"IncrementalNewlineDecoder.__init__FcCs|jdkr|}n|jj||d}|jr<|s.|rr>r?r;s(   "  z IncrementalNewlineDecoder.decodecCs@|jdkrd}d}n|j\}}|dK}|jr8|dO}||fS)Nrrr )rgetstater)rCrflagr>r>r?rZs z"IncrementalNewlineDecoder.getstatecCs8|\}}t|d@|_|jdk r4|j||d?fdS)Nr )boolrrsetstate)rCstaterrr>r>r?res z"IncrementalNewlineDecoder.setstatecCs$d|_d|_|jdk r |jdS)NrF)rrrreset)rCr>r>r?rks zIncrementalNewlineDecoder.resetr r cCs d|jS)N)Nrr)rrz )rz )rz )rrz )r)rCr>r>r?rusz"IncrementalNewlineDecoder.newlinesN)r)F)rGrHrIrBrrrrrrrrrrr>r>r>r?r-s   rc@sveZdZdZdZdZdOddZddZdPd d Zd d Z e d dZ e ddZ e ddZ e ddZe ddZddedddddZddZddZddZd d!Zd"d#Ze d$d%Ze d&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3ZdQd4d5Zd6d7Z d8d9Z!dRd;d<Z"d=d>Z#d?d@Z$dSdAdBZ%dCdDZ&dTdEdFZ'dUdGdHZ(dIdJZ)dVdKdLZ*e dMdNZ+dS)Wr0aCharacter 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|||dkrvyt|}Wnttfk r<YnX|dkrvy ddl}Wntk rjd}Yn X|d}t |t st d|t |jsd}t|||dkrd}nt |t st d|||_d|_d|_d|_|j|_|_t|jd |_||||||dS) NrasciiFzinvalid encoding: %rzG%r is not a text encoding; use codecs.open() to handle arbitrary codecsrzinvalid errors: %rrr)_check_newlinerdevice_encodingr)r,rOlocale ImportErrorZgetpreferredencodingrrr!rlookup_is_text_encoding LookupErrorr_decoded_chars_decoded_chars_used _snapshotr=r]r_tellingrn _has_read1 _configure) rCr=r5r6r7r< write_throughr r^r>r>r?rs:           zTextIOWrapper.__init__cCs>|dk r$t|ts$tdt|f|dkr:td|fdS)Nzillegal newline type: %r)Nrrrz zillegal newline value: %r)rrrtyper!)rCr7r>r>r?r szTextIOWrapper._check_newlinecCs||_||_d|_d|_d|_| |_|dk|_||_|dk|_|pHt j |_ ||_ ||_ |jr|r|j}|dkry|dWntk rYnXdS)Ngrr) _encoding_errors_encoder_decoder _b2cratio_readuniversal_readtranslate_readnl_writetranslaterlinesep_writenl_line_buffering_write_throughrrbr=rW _get_encoderrr)rCr5r6r7r<rpositionr>r>r?rs&    zTextIOWrapper._configurecCsd|jj|jj}y |j}Wntk r2YnX|d|7}y |j}Wntk r`YnX|d|7}|d|jS)Nz<{}.{}z name={0!r}z mode={0!r}z encoding={0!r}>)rrQrHrIrRrr1r5)rCr;rRr1r>r>r?rs    zTextIOWrapper.__repr__cCs|jS)N)r)rCr>r>r?r5szTextIOWrapper.encodingcCs|jS)N)r)rCr>r>r?r6 szTextIOWrapper.errorscCs|jS)N)r#)rCr>r>r?r<szTextIOWrapper.line_bufferingcCs|jS)N)r$)rCr>r>r?rszTextIOWrapper.write_throughcCs|jS)N)r)rCr>r>r?r=szTextIOWrapper.buffer)r5r6r7r<rcCs|jdk r*|dk s"|dk s"|tk r*td|dkrH|dkrB|j}q^d}nt|ts^td||dkrn|j}nt|tstd||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 readrzinvalid errors: %rzinvalid encoding: %r)rEllipsisrOrrrrrrr r<rrZr)rCr5r6r7r<rr>r>r? reconfigures2       zTextIOWrapper.reconfigurecCs|jrtd|jS)NzI/O operation on closed file.)rdr!r)rCr>r>r?r]CszTextIOWrapper.seekablecCs |jS)N)r=r`)rCr>r>r?r`HszTextIOWrapper.readablecCs |jS)N)r=rb)rCr>r>r?rbKszTextIOWrapper.writablecCs|j|j|_dS)N)r=rZrr)rCr>r>r?rZNs zTextIOWrapper.flushcCs.|jdk r*|js*z |Wd|jXdS)N)r=rdrZr2)rCr>r>r?r2Rs zTextIOWrapper.closecCs|jjS)N)r=rd)rCr>r>r?rdYszTextIOWrapper.closedcCs|jjS)N)r=rR)rCr>r>r?rR]szTextIOWrapper.namecCs |jS)N)r=r))rCr>r>r?r)aszTextIOWrapper.filenocCs |jS)N)r=r&)rCr>r>r?r&dszTextIOWrapper.isattycCs|jrtdt|ts(td|jjt|}|js<|j oBd|k}|rf|jrf|j dkrf| d|j }|j pr| }||}|j||j r|sd|kr||dd|_|jr|j|S)zWrite data, where s is a strzwrite to closed filezcan't write %s to text streamrrrN)rdr!rrrrQrGr r r#r"rrr%encoder=r~rZ_set_decoded_charsrrr)rCrlengthZhaslfencoderrr>r>r?r~gs&      zTextIOWrapper.writecCst|j}||j|_|jS)N)rgetincrementalencoderrrr)rCZ make_encoderr>r>r?r%~s  zTextIOWrapper._get_encodercCs2t|j}||j}|jr(t||j}||_|S)N)rgetincrementaldecoderrrrrrr)rCZ make_decoderrr>r>r? _get_decoders    zTextIOWrapper._get_decodercCs||_d|_dS)zSet the _decoded_chars buffer.rN)rr)rCcharsr>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)rrr )rCrkoffsetr0r>r>r?_get_decoded_charss z TextIOWrapper._get_decoded_charscCs$|j|krtd|j|8_dS)z!Rewind the _decoded_chars buffer.z"rewind decoded_chars out of boundsN)rAssertionError)rCrkr>r>r?_rewind_decoded_charss z#TextIOWrapper._rewind_decoded_charscCs|jdkrtd|jr&|j\}}|jr<|j|j}n|j|j}| }|j ||}| ||rt |t |j |_ nd|_ |jr|||f|_| S)zQ Read and decode the next chunk of data from the BufferedReader. Nz no decoderg)rr!rrrr=r _CHUNK_SIZErqrr*r rrr)rC dec_buffer dec_flags input_chunkeofZ decoded_charsr>r>r? _read_chunks  zTextIOWrapper._read_chunkrcCs(||d>B|d>B|d>Bt|d>BS)N@)r)rCr&r7 bytes_to_feedneed_eof chars_to_skipr>r>r? _pack_cookieszTextIOWrapper._pack_cookiecCsFt|d\}}t|d\}}t|d\}}t|d\}}|||||fS)Nl)divmod)rCZbigintrestr&r7r?r@rAr>r>r?_unpack_cookies zTextIOWrapper._unpack_cookiec Cs:|jstd|jstd||j}|j}|dksF|jdkrX|j rTt d|S|j\}}|t |8}|j }|dkr| ||S|}zt|j|}d}x|dkr"|d|ft ||d|} | |kr|\} } | s| }|| 8}P|t | 8}d}q||8}|d}qWd}|d|f||} |} |dkrX| | | Sd}d}d}xt|t |D]t}|d7}|t ||||d7}|\}}|s||kr| |7} ||8}|dd} }}||krtPqtW|t |jddd 7}d}||krtd | | | |||S||XdS) Nz!underlying stream is not seekablez(telling position disabled by next() callzpending decoded textrr rr T)rz'can't reconstruct logical file position)rrOrr+rZr=rWrrrr3r rrBrrrrrrange)rCr&rr7Z next_inputrAZ saved_stateZ skip_bytesZ skip_backrkrd start_posZ start_flagsZ bytes_fedr@Z chars_decodedir6r>r>r?rWsv              zTextIOWrapper.tellcCs$||dkr|}|j|S)N)rZrWr=rX)rCrUr>r>r?rXA szTextIOWrapper.truncatecCs*|jdkrtd||j}d|_|S)Nzbuffer is already detached)r=r!rZr)rCr=r>r>r?rG s  zTextIOWrapper.detachc sfdd}jrtdjs(td|dkrL|dkr@tdd}}|dkr|dkrdtd jdd}d d_ j rj |||S|dkrtd |f|dkrtd |f |\}}}}} j|d d_ |dkr(j r(j n@j s<|s<| rhj pJ _ j d |f|d f_ | rj|} j | ||| f_ tj| krtd| _|||S)NcsHyjp}Wntk r&YnX|dkr<|dn|dS)z9Reset the encoder (merely useful for proper BOM handling)rN)rr%rrr)r&r,)rCr>r?_reset_encoderP s z*TextIOWrapper.seek.._reset_encoderztell on closed filez!underlying stream is not seekabler rz#can't do nonzero cur-relative seeksr z#can't do nonzero end-relative seeksrzunsupported whence (%r)znegative seek position %rrz#can't restore logical file position)rdr!rrOrWrZr=rTr*rrrrEr/rrqrr rr+r) rCZcookierVrJr&rHr7r?r@rAr8r>)rCr?rTO s\         zTextIOWrapper.seekcCs||dkrd}n4y |j}Wn"tk rBt|dYnX|}|jpV|}|dkr||j|j dd}| dd|_ |Sd}||}x4t ||kr|s| }|||t |7}qW|SdS)Nrz is not an integerrT)rrF)raror,rrr/r2rr=rqr*rr r:)rCrlrsrr;r9r>r>r?rq s*    zTextIOWrapper.readcCs(d|_|}|s$d|_|j|_t|S)NF)rrurrrw)rCrxr>r>r?ry szTextIOWrapper.__next__c Cs|jrtd|dkrd}n4y |j}Wn"tk rHt|dYnX|}|}d}|jsj|d}}xV|jr| d|}|dkr|d}Pnt |}n|j r>| d|}| d|}|dkr|dkrt |}n |d}PnP|dkr|d}Pn:||kr|d}Pn$||dkr2|d}Pn |d}Pn&| |j }|dkrd|t |j }P|dkrt ||kr|}Px| r|jrPqW|jr||7}qv|d d|_|SqvW|dkr||kr|}|t |||d|S) Nzread from closed filerz is not an integerrrr rr r)rdr!ror,rr2rr/rrir rrr:rr*rr4) rCrlrsrxstartrUendposZnlposZcrposr>r>r?ru sv            zTextIOWrapper.readlinecCs|jr|jjSdS)N)rr)rCr>r>r?r szTextIOWrapper.newlines)NNNFF)NNNFF)N)rrrr)N)r)N)N),rGrHrIrBr5rrr rrrr5r6r<rr=r'r(r]r`rbrZr2rdrRr)r&r~r%r/r*r2r4r:rBrErWrXrrTrqryrurr>r>r>r?r0sV ' #     '    * c  K  ]r0csReZdZdZdfdd ZddZdd Zed d Zed d Z ddZ Z S)StringIOzText 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. rrcsftt|jtdd|d|dkr(d|_|dk rbt|tsNtdt |j | || ddS)Nzutf-8 surrogatepass)r5r6r7Fz*initial_value must be str or None, not {0}r) rrMrrr rrrrrrGr~rT)rCZ initial_valuer7)rQr>r?r( s  zStringIO.__init__c CsL||jp|}|}|z|j|jddS||XdS)NT)r) rZrr/rrrr=rr)rCrZ old_stater>r>r?r8 szStringIO.getvaluecCs t|S)N)objectr)rCr>r>r?rB szStringIO.__repr__cCsdS)Nr>)rCr>r>r?r6G szStringIO.errorscCsdS)Nr>)rCr>r>r?r5K szStringIO.encodingcCs|ddS)Nr)rS)rCr>r>r?rO szStringIO.detach)rr) rGrHrIrBrrrrr6r5rrr>r>)rQr?rM! s   rM)r rNNNTN)3rBrabcrrrsys_threadrrplatformZmsvcrtrriorrrr rrnaddr SEEK_DATAr'rr@rArJrOr,r+r!ABCMetarPregisterr_ior%rrrr/r.rr-rrrr0rMr>r>r>r?st       T   =   g iCiIJY@ U$