grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026U iÛfùkã@s|dZddlZddlZddlZddlZddlZddlZddlmZ ej dkrXddl m 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 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Ú)Ú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ú*/opt/alt/python38/lib64/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„Z dd„Z d8dd„Z dd„Zd9dd„Zdd„Zd:dd„Zedd „ƒZd;d!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„ZdÚ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[csz IOBase.seekcCs | dd¡S)z5Return an int indicating the current stream position.rr )r[©rIrArArBÚtellssz IOBase.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..nreadaheadcSsdS©Nr rArArArArBr~ sNrú is not an integerrrx) ÚhasattrÚ __index__r/r Ú bytearrayr"ÚreadÚendswithr)rIr}r~Ú size_indexÚresrrAr|rBÚreadline s&     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 „Zd S) Ú 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 „Zd d „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„Z e 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‡fd d „Z d"dd„Z d#dd„Z dd„Z d$dd„Z dd„Zd%dd„Zdd„Zdd„Zdd „Z‡ZS)&ÚBytesIOzêsz"FileIO.__init__..r rzKMust have exactly one of create/read/write/append mode and at most one plusrTr rrÚO_BINARYZ O_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„asz FileIO.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 z FileIO.seekcCs| ¡t |jdt¡S)zYtell() -> int. Current file position. Can raise OSError for non seekable files.r)rerrrírr`rArArBraºsz FileIO.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„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Œt d|ƒ‚t   |¡js¨d}t||ƒ‚|dkr¶d}nt |t ƒsÌt d|ƒ‚||_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¾r Trz'can't reconstruct logical file position)rrVr<r.rfr@rarEr;r9r\r"r:rkr*r-rrFr#Úrange)rIrPrr`Z next_inputrjZ saved_stateZ skip_bytesZ skip_backr{rÚdÚ start_posZ start_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.detachc sć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¡|d fˆ_ | �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.._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 r r)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 ‡Z S)Ú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Ús†      ÿ [    $ =   g hCiIJY@ U$