grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026î ¡ f¥ ã@südZddlZddlZddlZddlZyddlmZWn"ek rnddl mZYnXddl Z ddl m Z m Z m Z mZdddhZeedƒrÞejejƒejejƒndd ZeZd d dddd dd d „ZGdd„dƒZGdd„dƒZy e jZWn+ek rpGdd„deeƒZYnXGdd„ddejƒZe jjeƒGdd„deƒZ e j je ƒddl!m"Z"e je"ƒGdd„deƒZ#e j#je#ƒGdd„de#ƒZ$Gdd„de#ƒ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*e j*je*ƒGd*d+„d+ej+ƒZ,Gd,d-„d-e*ƒZ-Gd.d/„d/e-ƒZ.dS)0z) Python implementation of the io module. éN)Ú allocate_lock)Ú__all__ÚSEEK_SETÚSEEK_CURÚSEEK_ENDééÚ SEEK_HOLEéiÚrTcCsŒt|tttfƒs+td|ƒ‚nt|tƒsMtd|ƒ‚nt|tƒsotd|ƒ‚n|dk ržt|tƒ ržtd|ƒ‚n|dk rÍt|tƒ rÍtd|ƒ‚nt|ƒ}|tdƒst|ƒt|ƒkrtd|ƒ‚nd|k} d |k} d |k} d |k} d |k} d |k}d|k}d|kr½| s†| s†| r•tdƒ‚nddl}|j dt dƒd} n|rØ|rØtdƒ‚n| | | | dkrÿtdƒ‚n| p| p| p| s&tdƒ‚n|rG|dk rGtdƒ‚n|rh|dk rhtdƒ‚n|r‰|dk r‰tdƒ‚nt || r›dpžd| rªd p­d| rºd p½d| rÊd pÍd| rÚd pÝd|d|ƒ}|}y}d}|dks |dkr/|j ƒr/d"}d}n|dkr�t }ytj|jƒƒj}Wnttfk rwYq�X|dkr�|}q�n|dkr«tdƒ‚n|dkrÐ|rÁ|Std ƒ‚n| rèt||ƒ}nL| sú| sú| r t||ƒ}n(| r$t||ƒ}ntd!|ƒ‚|}|rD|St|||||ƒ}|}||_|SWn|jƒ‚YnXdS)#aÀOpen file and return a stream. Raise OSError upon failure. file is either a text or byte string giving the name (and the path if the file isn't in the current working directory) of the file to be opened or an integer file descriptor of the file to be wrapped. (If a file descriptor is given, it is closed when the returned I/O object is closed, unless closefd is set to False.) mode is an optional string that specifies the mode in which the file is opened. It defaults to 'r' which means open for reading in text mode. Other common values are 'w' for writing (truncating the file if it already exists), 'x' for exclusive creation of a new file, and 'a' for appending (which on some Unix systems, means that all writes append to the end of the file regardless of the current seek position). In text mode, if encoding is not specified the encoding used is platform dependent. (For reading and writing raw bytes use binary mode and leave encoding unspecified.) The available modes are: ========= =============================================================== Character Meaning --------- --------------------------------------------------------------- 'r' open for reading (default) 'w' open for writing, truncating the file first 'x' create a new file and open it for writing 'a' open for writing, appending to the end of the file if it exists 'b' binary mode 't' text mode (default) '+' open a disk file for updating (reading and writing) 'U' universal newline mode (deprecated) ========= =============================================================== The default mode is 'rt' (open for reading text). For binary random access, the mode 'w+b' opens and truncates the file to 0 bytes, while 'r+b' opens the file without truncation. The 'x' mode implies 'w' and raises an `FileExistsError` if the file already exists. Python distinguishes between files opened in binary and text modes, even when the underlying operating system doesn't. Files opened in binary mode (appending 'b' to the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when 't' is appended to the mode argument), the contents of the file are returned as strings, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given. 'U' mode is deprecated and will raise an exception in future versions of Python. It has no effect in Python 3. Use newline to control universal newlines mode. buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows: * Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device's "block size" and falling back on `io.DEFAULT_BUFFER_SIZE`. On many systems, the buffer will typically be 4096 or 8192 bytes long. * "Interactive" text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files. encoding is the str name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings. errors is an optional string that specifies how encoding errors are to be handled---this argument should not be used in binary mode. Pass 'strict' to raise a ValueError exception if there is an encoding error (the default of None has the same effect), or pass 'ignore' to ignore errors. (Note that ignoring encoding errors can lead to data loss.) See the documentation for codecs.register for a list of the permitted encoding error strings. newline is a string controlling how universal newlines works (it only applies to text mode). It can be None, '', '\n', '\r', and '\r\n'. It works as follows: * On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in '\n', '\r', or '\r\n', and these are translated into '\n' before being returned to the caller. If it is '', universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated. * On output, if newline is None, any '\n' characters written are translated to the system default line separator, os.linesep. If newline is '', no translation takes place. If newline is any of the other legal values, any '\n' characters written are translated to the given string. closedfd is a bool. If closefd is False, the underlying file descriptor will be kept open when the file is closed. This does not work when a file name is given and must be True in that case. The newly created file is non-inheritable. A custom opener can be used by passing a callable as *opener*. The underlying file descriptor for the file object is then obtained by calling *opener* with (*file*, *flags*). *opener* must return an open file descriptor (passing os.open as *opener* results in functionality similar to passing None). open() returns a file object whose type depends on the mode, and through which the standard file operations such as reading and writing are performed. When open() is used to open a file in a text mode ('w', 'r', 'wt', 'rt', etc.), it returns a TextIOWrapper. When used to open a file in a binary mode, the returned class varies: in read binary mode, it returns a BufferedReader; in write binary and append binary modes, it returns a BufferedWriter, and in read/write mode, it returns a BufferedRandom. It is also possible to use a string or bytearray as a file for both reading and writing. For strings StringIO can be used like a file opened in a text mode, and for bytes a BytesIO can be used like a file opened in a binary mode. zinvalid file: %rzinvalid mode: %rzinvalid buffering: %rNzinvalid encoding: %rzinvalid errors: %rzaxrwb+tUÚxr ÚwÚaú+ÚtÚbÚUz$can't use U and writing mode at oncerz'U' mode is deprecatedrTz'can't have text and binary mode at oncerz)can't have read/write/append mode at oncez/must have exactly one of read/write/append modez-binary mode doesn't take an encoding argumentz+binary mode doesn't take an errors argumentz+binary mode doesn't take a newline argumentÚÚopenerFzinvalid buffering sizezcan't have unbuffered text I/Ozunknown mode: %réÿÿÿÿ)Ú isinstanceÚstrÚbytesÚintÚ TypeErrorÚsetÚlenÚ ValueErrorÚwarningsÚwarnÚDeprecationWarningÚFileIOÚisattyÚDEFAULT_BUFFER_SIZEÚosÚfstatÚfilenoÚ st_blksizeÚOSErrorÚAttributeErrorÚBufferedRandomÚBufferedWriterÚBufferedReaderÚ TextIOWrapperÚmodeÚclose)Úfiler.Ú bufferingÚencodingÚerrorsÚnewlineÚclosefdrZmodesZcreatingZreadingZwritingZ appendingZupdatingÚtextZbinaryrÚrawÚresultÚline_bufferingZbsÚbuffer©r;ú*/opt/alt/python34/lib64/python3.4/_pyio.pyÚopen"s { (             ?$        r=c@s"eZdZdZdd„ZdS)Ú 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__)ÚselfÚobjÚtypr;r;r<Ú__get__÷szDocDescriptor.__get__N)Ú__name__Ú __module__Ú __qualname__r?rCr;r;r;r<r>ôs r>c@s+eZdZdZeƒ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/pythonrun.c. cOs t||ŽS)N)r=)ÚclsÚargsÚkwargsr;r;r<Ú__new__szOpenWrapper.__new__N)rDrErFr?r>rKr;r;r;r<rGýs  rGc@seZdZdS)ÚUnsupportedOperationN)rDrErFr;r;r;r<rLs rLc@sZeZdZdZdd„Zddd„Zdd„Zd d d „Zd d „ZdZ dd„Z dd„Z dd„Z d dd„Z dd„Zd dd„Zdd„Zd dd„Zedd „ƒZd d!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd6d,d-„Zd.d/„Zd0d1„Zd d2d3„Zd4d5„Zd S)7ÚIOBasea-The abstract base class for all I/O classes, acting on streams of bytes. There is no public constructor. This class provides dummy implementations for many methods that derived classes can override selectively; the default implementations represent a file that cannot be read, written or seeked. Even though IOBase does not declare read, readinto, or write because their signatures will vary, implementations and clients should consider those methods part of the interface. Also, implementations may raise UnsupportedOperation when operations they do not support are called. The basic type used for binary data read from or written to a file is bytes. bytearrays are accepted too, and in some cases (such as readinto) needed. 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!') cCs td|jj|fƒ‚dS)z@Internal: raise an OSError exception for unsupported operations.z%s.%s() not supportedN)rLÚ __class__rD)r@Únamer;r;r<Ú _unsupported7szIOBase._unsupportedrcCs|jdƒdS)a$Change stream position. Change the stream position to byte offset pos. Argument pos is interpreted relative to the position indicated by whence. Values for whence are ints: * 0 -- start of stream (the default); offset should be zero or positive * 1 -- current stream position; offset may be negative * 2 -- end of stream; offset is usually negative Some operating systems / file systems could provide additional values. Return an int indicating the new absolute position. ÚseekN)rP)r@ÚposÚwhencer;r;r<rQ>sz IOBase.seekcCs|jddƒS)z5Return an int indicating the current stream position.rr)rQ)r@r;r;r<ÚtellNsz IOBase.tellNcCs|jdƒdS)zŒTruncate file to size bytes. Size defaults to the current IO position as reported by tell(). Return the new size. ÚtruncateN)rP)r@rRr;r;r<rURszIOBase.truncatecCs|jƒdS)zuFlush write buffers, if applicable. This is not implemented for read-only and non-blocking streams. N)Ú _checkClosed)r@r;r;r<Úflush\sz IOBase.flushFc Cs+|js'z|jƒWdd|_XndS)ziFlush and close the IO object. This method has no effect if the file is already closed. NT)Ú_IOBase__closedrW)r@r;r;r<r/fs z IOBase.closec Csy|jƒWnYnXdS)zDestructor. Calls close().N)r/)r@r;r;r<Ú__del__qszIOBase.__del__cCsdS)zÌReturn a bool indicating whether object supports random access. If False, seek(), tell() and truncate() will raise UnsupportedOperation. This method may need to do a test seek(). Fr;)r@r;r;r<ÚseekableszIOBase.seekablecCs1|jƒs-t|dkr!dn|ƒ‚ndS)zEInternal: raise UnsupportedOperation if file is not seekable NzFile or stream is not seekable.)rZrL)r@Úmsgr;r;r<Ú_checkSeekable‡s zIOBase._checkSeekablecCsdS)zƒReturn a bool indicating whether object was opened for reading. If False, read() will raise UnsupportedOperation. Fr;)r@r;r;r<ÚreadableŽszIOBase.readablecCs1|jƒs-t|dkr!dn|ƒ‚ndS)zEInternal: raise UnsupportedOperation if file is not readable NzFile or stream is not readable.)r]rL)r@r[r;r;r<Ú_checkReadable•s zIOBase._checkReadablecCsdS)z“Return a bool indicating whether object was opened for writing. If False, write() and truncate() will raise UnsupportedOperation. Fr;)r@r;r;r<ÚwritableœszIOBase.writablecCs1|jƒs-t|dkr!dn|ƒ‚ndS)zEInternal: raise UnsupportedOperation if file is not writable NzFile or stream is not writable.)r_rL)r@r[r;r;r<Ú_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. )rX)r@r;r;r<Úclosedªsz IOBase.closedcCs.|jr*t|dkrdn|ƒ‚ndS)z8Internal: raise an ValueError if file is closed NzI/O operation on closed file.)rar)r@r[r;r;r<rV²s zIOBase._checkClosedcCs|jƒ|S)zCContext management protocol. Returns self (an instance of IOBase).)rV)r@r;r;r<Ú __enter__»s zIOBase.__enter__cGs|jƒdS)z+Context management protocol. Calls close()N)r/)r@rIr;r;r<Ú__exit__ÀszIOBase.__exit__cCs|jdƒdS)z’Returns underlying file descriptor (an int) if one exists. An OSError is raised if the IO object does not use a file descriptor. r&N)rP)r@r;r;r<r&Èsz IOBase.filenocCs|jƒdS)z{Return a bool indicating whether this is an 'interactive' stream. Return False if it can't be determined. F)rV)r@r;r;r<r"Ïs z IOBase.isattyrcs×tˆdƒr'‡‡fdd†}n dd„}ˆdkrHd ‰ntˆtƒsftdƒ‚ntƒ}x[ˆdks�t|ƒˆkr̈j|ƒƒ}|s¬Pn||7}|jd ƒrrPqrqrWt|ƒ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. ÚpeekcsZˆjdƒ}|sdS|jdƒdp5t|ƒ}ˆdkrVt|ˆƒ}n|S)Nrs r)rdÚfindrÚmin)Z readaheadÚn)r@Úsizer;r<Ú nreadaheadås z#IOBase.readline..nreadaheadcSsdS)Nrr;r;r;r;r<riîsNrzsize must be an integerrs r) ÚhasattrrrrÚ bytearrayrÚreadÚendswithr)r@rhriÚresrr;)r@rhr<ÚreadlineÙs     ! zIOBase.readlinecCs|jƒ|S)N)rV)r@r;r;r<Ú__iter__þs zIOBase.__iter__cCs|jƒ}|st‚n|S)N)roÚ StopIteration)r@Úliner;r;r<Ú__next__s  zIOBase.__next__cCsp|dks|dkr"t|ƒSd}g}x;|D]3}|j|ƒ|t|ƒ7}||kr5Pq5q5W|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)r@ZhintrgÚlinesrrr;r;r<Ú readliness    zIOBase.readlinescCs,|jƒx|D]}|j|ƒqWdS)N)rVÚwrite)r@rvrrr;r;r<Ú writeliness  zIOBase.writelinesr)rDrErFr?rPrQrTrUrWrXr/rYrZr\r]r^r_r`ÚpropertyrarVrbrcr&r"rorprsrwryr;r;r;r<rMs4            %  rMÚ metaclassc@sIeZdZdZd dd„Zdd„Zdd„Zd d „Zd S) Ú RawIOBasezBase class for raw binary I/O.rcCss|dkrd}n|dkr+|jƒSt|jƒƒ}|j|ƒ}|dkr\dS||d…=t|ƒS)zºRead and return up to size bytes, where size is an int. Returns an empty bytes object on EOF, or None if the object is set not to block and has no data to read. Nrrr)ÚreadallrkÚ __index__Úreadintor)r@rhrrgr;r;r<rl0s      zRawIOBase.readcCsKtƒ}x'|jtƒ}|s%Pn||7}q W|rCt|ƒS|SdS)z+Read until EOF, using multiple read() call.N)rkrlr#r)r@rnÚdatar;r;r<r}As  zRawIOBase.readallcCs|jdƒdS)zÈRead up to len(b) bytes into bytearray 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)rP)r@rr;r;r<rOszRawIOBase.readintocCs|jdƒdS)z~Write the given buffer to the IO stream. Returns the number of bytes written, which may be less than len(b). rxN)rP)r@rr;r;r<rxWszRawIOBase.writeNr)rDrErFr?rlr}rrxr;r;r;r<r|"s    r|)r!c@sXeZdZdZddd„Zddd„Zdd„Zd d „Zd d „ZdS) ÚBufferedIOBaseaBase class for buffered IO objects. The main difference with RawIOBase is that the read() method supports omitting the size argument, and does not have a default implementation that defers to readinto(). In addition, read(), readinto() and write() may raise BlockingIOError if the underlying raw stream is in non-blocking mode and not ready; unlike their raw counterparts, they will never return None. A typical implementation should not inherit from a RawIOBase implementation, but wrap one. NcCs|jdƒdS)a¤Read and return up to size bytes, where size is an int. If the argument is omitted, None, or negative, reads and returns all data until EOF. If the argument is positive, and the underlying raw stream is not 'interactive', multiple raw reads may be issued to satisfy the byte count (unless EOF is reached first). But for interactive raw streams (XXX and for pipes?), at most one raw read will be issued, and a short result does not imply that EOF is imminent. Returns an empty bytes array on EOF. Raises BlockingIOError if the underlying raw stream has no data at the moment. rlN)rP)r@rhr;r;r<rltszBufferedIOBase.readcCs|jdƒdS)zaRead up to size bytes with at most one read() system call, where size is an int. Úread1N)rP)r@rhr;r;r<r‚ˆszBufferedIOBase.read1cCs¤|jt|ƒƒ}t|ƒ}y||d|…|jdkrtdƒ‚n|jƒ|j}d|_|S)Nzraw stream already detached)r7rrWr‡)r@r7r;r;r<r…ñs    z_BufferedIOMixin.detachcCs |jjƒS)N)r7rZ)r@r;r;r<rZûsz_BufferedIOMixin.seekablecCs |jjƒS)N)r7r])r@r;r;r<r]þsz_BufferedIOMixin.readablecCs |jjƒS)N)r7r_)r@r;r;r<r_sz_BufferedIOMixin.writablecCs|jS)N)r‡)r@r;r;r<r7sz_BufferedIOMixin.rawcCs |jjS)N)r7ra)r@r;r;r<rasz_BufferedIOMixin.closedcCs |jjS)N)r7rO)r@r;r;r<rO sz_BufferedIOMixin.namecCs |jjS)N)r7r.)r@r;r;r<r.sz_BufferedIOMixin.modecCstdj|jjƒƒ‚dS)Nz can not serialize a '{0}' object)rÚformatrNrD)r@r;r;r<Ú __getstate__s z_BufferedIOMixin.__getstate__c CsO|jj}y |j}Wntk r:dj|ƒSYnXdj||ƒSdS)Nz <_pyio.{0}>z<_pyio.{0} name={1!r}>)rNrDrOÚ Exceptionr‰)r@ZclsnamerOr;r;r<Ú__repr__s    z_BufferedIOMixin.__repr__cCs |jjƒS)N)r7r&)r@r;r;r<r&#sz_BufferedIOMixin.filenocCs |jjƒS)N)r7r")r@r;r;r<r"&sz_BufferedIOMixin.isatty)rDrErFr?rˆrQrTrUrWr/r…rZr]r_rzr7rarOr.rŠrŒr&r"r;r;r;r<r†¼s&          r†csÐeZdZdZddd„Zdd„Zdd„Zd d „Z‡fd d †Zdd d„Z dd„Z dd„Z ddd„Z dd„Z ddd„Zdd„Zdd„Zdd„Z‡S) ÚBytesIOzt|jƒ|j}||8}|jd|j…|_t |j |j |ƒ‚nWYdd}~XqTXn|SWdQXdS)Nzwrite to closed filez can't write str to binary stream)rarrrrr¨rr§ršÚ_flush_unlockedÚextendÚBlockingIOErrorÚerrnoÚstrerror)r@rZbeforeZwrittenÚeZoverager;r;r<rxSs(    1zBufferedWriter.writeNc CsL|j�=|jƒ|dkr2|jjƒ}n|jj|ƒSWdQXdS)N)r¨r©r7rTrU)r@rRr;r;r<rUos    zBufferedWriter.truncatecCs|j�|jƒWdQXdS)N)r¨r©)r@r;r;r<rWvs zBufferedWriter.flushc CsÞ|jrtdƒ‚nx¿|jrÙy|jj|jƒ}Wn2tk rTwYntk rqtdƒ‚YnX|dkr–ttj ddƒ‚n|t |jƒks·|dkrÆt dƒ‚n|jd|…=qWdS)Nzflush of closed filezHself.raw should implement RawIOBase: it should not raise BlockingIOErrorz)write could not complete without blockingrz*write() returned incorrect number of bytes) rarr§r7rxr¡r«Ú RuntimeErrorr¬ZEAGAINrr()r@rgr;r;r<r©zs      !zBufferedWriter._flush_unlockedcCstj|ƒt|jƒS)N)r†rTrr§)r@r;r;r<rT�szBufferedWriter.tellrc CsL|tkrtdƒ‚n|j�"|jƒtj|||ƒSWdQXdS)Nzinvalid whence value)r¦rr¨r©r†rQ)r@rRrSr;r;r<rQ�s    zBufferedWriter.seek) rDrErFr?r#rˆrxrUrWr©rTrQr;r;r;r<r+?s     r+c@sµeZdZdZedd„Zddd„Zdd„Zd d „Zd d d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zedd„ƒZdS)ÚBufferedRWPaira“A buffered reader and writer object together. A buffered reader object and buffered writer object put together to form a sequential IO object that can read and write. This is typically used with a socket or two-way pipe. reader and writer are RawIOBase objects that are readable and writeable respectively. If the buffer_size is omitted it defaults to DEFAULT_BUFFER_SIZE. cCs^|jƒstdƒ‚n|jƒs6tdƒ‚nt||ƒ|_t||ƒ|_dS)zEConstructor. The arguments are two RawIO instances. z#"reader" argument must be readable.z#"writer" argument must be writable.N)r]r(r_r,Úreaderr+Úwriter)r@r±r²ršr;r;r<rˆ¨s   zBufferedRWPair.__init__NcCs%|dkrd}n|jj|ƒS)Nrr)r±rl)r@rhr;r;r<rl¶s  zBufferedRWPair.readcCs|jj|ƒS)N)r±r)r@rr;r;r<r»szBufferedRWPair.readintocCs|jj|ƒS)N)r²rx)r@rr;r;r<rx¾szBufferedRWPair.writercCs|jj|ƒS)N)r±rd)r@rhr;r;r<rdÁszBufferedRWPair.peekcCs|jj|ƒS)N)r±r‚)r@rhr;r;r<r‚ÄszBufferedRWPair.read1cCs |jjƒS)N)r±r])r@r;r;r<r]ÇszBufferedRWPair.readablecCs |jjƒS)N)r²r_)r@r;r;r<r_ÊszBufferedRWPair.writablecCs |jjƒS)N)r²rW)r@r;r;r<rWÍszBufferedRWPair.flushc Cs&z|jjƒWd|jjƒXdS)N)r²r/r±)r@r;r;r<r/ÐszBufferedRWPair.closecCs|jjƒp|jjƒS)N)r±r"r²)r@r;r;r<r"ÖszBufferedRWPair.isattycCs |jjS)N)r²ra)r@r;r;r<raÙszBufferedRWPair.closed)rDrErFr?r#rˆrlrrxrdr‚r]r_rWr/r"rzrar;r;r;r<r°˜s         r°c@s‘eZdZdZedd„Zddd„Zdd„Zd d d „Zd d d „Z dd„Z ddd„Z dd„Z dd„Z d S)r*zçA buffered interface to random access streams. The constructor creates a reader and writer for a seekable stream, raw, given in the first argument. If the buffer_size is omitted it defaults to DEFAULT_BUFFER_SIZE. cCs4|jƒtj|||ƒtj|||ƒdS)N)r\r,rˆr+)r@r7ršr;r;r<rˆçs zBufferedRandom.__init__rcCs²|tkrtdƒ‚n|jƒ|jrd|j�(|jj|jt|jƒdƒWdQXn|jj||ƒ}|j�|j ƒWdQX|dkr®t dƒ‚n|S)Nzinvalid whence valuerrz seek() returned invalid position) r¦rrWržr�r7rQrŸrr›r()r@rRrSr;r;r<rQìs    ,  zBufferedRandom.seekcCs'|jrtj|ƒStj|ƒSdS)N)r§r+rTr,)r@r;r;r<rTýs  zBufferedRandom.tellNcCs+|dkr|jƒ}ntj||ƒS)N)rTr+rU)r@rRr;r;r<rUs zBufferedRandom.truncatecCs/|dkrd}n|jƒtj||ƒS)Nrr)rWr,rl)r@rhr;r;r<rl s   zBufferedRandom.readcCs|jƒtj||ƒS)N)rWr,r)r@rr;r;r<rs zBufferedRandom.readintocCs|jƒtj||ƒS)N)rWr,rd)r@rhr;r;r<rds zBufferedRandom.peekcCs|jƒtj||ƒS)N)rWr,r‚)r@rhr;r;r<r‚s zBufferedRandom.read1c CsY|jrI|j�2|jj|jt|jƒdƒ|jƒWdQXntj||ƒS)Nr) ržr�r7rQrŸrr›r+rx)r@rr;r;r<rxs   #zBufferedRandom.write)rDrErFr?r#rˆrQrTrUrlrrdr‚rxr;r;r;r<r*Þs    r*c@sŽeZdZdZddd„Zdd„Zddd „Zd d „Zd d „Ze dd„ƒZ e dd„ƒZ e dd„ƒZ dS)Ú TextIOBasezàBase class for text I/O. This class provides a character and line based interface to stream I/O. There is no readinto method because Python's character strings are immutable. There is no public constructor. rcCs|jdƒdS)zíRead at most size characters from stream, where size is an int. Read from underlying buffer until we have size characters or we hit EOF. If size is negative or omitted, read until EOF. Returns a string. rlN)rP)r@rhr;r;r<rl-szTextIOBase.readcCs|jdƒdS)z.Write string s to stream and returning an int.rxN)rP)r@Úsr;r;r<rx7szTextIOBase.writeNcCs|jdƒdS)z*Truncate size to pos, where pos is an int.rUN)rP)r@rRr;r;r<rU;szTextIOBase.truncatecCs|jdƒdS)z_Read until newline or EOF. Returns an empty string if EOF is hit immediately. roN)rP)r@r;r;r<ro?szTextIOBase.readlinecCs|jdƒdS)z· Separate the underlying buffer from the TextIOBase and return it. After the underlying buffer has been detached, the TextIO is in an unusable state. r…N)rP)r@r;r;r<r…FszTextIOBase.detachcCsdS)zSubclasses should override.Nr;)r@r;r;r<r2OszTextIOBase.encodingcCsdS)z’Line endings translated so far. Only line endings translated during reading are considered. Subclasses should override. Nr;)r@r;r;r<ÚnewlinesTszTextIOBase.newlinescCsdS)zMError setting of the decoder or encoder. Subclasses should override.Nr;)r@r;r;r<r3^szTextIOBase.errorsr) rDrErFr?rlrxrUror…rzr2rµr3r;r;r;r<r³$s     r³c@s|eZdZdZddd„Zddd„Zdd „Zd d „Zd d „ZdZ dZ dZ e dd„ƒZ dS)ÚIncrementalNewlineDecodera+Codec used when reading a file in universal newlines mode. It wraps another incremental decoder, translating \r\n and \r into \n. It also records the types of newlines encountered. When used with translate=False, it ensures that the newline sequence is returned in one piece. ÚstrictcCs>tjj|d|ƒ||_||_d|_d|_dS)Nr3rF)ÚcodecsÚIncrementalDecoderrˆÚ translateÚdecoderÚseennlÚ pendingcr)r@r»rºr3r;r;r<rˆos    z"IncrementalNewlineDecoder.__init__FcCs:|jdkr|}n|jj|d|ƒ}|jr[|sE|r[d|}d|_n|jdƒr�| r�|dd…}d|_n|jdƒ}|jdƒ|}|jdƒ|}|j|oÕ|j|oá|jB|oî|jBO_|j r6|r|j ddƒ}n|r6|j ddƒ}q6n|S) NÚfinalú FrTz Ú r) r»Údecoder½rmÚcountr¼Ú_LFÚ_CRÚ_CRLFrºÚreplace)r@Úinputr¾ÚoutputZcrlfZcrZlfr;r;r<rÁvs(    + z IncrementalNewlineDecoder.decodecCs]|jdkrd}d}n|jjƒ\}}|dK}|jrS|dO}n||fS)Nr˜rr)r»Úgetstater½)r@r�Úflagr;r;r<rÉ•s    z"IncrementalNewlineDecoder.getstatecCsO|\}}t|d@ƒ|_|jdk rK|jj||d?fƒndS)Nr)Úboolr½r»Úsetstate)r@Ústater�rÊr;r;r<rÌ s z"IncrementalNewlineDecoder.setstatecCs5d|_d|_|jdk r1|jjƒndS)NrF)r¼r½r»Úreset)r@r;r;r<rΦs  zIncrementalNewlineDecoder.resetrréc Cs d|jS) NrÀr¿ú ©r¿rÀ©rÀrЩr¿rЩr¿rÀrÐ)NrÀr¿rÑrÐrÒrÓrÔ)r¼)r@r;r;r<rµ°sz"IncrementalNewlineDecoder.newlinesN)rDrErFr?rˆrÁrÉrÌrÎrÃrÄrÅrzrµr;r;r;r<r¶hs   r¶c@sðeZdZdZdZddddddd„Zdd„Zed d „ƒZed d „ƒZ ed d„ƒZ edd„ƒZ dd„Z dd„Z dd„Zdd„Zdd„Zedd„ƒZedd„ƒZdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zdd+d,„Zd-d.„Zd/d0„Zd1d1d1d1d2d3„Zd4d5„Zd6d7„Zdd8d9„Zd:d;„Z d1d<d=„Z!dd>d?„Z"d@dA„Z#ddBdC„Z$edDdE„ƒZ%dS)Fr-aCharacter and line based layer over a BufferedIOBase object, buffer. encoding gives the name of the encoding that the stream will be decoded or encoded with. It defaults to locale.getpreferredencoding(False). errors determines the strictness of encoding and decoding (see the codecs.register) and defaults to "strict". newline can be None, '', '\n', '\r', or '\r\n'. It controls the handling of line endings. If it is None, universal newlines is enabled. With this enabled, on input, the lines endings '\n', '\r', or '\r\n' are translated to '\n' before being returned to the caller. Conversely, on output, '\n' is translated to the system default line separator, os.linesep. If newline is any other of its legal values, that newline becomes the newline when the file is read and it is returned untranslated. On output, '\n' is converted to the newline. If line_buffering is True, a call to flush is implied when a call to write contains a newline character. iNFc Cs›|dk r8t|tƒ r8tdt|ƒfƒ‚n|dkrZtd|fƒ‚n|dkræytj|jƒƒ}Wntt fk r™YnX|dkræyddl }Wnt k rÐd}YqãX|j d ƒ}qænt|tƒstd |ƒ‚nt j|ƒjs3d }t||ƒ‚n|dkrHd }n"t|tƒsjtd |ƒ‚n||_||_||_||_| |_|dk|_||_|dk|_|pËtj|_d|_d|_d|_d|_d|_|j j!ƒ|_"|_#t$|j dƒ|_%d|_&|j"r—|j'ƒr—|j j(ƒ} | dkr—y|j)ƒj*dƒWq”tk r�Yq”Xq—ndS)Nzillegal newline type: %rrrÀr¿ú zillegal newline value: %rrÚasciiFzinvalid encoding: %rzG%r is not a text encoding; use codecs.open() to handle arbitrary codecsr·zinvalid errors: %rr‚g)NrrÀr¿rÕ)+rrrÚtyperr$Údevice_encodingr&r)rLÚlocaleÚ ImportErrorÚgetpreferredencodingr¸ÚlookupÚ_is_text_encodingÚ LookupErrorrŽÚ_line_bufferingÚ _encodingÚ_errorsÚ_readuniversalÚ_readtranslateÚ_readnlÚ_writetranslateÚlinesepÚ_writenlÚ_encoderÚ_decoderÚ_decoded_charsÚ_decoded_chars_usedÚ _snapshotr:rZÚ _seekableÚ_tellingrjÚ _has_read1Ú _b2cratior_rTÚ _get_encoderrÌ) r@r:r2r3r4r9Z write_throughrÙr[Úpositionr;r;r<rˆÚs`                     zTextIOWrapper.__init__cCs„d}y |j}Wntk r'YnX|dj|ƒ7}y |j}Wntk r\YnX|dj|ƒ7}|dj|jƒS)Nz<_pyio.TextIOWrapperz name={0!r}z mode={0!r}z encoding={0!r}>)rOr‹r‰r.r2)r@r8rOr.r;r;r<rŒ s    zTextIOWrapper.__repr__cCs|jS)N)rà)r@r;r;r<r20szTextIOWrapper.encodingcCs|jS)N)rá)r@r;r;r<r34szTextIOWrapper.errorscCs|jS)N)rß)r@r;r;r<r98szTextIOWrapper.line_bufferingcCs|jS)N)rŽ)r@r;r;r<r:<szTextIOWrapper.buffercCs|jrtdƒ‚n|jS)NzI/O operation on closed file.)rarrí)r@r;r;r<rZ@s zTextIOWrapper.seekablecCs |jjƒS)N)r:r])r@r;r;r<r]EszTextIOWrapper.readablecCs |jjƒS)N)r:r_)r@r;r;r<r_HszTextIOWrapper.writablecCs|jjƒ|j|_dS)N)r:rWrírî)r@r;r;r<rWKs zTextIOWrapper.flushc Cs?|jdk r;|j r;z|jƒWd|jjƒXndS)N)r:rarWr/)r@r;r;r<r/OszTextIOWrapper.closecCs |jjS)N)r:ra)r@r;r;r<raVszTextIOWrapper.closedcCs |jjS)N)r:rO)r@r;r;r<rOZszTextIOWrapper.namecCs |jjƒS)N)r:r&)r@r;r;r<r&^szTextIOWrapper.filenocCs |jjƒS)N)r:r")r@r;r;r<r"aszTextIOWrapper.isattycCs"|jrtdƒ‚nt|tƒs@td|jjƒ‚nt|ƒ}|js^|j ogd|k}|r |jr |j dkr |j d|j ƒ}n|j p²|j ƒ}|j|ƒ}|jj|ƒ|j rü|sïd|krü|jƒnd|_|jr|jjƒn|S)zWrite data, where s is a strzwrite to closed filezcan't write %s to text streamrÀr¿N)rarrrrrNrDrrårßrçrÆrèrñÚencoder:rxrWrìrérÎ)r@r´ZlengthZhaslfÚencoderrr;r;r<rxds$     zTextIOWrapper.writecCs+tj|jƒ}||jƒ|_|jS)N)r¸Úgetincrementalencoderràrárè)r@Z make_encoderr;r;r<rñzszTextIOWrapper._get_encodercCsLtj|jƒ}||jƒ}|jr?t||jƒ}n||_|S)N)r¸Úgetincrementaldecoderràrárâr¶rãré)r@Z make_decoderr»r;r;r<Ú _get_decoders   zTextIOWrapper._get_decodercCs||_d|_dS)zSet the _decoded_chars buffer.rN)rêrë)r@Úcharsr;r;r<Ú_set_decoded_charsŠs z TextIOWrapper._set_decoded_charscCs[|j}|dkr+|j|d…}n|j|||…}|jt|ƒ7_|S)z'Advance into the _decoded_chars buffer.N)rërêr)r@rgÚoffsetrør;r;r<Ú_get_decoded_chars�s   z TextIOWrapper._get_decoded_charscCs1|j|krtdƒ‚n|j|8_dS)z!Rewind the _decoded_chars buffer.z"rewind decoded_chars out of boundsN)rëÚAssertionError)r@rgr;r;r<Ú_rewind_decoded_chars™sz#TextIOWrapper._rewind_decoded_charscCsð|jdkrtdƒ‚n|jr?|jjƒ\}}n|jr`|jj|jƒ}n|jj|jƒ}| }|jj ||ƒ}|j |ƒ|rÃt |ƒt |j ƒ|_ n d|_ |jrë|||f|_n| S)zQ Read and decode the next chunk of data from the BufferedReader. Nz no decoderg)rérrîrÉrïr:r‚Ú _CHUNK_SIZErlrÁrùrrêrðrì)r@Ú dec_bufferÚ dec_flagsÚ input_chunkÚeofZ decoded_charsr;r;r<Ú _read_chunkŸs      zTextIOWrapper._read_chunkrcCs*||d>B|d>B|d>Bt|ƒd>BS)Né@é€éÀé)rË)r@ròrÚ bytes_to_feedÚneed_eofÚ chars_to_skipr;r;r<Ú _pack_cookieÉszTextIOWrapper._pack_cookiecCsgt|dƒ\}}t|dƒ\}}t|dƒ\}}t|dƒ\}}|||||fS)Nrrllll)Údivmod)r@ZbigintÚrestròrrr r r;r;r<Ú_unpack_cookieÓs zTextIOWrapper._unpack_cookiecCs.|jstdƒ‚n|js0tdƒ‚n|jƒ|jjƒ}|j}|dksm|jdkr‰|j r…t dƒ‚n|S|j\}}|t |ƒ8}|j }|dkrÍ|j ||ƒS|jƒ}z@t|j|ƒ}d}|t |ƒks t ‚xÀ|dkr¶|jd|fƒt |j|d|…ƒƒ} | |krŸ|jƒ\} } | s†| }|| 8}Pn|t | ƒ8}d}q||8}|d}qWd}|jd|fƒ||} |} |dkrü|j | | ƒSd}d}d}xît|t |ƒƒD]—}|d7}|t |j|||d…ƒƒ7}|jƒ\}}| r«||kr«| |7} ||8}|dd} }}n||kr$Pq$q$W|t |jddd ƒƒ7}d}||krÿtd ƒ‚n|j | | |||ƒSWd|j|ƒXdS) Nz!underlying stream is not seekablez(telling position disabled by next() callzpending decoded textrrr˜rr¾Tz'can't reconstruct logical file position)rírLrîr(rWr:rTrérìrêrürrër rÉrrðrÌrÁÚrange)r@ròr»rZ next_inputr Z saved_stateZ skip_bytesZ skip_backrgrÚdÚ start_posZ start_flagsZ bytes_fedr Z chars_decodedÚirÿr;r;r<rTÚsx               '    zTextIOWrapper.tellcCs5|jƒ|dkr%|jƒ}n|jj|ƒS)N)rWrTr:rU)r@rRr;r;r<rU=s  zTextIOWrapper.truncatecCs>|jdkrtdƒ‚n|jƒ|j}d|_|S)Nzbuffer is already detached)r:rrWrŽ)r@r:r;r;r<r…Cs    zTextIOWrapper.detachc sއfdd†}ˆjr*tdƒ‚nˆjsBtdƒ‚n|dkr~|dkritdƒ‚nd}ˆjƒ}n|dkr|dkr¥td ƒ‚nˆjƒˆjjddƒ}ˆjd ƒdˆ_ ˆj róˆj j ƒn||ƒ|S|dkr#td |fƒ‚n|dkrEtd |fƒ‚nˆjƒˆj |ƒ\}}}}} ˆjj|ƒˆjd ƒdˆ_ |dkr¸ˆj r¸ˆj j ƒnUˆj sÍ|sÍ| r ˆj p߈j ƒˆ_ ˆj jd |fƒ|d fˆ_ n| r€ˆjj|ƒ} ˆjˆj j| |ƒƒ|| fˆ_ tˆjƒ| krttdƒ‚n| ˆ_n||ƒ|S)Nc sXyˆjpˆjƒ}Wntk r-Yn'X|dkrJ|jdƒn |jƒdS)z9Reset the encoder (merely useful for proper BOM handling)rN)rèrñrÞrÌrÎ)ròrô)r@r;r<Ú_reset_encoderLs  z*TextIOWrapper.seek.._reset_encoderztell on closed filez!underlying stream is not seekablerrz#can't do nonzero cur-relative seeksrz#can't do nonzero end-relative seeksrzunsupported whence (%r)znegative seek position %rr˜z#can't restore logical file position)rarrírLrTrWr:rQrùrìrérÎrr÷rÌrlrÁrrêr(rë) r@ZcookierSrròrrrr r rr;)r@r<rQKs\                  zTextIOWrapper.seekcCs+|jƒ|dkrd}n|jp1|jƒ}y |jWn4tk ru}ztdƒ|‚WYdd}~XnX|dkrÄ|jƒ|j|jj ƒddƒ}|j dƒd|_ |Sd}|j|ƒ}xGt |ƒ|kr"| r"|j ƒ }||j|t |ƒƒ7}qÜW|SdS) Nrzan integer is requiredrr¾TrFr)r^rér÷r~r)rrûrÁr:rlrùrìrr)r@rhr»r„r8rr;r;r<rl–s(    "     !zTextIOWrapper.readcCs=d|_|jƒ}|s9d|_|j|_t‚n|S)NF)rîrorìrírq)r@rrr;r;r<rs¯s     zTextIOWrapper.__next__cCsƒ|jrtdƒ‚n|dkr-d }nt|tƒsKtdƒ‚n|jƒ}d}|jss|jƒnd}}x½|jrÄ|j d|ƒ}|dkrµ|d}Pq»t |ƒ}n÷|j r†|j d|ƒ}|j d|ƒ}|d kr&|d krt |ƒ}qƒ|d}Pq»|d kr@|d}Pq»||krZ|d}Pq»||dkrx|d}Pq»|d}Pn5|j |j ƒ}|dkr»|t |j ƒ}Pn|dkrãt |ƒ|krã|}Pnx|j ƒr|jræPqæqæW|jr||jƒ7}q€|jdƒd|_|Sq€W|dkr^||kr^|}n|jt |ƒ|ƒ|d|…S) Nzread from closed filerzsize must be an integerrrÀr¿rrrrrr)rarrrrrûrér÷rãrerrârärrêrùrìrý)r@rhrrÚstartrRÚendposZnlposZcrposr;r;r<ro¸sp                          zTextIOWrapper.readlinecCs|jr|jjSdS)N)rérµ)r@r;r;r<rµszTextIOWrapper.newlines)&rDrErFr?rþrˆrŒrzr2r3r9r:rZr]r_rWr/rarOr&r"rxrñr÷rùrûrýrr rrTrUr…rQrlrsrorµr;r;r;r<r-½sH  E             *  c K Xr-csveZdZdZdd‡fdd†Zdd„Zdd „Zed d „ƒZed d „ƒZ dd„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Àcs tt|ƒjtƒddddd|ƒ|dkrCd|_n|dk rœt|tƒstdjt |ƒj ƒƒ‚n|j |ƒ|j dƒndS) Nr2zutf-8r3Ú surrogatepassr4Fz*initial_value must be str or None, not {0}r) r—rrˆr�rårrrr‰r×rDrxrQ)r@Z initial_valuer4)rNr;r<rˆs     zStringIO.__init__c Csj|jƒ|jp|jƒ}|jƒ}|jƒz |j|jjƒddƒSWd|j|ƒXdS)Nr¾T) rWrér÷rÉrÎrÁr:r“rÌ)r@r»Z old_stater;r;r<r“,s    zStringIO.getvaluecCs tj|ƒS)N)ÚobjectrŒ)r@r;r;r<rŒ6szStringIO.__repr__cCsdS)Nr;)r@r;r;r<r3;szStringIO.errorscCsdS)Nr;)r@r;r;r<r2?szStringIO.encodingcCs|jdƒdS)Nr…)rP)r@r;r;r<r…CszStringIO.detach) rDrErFr?rˆr“rŒrzr3r2r…r;r;)rNr<rs  r)/r?r$Úabcr¸r¬Ú_threadrrœrÚZ _dummy_threadÚiorrrrr¦rjÚaddr Ú SEEK_DATAr#r«r=r>rGrLr)rr(ÚABCMetarMÚregisterr|Ú_ior!r�r†r�r,r+r°r*r³r¹r¶r-rr;r;r;r<Ús\      "  Ñ   ÿ < Vn~—YFFAUÿÿZ