a DOgl@szdZddlZddlZddlZddlZddlZddlZddlmZ ej dvrXddl m Z ndZ ddlZddlmZmZmZmZhdZeedreejeejd ZeZeed pejjZeZd6ddZddZz ej Z Wne!yeZ Yn0GdddZ"GdddZ#z ej$Z$Wn&e!yFGddde%e&Z$Yn0Gdddej'dZ(ej()e(Gddde(Z*ej*)e*ddl+m,Z,e*)e,Gddde(Z-ej-)e-Gd d!d!e-Z.Gd"d#d#e-Z/Gd$d%d%e.Z0Gd&d'd'e.Z1Gd(d)d)e-Z2Gd*d+d+e1e0Z3Gd,d-d-e*Z,Gd.d/d/e(Z4ej4)e4Gd0d1d1ej5Z6Gd2d3d3e4Z7Gd4d5d5e7Z8dS)7z) Python implementation of the io module. N) allocate_lock>cygwinZwin32)setmode)__all__SEEK_SETSEEK_CURSEEK_END>r SEEK_HOLEi ZgettotalrefcountrTc Cst|tst|}t|tttfs0td|t|tsFtd|t|ts\td||durzt|tsztd||durt|tstd|t|}|tdst|t|krt d|d|v} d |v} d |v} d |v} d |v} d |v}d|v}d|vrD| s"| s"| s"| r*t dddl }| dt dd} |rX|rXt d| | | | dkrvt d| s| s| s| st d|r|durt d|r|durt d|r|durt d|r|dkrddl }| dt dt|| rdpd| r"d p$d| r2d p4d| rBd pDd| rRd pTd||d}|}z"d}|dks|dkr|rd }d}|dkrt}zt|j}WnttfyYn0|dkr|}|dkrt d!|dkr |r|WSt d"| rt||}n<| s0| s0| r 1 to indicate the size of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows: * Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device's "block size" and falling back on `io.DEFAULT_BUFFER_SIZE`. On many systems, the buffer will typically be 4096 or 8192 bytes long. * "Interactive" text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files. encoding is the str name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings. errors is an optional string that specifies how encoding errors are to be handled---this argument should not be used in binary mode. Pass 'strict' to raise a ValueError exception if there is an encoding error (the default of None has the same effect), or pass 'ignore' to ignore errors. (Note that ignoring encoding errors can lead to data loss.) See the documentation for codecs.register for a list of the permitted encoding error strings. newline is a string controlling how universal newlines works (it only applies to text mode). It can be None, '', '\n', '\r', and '\r\n'. It works as follows: * On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in '\n', '\r', or '\r\n', and these are translated into '\n' before being returned to the caller. If it is '', universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated. * On output, if newline is None, any '\n' characters written are translated to the system default line separator, os.linesep. If newline is '', no translation takes place. If newline is any of the other legal values, any '\n' characters written are translated to the given string. closedfd is a bool. If closefd is False, the underlying file descriptor will be kept open when the file is closed. This does not work when a file name is given and must be True in that case. The newly created file is non-inheritable. A custom opener can be used by passing a callable as *opener*. The underlying file descriptor for the file object is then obtained by calling *opener* with (*file*, *flags*). *opener* must return an open file descriptor (passing os.open as *opener* results in functionality similar to passing None). open() returns a file object whose type depends on the mode, and through which the standard file operations such as reading and writing are performed. When open() is used to open a file in a text mode ('w', 'r', 'wt', 'rt', etc.), it returns a TextIOWrapper. When used to open a file in a binary mode, the returned class varies: in read binary mode, it returns a BufferedReader; in write binary and append binary modes, it returns a BufferedWriter, and in read/write mode, it returns a BufferedRandom. It is also possible to use a string or bytearray as a file for both reading and writing. For strings StringIO can be used like a file opened in a text mode, and for bytes a BytesIO can be used like a file opened in a binary mode. zinvalid file: %rzinvalid mode: %rzinvalid buffering: %rNinvalid encoding: %rinvalid 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 argumentzaline buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used)openerFr zinvalid buffering sizezcan't have unbuffered text I/Ozunknown mode: %r) isinstanceintosfspathstrbytes TypeErrorsetlen ValueErrorwarningswarnDeprecationWarningRuntimeWarningFileIOisattyDEFAULT_BUFFER_SIZEfstatfileno st_blksizeOSErrorAttributeErrorBufferedRandomBufferedWriterBufferedReader TextIOWrappermodeclose)filer3 bufferingencodingerrorsnewlineclosefdrZmodesZcreatingZreadingZwritingZ appendingZupdatingtextZbinaryr#rawresultline_bufferingZbsbufferr@*/opt/alt/python39/lib64/python3.9/_pyio.pyopen+s{                    rBcCs ddl}|dtdt|dS)azOpens the provided file with mode ``'rb'``. This function should be used when the intent is to treat the contents as executable code. ``path`` should be an absolute path. When supported by the runtime, this function can be hooked in order to allow embedders more control over code files. This functionality is not supported on the current runtime. rNz(_pyio.open_code() may not be using hooksr rb)r#r$r&rB)pathr#r@r@rA_open_code_with_warnings rEc@seZdZdZdddZdS) DocDescriptorz%Helper for builtins.open.__doc__ NcCs dtjS)Nz\open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True) )rB__doc__)selfobjtypr@r@rA__get__szDocDescriptor.__get__)N)__name__ __module__ __qualname__rGrKr@r@r@rArFsrFc@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. cOst|i|SN)rB)clsargskwargsr@r@rA__new__.szOpenWrapper.__new__N)rLrMrNrGrFrTr@r@r@rArO$srOc@s eZdZdS)UnsupportedOperationN)rLrMrNr@r@r@rArU7srUc@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. 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)rU __class__rL)rHnamer@r@rA _unsupported]s zIOBase._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. seekNrYrHposwhencer@r@rArZdsz IOBase.seekcCs |ddS)z5Return an int indicating the current stream position.rr )rZrHr@r@rAtelltsz IOBase.tellNcCs|ddS)zTruncate file to size bytes. Size defaults to the current IO position as reported by tell(). Return the new size. truncateNr[rHr]r@r@rAraxszIOBase.truncatecCs |dS)zuFlush write buffers, if applicable. This is not implemented for read-only and non-blocking streams. N _checkClosedr_r@r@rAflushsz IOBase.flushFcCs&|js"z|Wd|_nd|_0dS)ziFlush and close the IO object. This method has no effect if the file is already closed. TN)_IOBase__closedrer_r@r@rAr4s z IOBase.closecCsTz |j}WntyYdS0|r(dStr6|nz |Wn Yn0dS)zDestructor. Calls close().N)closedr._IOBASE_EMITS_UNRAISABLEr4)rHrgr@r@rA__del__s    zIOBase.__del__cCsdS)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@r_r@r@rAseekableszIOBase.seekablecCs |st|durdn|dS)zEInternal: raise UnsupportedOperation if file is not seekable NzFile or stream is not seekable.)rjrUrHmsgr@r@rA_checkSeekables zIOBase._checkSeekablecCsdS)zvReturn a bool indicating whether object was opened for reading. If False, read() will raise OSError. Fr@r_r@r@rAreadableszIOBase.readablecCs |st|durdn|dS)zEInternal: raise UnsupportedOperation if file is not readable NzFile or stream is not readable.)rnrUrkr@r@rA_checkReadables zIOBase._checkReadablecCsdS)zReturn a bool indicating whether object was opened for writing. If False, write() and truncate() will raise OSError. Fr@r_r@r@rAwritableszIOBase.writablecCs |st|durdn|dS)zEInternal: raise UnsupportedOperation if file is not writable NzFile or stream is not writable.)rprUrkr@r@rA_checkWritables zIOBase._checkWritablecCs|jS)zclosed: bool. True iff the file has been closed. For backwards compatibility, this is a property, not a predicate. )rfr_r@r@rArgsz IOBase.closedcCs|jrt|durdn|dS)z7Internal: raise a ValueError if file is closed NI/O operation on closed file.rgr"rkr@r@rArds zIOBase._checkClosedcCs ||S)zCContext management protocol. Returns self (an instance of IOBase).rcr_r@r@rA __enter__szIOBase.__enter__cGs |dS)z+Context management protocol. Calls close()N)r4)rHrRr@r@rA__exit__szIOBase.__exit__cCs|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+Nr[r_r@r@rAr+sz IOBase.filenocCs |dS)z{Return a bool indicating whether this is an 'interactive' stream. Return False if it can't be determined. Frcr_r@r@rAr(sz IOBase.isattyr cstdrfdd}ndd}dur0dn2z j}Wn tyZtdYn0|t}dks|t|kr|}|sq||7}|d rhqqht|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)rvfindr!min)Z readaheadnrHsizer@rA nreadaheads  z#IOBase.readline..nreadaheadcSsdSNr r@r@r@r@rAr}!sNr  is not an integerrrw) hasattr __index__r.r bytearrayr!readendswithr)rHr|r} size_indexresrr@r{rAreadline s&      zIOBase.readlinecCs ||SrPrcr_r@r@rA__iter__6szIOBase.__iter__cCs|}|st|SrP)r StopIterationrHliner@r@rA__next__:szIOBase.__next__cCsP|dus|dkrt|Sd}g}|D]&}|||t|7}||kr$qLq$|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!)rHhintrzlinesrr@r@rA readlines@s  zIOBase.readlinescCs ||D]}||q dS)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)rdwrite)rHrrr@r@rA writelinesRszIOBase.writelines)r)N)N)N)N)N)r )N)rLrMrNrGrYrZr`rarerfr4rirjrmrnrorprqpropertyrgrdrtrur+r(rrrrrr@r@r@rArV;s6          * rV) metaclassc@s2eZdZdZd ddZddZddZd d Zd S) RawIOBasezBase class for raw binary I/O.r cCsP|dur d}|dkr|St|}||}|dur>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. Nr r)readallrrreadintor)rHr|rrzr@r@rArms   zRawIOBase.readcCs4t}|t}|sq ||7}q|r,t|S|SdS)z+Read until EOF, using multiple read() call.N)rrr)r)rHrdatar@r@rAr~s  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. rNr[rHrr@r@rArszRawIOBase.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. rNr[rr@r@rArszRawIOBase.writeN)r )rLrMrNrGrrrrr@r@r@rAr_s  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. r cCs|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. rNr[r{r@r@rArszBufferedIOBase.readcCs|ddS)zaRead up to size bytes with at most one read() system call, where size is an int. read1Nr[r{r@r@rArszBufferedIOBase.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. Fr _readintorr@r@rArs 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. Trrrr@r@rA readinto1s zBufferedIOBase.readinto1cCsVt|tst|}|d}|r0|t|}n|t|}t|}||d|<|S)NB)r memoryviewcastrr!r)rHrrrrzr@r@rArs   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. rNr[rr@r@rArs 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. detachNr[r_r@r@rArszBufferedIOBase.detachN)r )r ) rLrMrNrGrrrrrrrr@r@r@rArs    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 ||_dSrP_rawrHr<r@r@rA__init__sz_BufferedIOMixin.__init__rcCs"|j||}|dkrtd|S)Nrz#seek() returned an invalid position)r<rZr-)rHr]r^Z new_positionr@r@rArZsz_BufferedIOMixin.seekcCs|j}|dkrtd|S)Nrz#tell() returned an invalid position)r<r`r-rbr@r@rAr`s z_BufferedIOMixin.tellNcCs4||||dur(|}|j|SrP)rdrqrer`r<rarbr@r@rAra%s z_BufferedIOMixin.truncatecCs|jrtd|jdS)Nflush on closed file)rgr"r<rer_r@r@rAre6sz_BufferedIOMixin.flushcCs8|jdur4|js4z|W|jn |j0dSrP)r<rgrer4r_r@r@rAr4;s z_BufferedIOMixin.closecCs*|jdurtd||j}d|_|S)Nzraw stream already detached)r<r"rerrr@r@rArCs  z_BufferedIOMixin.detachcCs |jSrP)r<rjr_r@r@rArjMsz_BufferedIOMixin.seekablecCs|jSrPrr_r@r@rAr<Psz_BufferedIOMixin.rawcCs|jjSrP)r<rgr_r@r@rArgTsz_BufferedIOMixin.closedcCs|jjSrP)r<rXr_r@r@rArXXsz_BufferedIOMixin.namecCs|jjSrP)r<r3r_r@r@rAr3\sz_BufferedIOMixin.modecCstd|jjddSNzcannot pickle z objectrrWrLr_r@r@rA __getstate__`sz_BufferedIOMixin.__getstate__cCsL|jj}|jj}z |j}Wnty8d||YS0d|||SdS)Nz<{}.{}>z<{}.{} name={!r}>)rWrMrNrXr.format)rHmodnameZclsnamerXr@r@rA__repr__cs  z_BufferedIOMixin.__repr__cCs |jSrP)r<r+r_r@r@rAr+osz_BufferedIOMixin.filenocCs |jSrP)r<r(r_r@r@rAr(rsz_BufferedIOMixin.isatty)r)N)rLrMrNrGrrZr`rarer4rrjrr<rgrXr3rrr+r(r@r@r@rAr s*        rcseZdZdZdZd!ddZddZddZd d Zfd d Z d"ddZ d#ddZ ddZ d$ddZ ddZd%ddZddZddZdd ZZS)&BytesIOz0YdS)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. Nr zinvalid number of bytes to read)r"r_read_unlockedr{r@r@rAr$szBufferedReader.readc Csd}d}|j}|j}|dus$|dkr|t|jdrj|j}|durZ||dpXdS||d|S||dg}d}|j}||vr|}q|t|7}||q|d |p|St||} || kr|j|7_||||S||dg}t |j |} | |krH|j| }||vr.|}qH| t|7} ||qt || }d |} | |d|_d|_| r| d|S|S)Nr)rNr rr) rrrrr<rrr!rjoinrrry) rHrzZ nodata_valZ empty_valuesrr]chunkZchunksZ current_sizeavailZwantedoutr@r@rAr1sL             zBufferedReader._read_unlockedrcCs4|j||WdS1s&0YdS)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_unlockedr{r@r@rArveszBufferedReader.peekcCsrt||j}t|j|j}||ks,|dkrb|j|}|j|}|rb|j|jd||_d|_|j|jdSr)ryrr!rrr<r)rHrzZwantZhaveZto_readZcurrentr@r@rAros   zBufferedReader._peek_unlockedr cCsj|dkr|j}|dkrdS|j6|d|t|t|j|jWdS1s\0YdS)zd |_d |_tjtjB}d |vrTd |_d |_|jrp|jrp|tjO}n|jr|tjO}n |tjO}|ttddO}ttddpttdd}||O}d}zT|dkr@|std|durt||d}n0|||}t|tstd|dkr*td|}|s@t|d||_t|} z(t| jrvt t!j"t#t!j"|Wnt$yYn0t| dd|_%|j%d krt&|_%t'rt'|tj(||_)|jrzt*|dt+Wn6ty} z| j!t!j,krWYd} ~ n d} ~ 00Wn"|dur6t|Yn0||_dS)adOpen a file. The mode can be 'r' (default), 'w', 'x' or 'a' for reading, writing, exclusive creation or appending. The file will be created if it doesn't exist when opened for writing or appending; it will be truncated when opened for writing. A FileExistsError will be raised if it already exists when opened for creating. Opening a file for creating implies writing so this mode behaves in a similar way to 'w'. Add a '+' to the mode to allow simultaneous reading and writing. A custom opener can be used by passing a callable as *opener*. The underlying file descriptor for the file object is then obtained by calling opener with (*name*, *flags*). *opener* must return an open file descriptor (passing os.open as *opener* results in functionality similar to passing None). rr z$integer argument expected, got floatznegative file descriptorzinvalid mode: %szxrwab+css|]}|dvVqdS)ZrwaxNr@).0cr@r@rA rz"FileIO.__init__..r rzKMust have exactly one of create/read/write/append mode and at most one plusrTr rrO_BINARYZ O_NOINHERIT O_CLOEXECNz'Cannot use closefd=False with file nameizexpected integer from openerzNegative file descriptorFr,)-_fd_closefdrr4rfloatrrr"rr sumcount_created _writableO_EXCLO_CREAT _readableO_TRUNC _appendingO_APPENDO_RDWRO_RDONLYO_WRONLYgetattrrBr-set_inheritabler*statS_ISDIRst_modeIsADirectoryErrorrZEISDIRrr._blksizer)_setmoderrXlseekrZESPIPE) rHr5r3r:rfdflagsZnoinherit_flagZowned_fdZfdfstatrr@r@rArs     $                    zFileIO.__init__cCsB|jdkr>|jr>|js>ddl}|jd|ftd|d|dS)Nrzunclosed file %rr ) stacklevelsource)rrrgr#r$ResourceWarningr4)rHr#r@r@rAriEs zFileIO.__del__cCstd|jjddSrrr_r@r@rArLszFileIO.__getstate__cCsnd|jj|jjf}|jr"d|Sz |j}Wn(tyTd||j|j|jfYS0d|||j|jfSdS)Nz%s.%sz <%s [closed]>z<%s fd=%d mode=%r closefd=%r>z<%s name=%r mode=%r closefd=%r>) rWrMrNrgrXr.rr3r)rH class_namerXr@r@rArOs   zFileIO.__repr__cCs|jstddS)NzFile not open for reading)rrUr_r@r@rAro]szFileIO._checkReadablecCs|jstddS)NzFile not open for writing)rrUrkr@r@rArqaszFileIO._checkWritablecCsR|||dus |dkr(|Szt|j|WStyLYdS0dS)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)rdrorrrrrr{r@r@rAres z FileIO.readcCs||t}z6t|jdt}t|jj}||krH||d}Wnt y\Yn0t }t ||krt |}|t |t7}|t |}zt |j|}Wnty|rYqYdS0|sq||7}qdt|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)rdror)rrrrr*st_sizer-rr!rrrr)rHbufsizer]endr=rzrr@r@rArus2     zFileIO.readallcCs4t|d}|t|}t|}||d|<|S)zSame as RawIOBase.readinto().rN)rrrr!)rHrmrrzr@r@rArs  zFileIO.readintocCs:||zt|j|WSty4YdS0dS)aWrite bytes b to file, return number written. Only makes one system call, so not all of the data may be written. The number of bytes actually written is returned. In non-blocking mode, returns None if the write would block. N)rdrqrrrrrr@r@rArs  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)rrrrdrrrr\r@r@rArZs z FileIO.seekcCs|t|jdtS)zYtell() -> int. Current file position. Can raise OSError for non seekable files.r)rdrrrrr_r@r@rAr`sz FileIO.tellcCs2|||dur |}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)rdrqr`r ftruncaterr{r@r@rAras zFileIO.truncatecs8|js4z |jrt|jWtn t0dS)zClose the file. A closed file cannot be used for further I/O operations. close() may be called more than once without error. N)rgrrr4rrr_rr@rAr4s z FileIO.closecCsD||jdur>z |Wnty6d|_Yn0d|_|jS)z$True if file supports random-access.NFT)rd _seekabler`r-r_r@r@rArjs    zFileIO.seekablecCs||jS)z'True if file was opened in a read mode.)rdrr_r@r@rArnszFileIO.readablecCs||jS)z(True if file was opened in a write mode.)rdrr_r@r@rArpszFileIO.writablecCs||jS)z3Return the underlying file descriptor (an integer).)rdrr_r@r@rAr+sz FileIO.filenocCs|t|jS)z.True if the file is connected to a TTY device.)rdrr(rr_r@r@rAr(sz FileIO.isattycCs|jS)z6True if the file descriptor will be closed by close().)rr_r@r@rAr:szFileIO.closefdcCsJ|jr|jrdSdSn0|jr,|jr&dSdSn|jrB|jrZ#d?d@Z$dSdAdBZ%dCdDZ&dTdEdFZ'dUdGdHZ(dIdJZ)dVdKdLZ*e dMdNZ+dS)Wr2aCharacter and line based layer over a BufferedIOBase object, buffer. encoding gives the name of the encoding that the stream will be decoded or encoded with. It defaults to locale.getpreferredencoding(False). errors determines the strictness of encoding and decoding (see the codecs.register) and defaults to "strict". newline can be None, '', '\n', '\r', or '\r\n'. It controls the handling of line endings. If it is None, universal newlines is enabled. With this enabled, on input, the lines endings '\n', '\r', or '\r\n' are translated to '\n' before being returned to the caller. Conversely, on output, '\n' is translated to the system default line separator, os.linesep. If newline is any other of its legal values, that newline becomes the newline when the file is read and it is returned untranslated. On output, '\n' is converted to the newline. If line_buffering is True, a call to flush is implied when a call to write contains a newline character. iNFc Cs$|||durrzt|}Wnttfy:Yn0|durrz ddl}Wntyfd}Yn 0|d}t |t st d|t |jsd}t|||durd}n$t |t st d|trt |||_d|_d|_d|_|j|_|_t|jd |_||||||dS) NrasciiFrzG%r is not a text encoding; use codecs.open() to handle arbitrary codecsrrrr)_check_newlinerdevice_encodingr+r.rUlocale ImportErrorZgetpreferredencodingrrr"rlookup_is_text_encoding LookupError _CHECK_ERRORS lookup_errorr_decoded_chars_decoded_chars_used _snapshotr?rjr_tellingr _has_read1 _configure) rHr?r7r8r9r> write_throughr4rlr@r@rArs@             zTextIOWrapper.__init__cCs>|dur$t|ts$tdt|f|dvr:td|fdS)Nzillegal newline type: %r)Nrr"r r!zillegal newline value: %r)rrrtyper")rHr9r@r@rAr2szTextIOWrapper._check_newlinecCs||_||_d|_d|_d|_| |_|du|_||_|dk|_|pHt j |_ ||_ ||_ |jr|r|j}|dkrz|dWntyYn0dS)Nrr) _encoding_errors_encoder_decoder _b2cratio_readuniversal_readtranslate_readnl_writetranslaterlinesep_writenl_line_buffering_write_throughrrpr?r` _get_encoderr-r8)rHr7r8r9r>rApositionr@r@rAr@s&     zTextIOWrapper._configurecCs|d|jj|jj}z |j}Wnty0Yn0|d|7}z |j}Wnty\Yn0|d|7}|d|jS)Nz<{}.{}z name={0!r}z mode={0!r}z encoding={0!r}>)rrWrMrNrXr.r3r7)rHr=rXr3r@r@rAr's     zTextIOWrapper.__repr__cCs|jSrP)rDr_r@r@rAr78szTextIOWrapper.encodingcCs|jSrP)rEr_r@r@rAr8<szTextIOWrapper.errorscCs|jSrP)rOr_r@r@rAr>@szTextIOWrapper.line_bufferingcCs|jSrP)rPr_r@r@rArADszTextIOWrapper.write_throughcCs|jSrP)rr_r@r@rAr?HszTextIOWrapper.buffer)r7r8r9r>rAcCs|jdur*|dus"|dus"|tur*td|durH|durB|j}q^d}nt|ts^td||durn|j}nt|tstd||tur|j}| ||dur|j }|dur|j }| | |||||dS)z`Reconfigure the text stream with new parameters. This also flushes the stream. NzPIt is not possible to set the encoding or newline of stream after the first readrrr)rGEllipsisrUrErrrrDrKr2r>rArer@)rHr7r8r9r>rAr@r@rA reconfigureLs>       zTextIOWrapper.reconfigurecCs|jrtd|jS)Nrr)rgr"rr_r@r@rArjuszTextIOWrapper.seekablecCs |jSrP)r?rnr_r@r@rArnzszTextIOWrapper.readablecCs |jSrP)r?rpr_r@r@rArp}szTextIOWrapper.writablecCs|j|j|_dSrP)r?rerr>r_r@r@rAres zTextIOWrapper.flushcCs8|jdur4|js4z|W|jn |j0dSrP)r?rgrer4r_r@r@rAr4s zTextIOWrapper.closecCs|jjSrP)r?rgr_r@r@rArgszTextIOWrapper.closedcCs|jjSrP)r?rXr_r@r@rArXszTextIOWrapper.namecCs |jSrP)r?r+r_r@r@rAr+szTextIOWrapper.filenocCs |jSrP)r?r(r_r@r@rAr(szTextIOWrapper.isattycCs|jrtdt|ts(td|jjt|}|js<|j oBd|v}|rf|jrf|j dkrf| d|j }|j pr| }||}|j||j r|sd|vr||dd|_|jr|j|S)zWrite data, where s is a strrzcan't write %s to text streamr"r rN)rgr"rrrrWrLr!rLrOrNr'rFrQencoder?rre_set_decoded_charsr=rGr/)rHrZlengthZhaslfencoderrr@r@rArs(     zTextIOWrapper.writecCst|j}||j|_|jSrP)rgetincrementalencoderrDrErF)rHZ make_encoderr@r@rArQs  zTextIOWrapper._get_encodercCs2t|j}||j}|jr(t||j}||_|SrP)rgetincrementaldecoderrDrErIrrJrG)rHZ make_decoderrr@r@rA _get_decoders    zTextIOWrapper._get_decodercCs||_d|_dS)zSet the _decoded_chars buffer.rN)r;r<)rHcharsr@r@rArVsz TextIOWrapper._set_decoded_charscCsF|j}|dur|j|d}n|j|||}|jt|7_|S)z'Advance into the _decoded_chars buffer.N)r<r;r!)rHrzoffsetr[r@r@rA_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)r<AssertionErrorrr@r@rA_rewind_decoded_charss z#TextIOWrapper._rewind_decoded_charscCs|jdurtd|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 decoderrC)rGr"r>r*r?r?r _CHUNK_SIZErr#rVr!r;rHr=)rH dec_buffer dec_flags input_chunkeofZ decoded_charsr@r@rA _read_chunks  zTextIOWrapper._read_chunkrcCs(||d>B|d>B|d>Bt|d>BS)N@)r,)rHrRrb bytes_to_feedneed_eof chars_to_skipr@r@rA _pack_cookies  zTextIOWrapper._pack_cookiecCsJt|d\}}t|d\}}t|d\}}t|d\}}|||t||fS)Nl)divmodr,)rHZbigintrestrRrbrjrkrlr@r@rA_unpack_cookie s zTextIOWrapper._unpack_cookiec CsP|jstd|jstd||j}|j}|dusF|jdurX|j rTt d|S|j\}}|t |8}|j }|dkr| ||S|}zt|j|}d}|dkr"|d|ft ||d|} | |kr|\} } | s| }|| 8}q4|t | 8}d}q||8}|d}qd}|d|f||} |} |dkrb| | | W||Sd}d}d}t|t |D]x}|d7}|t ||||d7}|\}}|s||kr| |7} ||8}|dd} }}||kr|q"q||t |jdd d 7}d }||kr"td | | | |||W||S||0dS) N!underlying stream is not seekablez(telling position disabled by next() callzpending decoded textrr rr FTrz'can't reconstruct logical file position)rrUr>r-rer?r`rGr=r;r^r!r<rmr*rrHr-r#range)rHrRrrbZ next_inputrlZ saved_stateZ skip_bytesZ skip_backrzrd start_posZ start_flagsZ bytes_fedrkZ chars_decodedirar@r@rAr` s                 zTextIOWrapper.tellcCs$||dur|}|j|SrP)rer`r?rarbr@r@rAras szTextIOWrapper.truncatecCs*|jdurtd||j}d|_|S)Nzbuffer is already detached)r?r"rer)rHr?r@r@rAry s  zTextIOWrapper.detachc sfdd}jrtdjs(td|tkrN|dkr@tdd}}nZ|tkr|dkrftdj d|} dd_ j rj |||S|dkrtd |f|dkrtd |f|\}}}}} j | dd_ |dkr*j r*j n@j s>|s>| rjj pL_ j d |f|d f_ | rj|} j | ||| f_ tj| krtd | _|||S) NcsFzjp}Wnty$Yn0|dkr:|dn|dS)z9Reset the encoder (merely useful for proper BOM handling)rN)rFrQr8r-r/)rRrWr_r@rA_reset_encoder s  z*TextIOWrapper.seek.._reset_encoderrrqrz#can't do nonzero cur-relative seeksz#can't do nonzero end-relative seeksrzunsupported whence (%r)rrz#can't restore logical file position)rgr"rrUrr`rrer?rZrVr=rGr/rprZr-rr#r!r;r-r<) rHZcookier^rvrRrtrbrjrkrlrcr@r_rArZ s`            zTextIOWrapper.seekcCs||durd}n2z |j}Wn ty@t|dYn0|}|jpT|}|dkr||j|j dd}| dd|_ |Sd}||}t ||kr|s| }|||t |7}q|SdS)Nr rrTrrF)rorr.rrGrZr]r#r?rrVr=r!re)rHr|rrr=rdr@r@rAr s,     zTextIOWrapper.readcCs(d|_|}|s$d|_|j|_t|S)NF)r>rr=rrrr@r@rAr szTextIOWrapper.__next__c Cs|jrtd|durd}n2z |j}Wn tyFt|dYn0|}|}d}|jsh|d}}|jr| d|}|dkr|d}qnt |}n|j rD| d|}| d|}|dkr|dkrt |}n |d}qnX|dkr|d}qn@||kr|d}qn(||dkr6|d}qn |d}qn(| |j }|dkrl|t |j }q|dkrt ||kr|}q| r|jrqq|jr||7}qp|d d|_|Sqp|dkr||kr|}|t |||d|S) Nrr rrr"r r r r)rgr"rr.rr]rGrZrJrxr!rIrKrer;rVr=r_) rHr|rrstartr]endposZnlposZcrposr@r@rAr st             zTextIOWrapper.readlinecCs|jr|jjSdSrP)rGrr_r@r@rArN szTextIOWrapper.newlines)NNNFF)NNNFF)N)rrFr)N)r)N)N),rLrMrNrGr`rrr2r@rrr7r8r>rAr?rSrTrjrnrprer4rgrXr+r(rrQrZrVr]r_rermrpr`rarrZrrrrr@r@r@rAr2sn * $      )    * c  K  ]r2csReZdZdZdfdd 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. rr"csftt|jtdd|d|dur(d|_|durbt|tsNtdt |j | || ddS)Nzutf-8 surrogatepass)r7r8r9Fz*initial_value must be str or None, not {0}r) rryrrrLrrrrrBrLrrZ)rHZ initial_valuer9rr@rArZ s  zStringIO.__init__c CsX||jp|}|}|z |j|jddW||S||0dS)NTr) rerGrZr*r/r#r?rr-)rHrZ old_stater@r@rArj s zStringIO.getvaluecCs t|SrP)objectrr_r@r@rArt szStringIO.__repr__cCsdSrPr@r_r@r@rAr8y szStringIO.errorscCsdSrPr@r_r@r@rAr7} szStringIO.encodingcCs|ddS)Nrr[r_r@r@rAr szStringIO.detach)rr") rLrMrNrGrrrrr8r7rrr@r@rrAryS s   ry)r r NNNTN)9rGrabcrrrsys_threadrrplatformZmsvcrtrriorrrrrraddr SEEK_DATAr)rrdev_moderhr9rBrE open_coder.rFrOrUr-r"ABCMetarVregisterr_ior'rrrr1r0rr/rrrr2ryr@r@r@rAs      [    # =   g kCiIJY@ U&