Lc@sdZddklZddklZdZddddd d d d d dddddgZddkZddkZddkZddk Z ddk Z ddZ e Z defdYZdeeeeedZdfdYZdfdYZdeefdYZd efd!YZd"efd#YZd$e iefd%YZd&efd'YZd(efd)YZd*efd+YZy,ddkZd,eiefd-YZ Wne!j o eZ nXd.efd/YZ"d0efd1YZ#d2efd3YZ$d4e#e"fd5YZ%d6efd7YZ&d8ei'fd9YZ(d:e&fd;YZ)d<e)fd=YZ*dS(>u The io module provides the Python interfaces to stream handling. The builtin open function is defined in this module. At the top of the I/O hierarchy is the abstract base class IOBase. It defines the basic interface to a stream. Note, however, that there is no separation between reading and writing to streams; implementations are allowed to throw an IOError if they do not support a given operation. Extending IOBase is RawIOBase which deals simply with the reading and writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide an interface to OS files. BufferedIOBase deals with buffering on a raw byte stream (RawIOBase). Its subclasses, BufferedWriter, BufferedReader, and BufferedRWPair buffer streams that are readable, writable, and both respectively. BufferedRandom provides a buffered interface to random access streams. BytesIO is a simple stream of in-memory bytes. Another IOBase subclass, TextIOBase, deals with the encoding and decoding of streams into text. TextIOWrapper, which extends it, is a buffered text interface to a buffered raw stream (`BufferedIOBase`). Finally, StringIO is a in-memory stream for text. Argument names are not part of the specification, and only the arguments of open() are intended to be used as keyword arguments. data: DEFAULT_BUFFER_SIZE An int containing the default buffer size used by the module's buffered I/O classes. open() uses the file's blksize (as obtained by os.stat) if possible. i(tprint_function(tunicode_literalsuqGuido van Rossum , Mike Verdone , Mark Russell uBlockingIOErroruopenuIOBaseu RawIOBaseuFileIOuBytesIOuStringIOuBufferedIOBaseuBufferedReaderuBufferedWriteruBufferedRWPairuBufferedRandomu TextIOBaseu TextIOWrapperNiitBlockingIOErrorcBseZdZddZRS(uCException raised when I/O would block on a non-blocking I/O stream.icCs ti|||||_dS(N(tIOErrort__init__tcharacters_written(tselfterrnotstrerrorR((s/usr/lib64/python2.6/io.pyRLs(t__name__t __module__t__doc__R(((s/usr/lib64/python2.6/io.pyRHsurc Csnt|ttfptd|nt|tptd|n|dj o%t|t otd|n|dj o%t|t otd|n|dj o%t|t otd|nt|}|tdpt|t|jotd|nd|j}d|j} d |j} d |j} d |j} d |j} d |jo(| p| otdnt}n| o| otdn|| | djotdn|p | p| ptdn| o|dj otdn| o|dj otdn| o|dj otdnt ||odpd| odpd| od pd| od pd|}|djo d}nt }|djp|djo|i od}t}n|djo\t }yt i|ii}Wnt itfj oqX|djo |}qn|djotdn|djo| o|Stdn| ot||}nL| p| ot||}n+|ot||}ntd|| o|St|||||} || _| S(uOpen file and return a stream. If the file cannot be opened, an IOError is raised. file is either a 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), 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 '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 (for backwards compatibility; unneeded for new code) ========= =============================================================== 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. 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. 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 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 controls 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. 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. 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. uinvalid file: %ruinvalid mode: %ruinvalid buffering: %ruinvalid encoding: %ruinvalid errors: %ruarwb+tUuruwuau+utubuUu$can't use U and writing mode at onceu'can't have text and binary mode at onceiu)can't have read/write/append mode at onceu/must have exactly one of read/write/append modeu-binary mode doesn't take an encoding argumentu+binary mode doesn't take an errors argumentu+binary mode doesn't take a newline argumentuiiuinvalid buffering sizeucan't have unbuffered text I/Ouunknown mode: %rN(t isinstancet basestringtintt TypeErrortNonetsettlent ValueErrortTruetFileIOtFalsetisattytDEFAULT_BUFFER_SIZEtostfstattfilenot st_blksizeterrortAttributeErrortBufferedRandomtBufferedWritertBufferedReadert TextIOWrappertmode(tfileR#t bufferingtencodingterrorstnewlinetclosefdtmodestreadingtwritingt appendingtupdatingttexttbinarytrawtline_bufferingtbstbuffer((s/usr/lib64/python2.6/io.pytopenQsn *        5   '      t_DocDescriptorcBseZdZdZRS(u%Helper for builtins.open.__doc__ cCs dtiS(Nu^open(file, mode='r', buffering=None, encoding=None, errors=None, newline=None, closefd=True) (R5R (Rtobjttyp((s/usr/lib64/python2.6/io.pyt__get__s(R R R R9(((s/usr/lib64/python2.6/io.pyR6 st OpenWrappercBs eZdZeZdZRS(uWrapper for builtins.open Trick so that open won't become a bound method when stored as a class variable (as dumbdbm does). See initstdio() in Python/pythonrun.c. cOs t||S(N(R5(tclstargstkwargs((s/usr/lib64/python2.6/io.pyt__new__s(R R R R6R>(((s/usr/lib64/python2.6/io.pyR:s tUnsupportedOperationcBseZRS((R R (((s/usr/lib64/python2.6/io.pyR?"stIOBasecBseZdZeiZdZddZdZddZ dZ e Z dZdZd Zdd Zd Zdd Zd ZddZedZddZdZdZdZdZddZdZdZddZ dZ!RS(uThe 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 a IOError 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 IOError 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 statment is complete: with open('spam.txt', 'r') as fp: fp.write('Spam and eggs!') cCs td|ii|fdS(u8Internal: raise an exception for unsupported operations.u%s.%s() not supportedN(R?t __class__R (Rtname((s/usr/lib64/python2.6/io.pyt _unsupportedJsicCs|iddS(uChange stream position. Change the stream position to byte offset offset. offset is interpreted relative to the position indicated by whence. Values for whence are: * 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 Return the new absolute position. useekN(RC(Rtpostwhence((s/usr/lib64/python2.6/io.pytseekQs cCs|iddS(uReturn current stream position.ii(RF(R((s/usr/lib64/python2.6/io.pyttell`scCs|iddS(uTruncate file to size bytes. Size defaults to the current IO position as reported by tell(). Return the new size. utruncateN(RC(RRD((s/usr/lib64/python2.6/io.pyttruncatedscCs|iotdndS(uuFlush write buffers, if applicable. This is not implemented for read-only and non-blocking streams. uflush of closed fileN(t_IOBase__closedR(R((s/usr/lib64/python2.6/io.pytflushns cCs%|ip|it|_ndS(uiFlush and close the IO object. This method has no effect if the file is already closed. N(RIRJR(R((s/usr/lib64/python2.6/io.pytclosezs  cCsy|iWnnXdS(uDestructor. Calls close().N(RK(R((s/usr/lib64/python2.6/io.pyt__del__scCstS(uReturn whether object supports random access. If False, seek(), tell() and truncate() will raise IOError. This method may need to do a test seek(). (R(R((s/usr/lib64/python2.6/io.pytseekablescCs5|ip$t|djodn|ndS(u;Internal: raise an IOError if file is not seekable uFile or stream is not seekable.N(RMRR(Rtmsg((s/usr/lib64/python2.6/io.pyt_checkSeekables cCstS(udReturn whether object was opened for reading. If False, read() will raise IOError. (R(R((s/usr/lib64/python2.6/io.pytreadablescCs5|ip$t|djodn|ndS(u;Internal: raise an IOError if file is not readable uFile or stream is not readable.N(RPRR(RRN((s/usr/lib64/python2.6/io.pyt_checkReadables cCstS(utReturn whether object was opened for writing. If False, write() and truncate() will raise IOError. (R(R((s/usr/lib64/python2.6/io.pytwritablescCs5|ip$t|djodn|ndS(u;Internal: raise an IOError if file is not writable uFile or stream is not writable.N(RRRR(RRN((s/usr/lib64/python2.6/io.pyt_checkWritables cCs|iS(uclosed: bool. True iff the file has been closed. For backwards compatibility, this is a property, not a predicate. (RI(R((s/usr/lib64/python2.6/io.pytclosedscCs2|io$t|djodn|ndS(u8Internal: raise an ValueError if file is closed uI/O operation on closed file.N(RTRR(RRN((s/usr/lib64/python2.6/io.pyt _checkCloseds cCs|i|S(u+Context management protocol. Returns self.(RU(R((s/usr/lib64/python2.6/io.pyt __enter__s cGs|idS(u+Context management protocol. Calls close()N(RK(RR<((s/usr/lib64/python2.6/io.pyt__exit__scCs|iddS(uReturns underlying file descriptor if one exists. An IOError is raised if the IO object does not use a file descriptor. ufilenoN(RC(R((s/usr/lib64/python2.6/io.pyRscCs|itS(uiReturn whether this is an 'interactive' stream. Return False if it can't be determined. (RUR(R((s/usr/lib64/python2.6/io.pyRs icsitdofd}n d}djo dntttfptdnt}xbdjpt|joAi |}|pPn||7}|i doPqqWt |S( u(Read and return a line from the stream. If limit is specified, at most limit bytes will be read. 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. upeekcs_id}|pdS|iddp t|}djot|}n|S(Nis i(tpeektfindRtmin(t readaheadtn(Rtlimit(s/usr/lib64/python2.6/io.pyt nreadaheads  cSsdS(Ni((((s/usr/lib64/python2.6/io.pyR^siulimit must be an integeris N( RUthasattrRR RtlongRt bytearrayRtreadtendswithtbytes(RR]R^trestb((RR]s/usr/lib64/python2.6/io.pytreadlines$        cCs|i|S(N(RU(R((s/usr/lib64/python2.6/io.pyt__iter__s cCs!|i}|p tn|S(N(Rgt StopIteration(Rtline((s/usr/lib64/python2.6/io.pytnexts  cCs|djo d}nt|ttfptdn|djo t|Sd}g}x=|D]5}|i||t|7}||joPqhqhW|S(uReturn 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. iuhint must be an integeriN(RR RR`RtlisttappendR(RthintR\tlinesRj((s/usr/lib64/python2.6/io.pyt readliness       cCs,|ix|D]}|i|qWdS(N(RUtwrite(RRoRj((s/usr/lib64/python2.6/io.pyt writelines0s N("R R R tabctABCMetat __metaclass__RCRFRGRRHRJRRIRKRLRMRORPRQRRRStpropertyRTRURVRWRRRgRhRkRpRr(((s/usr/lib64/python2.6/io.pyR@&s6                $   t RawIOBasecBs5eZdZddZdZdZdZRS(uBase class for raw binary I/O.icCsa|djo d}n|djo |iSt|i}|i|}||3t|S(uRead and return up to n bytes. Returns an empty bytes array on EOF, or None if the object is set not to block and has no data to read. iiN(RtreadallRat __index__treadintoRd(RR\Rf((s/usr/lib64/python2.6/io.pyRbDs    cCsGt}x1to)|it}|pPn||7}q Wt|S(u+Read until EOF, using multiple read() call.(RaRRbRRd(RRetdata((s/usr/lib64/python2.6/io.pyRxSs cCs|iddS(uRead up to len(b) bytes into b. Returns number of bytes read (0 for EOF), or None if the object is set not to block as has no data to read. ureadintoN(RC(RRf((s/usr/lib64/python2.6/io.pyRz]scCs|iddS(u~Write the given buffer to the IO stream. Returns the number of bytes written, which may be less than len(b). uwriteN(RC(RRf((s/usr/lib64/python2.6/io.pyRqes(R R R RbRxRzRq(((s/usr/lib64/python2.6/io.pyRw6s   RcBs5eZdZdedZdZedZRS(u$Raw I/O implementation for OS files.urcCs&tii||||||_dS(N(t_fileiot_FileIORt_name(RRBR#R)((s/usr/lib64/python2.6/io.pyRvscCs!tii|ti|dS(N(R|R}RKRw(R((s/usr/lib64/python2.6/io.pyRKzscCs|iS(N(R~(R((s/usr/lib64/python2.6/io.pyRB~s(R R R RRRKRvRB(((s/usr/lib64/python2.6/io.pyRms tBufferedIOBasecBs,eZdZddZdZdZRS(uBase 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. cCs|iddS(uRead and return up to n bytes. 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. ureadN(RC(RR\((s/usr/lib64/python2.6/io.pyRbscCs|it|}t|}y|||*WnTtj oH}ddk}t||ip |n|id|||*nX|S(u=Read up to len(b) bytes into b. Like read(), this may issue multiple reads to the underlying raw stream, unless the latter is 'interactive'. Returns the number of bytes read (0 for EOF). Raises BlockingIOError if the underlying raw stream has no data at the moment. iNRf(RbRRtarrayR (RRfR{R\terrR((s/usr/lib64/python2.6/io.pyRzs    cCs|iddS(u Write the given buffer to the IO stream. Return the number of bytes written, which is never less than len(b). Raises BlockingIOError if the buffer is full and the underlying raw stream cannot accept more data at the moment. uwriteN(RC(RRf((s/usr/lib64/python2.6/io.pyRqs N(R R R RRbRzRq(((s/usr/lib64/python2.6/io.pyRs  t_BufferedIOMixincBseZdZdZddZdZddZdZdZ dZ d Z d Z e d Ze d Ze d ZdZdZRS(uA mixin implementation of BufferedIOBase with an underlying raw stream. This passes most requests on to the underlying raw stream. It does *not* provide implementations of read(), readinto() or write(). cCs ||_dS(N(R1(RR1((s/usr/lib64/python2.6/io.pyRsicCs|ii||S(N(R1RF(RRDRE((s/usr/lib64/python2.6/io.pyRFscCs |iiS(N(R1RG(R((s/usr/lib64/python2.6/io.pyRGscCs7|i|djo|i}n|ii|S(N(RJRRGR1RH(RRD((s/usr/lib64/python2.6/io.pyRHs  cCs|iidS(N(R1RJ(R((s/usr/lib64/python2.6/io.pyRJscCs)|ip|i|iindS(N(RTRJR1RK(R((s/usr/lib64/python2.6/io.pyRKs  cCs |iiS(N(R1RM(R((s/usr/lib64/python2.6/io.pyRMscCs |iiS(N(R1RP(R((s/usr/lib64/python2.6/io.pyRPscCs |iiS(N(R1RR(R((s/usr/lib64/python2.6/io.pyRRscCs |iiS(N(R1RT(R((s/usr/lib64/python2.6/io.pyRTscCs |iiS(N(R1RB(R((s/usr/lib64/python2.6/io.pyRBscCs |iiS(N(R1R#(R((s/usr/lib64/python2.6/io.pyR#scCs |iiS(N(R1R(R((s/usr/lib64/python2.6/io.pyRscCs |iiS(N(R1R(R((s/usr/lib64/python2.6/io.pyRsN(R R R RRFRGRRHRJRKRMRPRRRvRTRBR#RR(((s/usr/lib64/python2.6/io.pyRs          t_BytesIOcBs}eZdZd dZdZd dZdZdZddZ dZ d d Z d Z d Z d ZRS(u<Buffered I/O implementation using an in-memory bytes buffer.cCs@t}|dj o|t|7}n||_d|_dS(Ni(RaRt_buffert_pos(Rt initial_bytestbuf((s/usr/lib64/python2.6/io.pyRs    cCs'|iotdnt|iS(u8Return the bytes value (contents) of the buffer ugetvalue on closed file(RTRRdR(R((s/usr/lib64/python2.6/io.pytgetvalue"s cCs|iotdn|djo d}nt|ttfptdn|djot|i}nt|i|i jodSt t|i|i |}|i|i |!}||_ t |S(Nuread from closed fileiuargument must be an integerit( RTRRR RR`RRRRRZRd(RR\tnewposRf((s/usr/lib64/python2.6/io.pyRb)s     cCs |i|S(u"this is the same as read. (Rb(RR\((s/usr/lib64/python2.6/io.pytread19scCs|iotdnt|totdnt|}|djodS|i}|t|ijo*d|t|i}|i|7_n||i|||+|i|7_|S(Nuwrite to closed fileu$can't write unicode to binary streamit(RTRR tunicodeRRRR(RRfR\RDtpadding((s/usr/lib64/python2.6/io.pyRq>s    icCs|iotdny |iWntj otdnX|djo1|djotd|fn||_ng|djotd|i||_n=|djo#tdt|i||_n td|iS(Nuseek on closed fileuan integer is requirediunegative seek position %riiuinvalid whence value( RTRRyRRRtmaxRR(RRDRE((s/usr/lib64/python2.6/io.pyRFPs        # cCs!|iotdn|iS(Nutell on closed file(RTRR(R((s/usr/lib64/python2.6/io.pyRGcs cCs|iotdn|djo |i}nRy |iWntj otdnX|djotd|fn|i|3|S(Nutruncate on closed fileuan integer is requirediunegative truncate position %r(RTRRRRyRRR(RRD((s/usr/lib64/python2.6/io.pyRHhs      cCstS(N(R(R((s/usr/lib64/python2.6/io.pyRPwscCstS(N(R(R((s/usr/lib64/python2.6/io.pyRRzscCstS(N(R(R((s/usr/lib64/python2.6/io.pyRM}sN(R R R RRRRbRRqRFRGRHRPRRRM(((s/usr/lib64/python2.6/io.pyRs          tBytesIOcBseZeiiZRS((R R t_bytesioRR (((s/usr/lib64/python2.6/io.pyRsR!cBsqeZdZedZdZd dZd dZddZ ddZ dZ d Z dd Z RS( uBufferedReader(raw[, buffer_size]) A buffer for a readable, sequential BaseRawIO object. The constructor creates a BufferedReader for the given readable raw stream and buffer_size. If buffer_size is omitted, DEFAULT_BUFFER_SIZE is used. cCs@|iti||||_|iti|_dS(uMCreate a new buffered reader using the given readable raw IO object. N(RQRRt buffer_sizet_reset_read_buft threadingtLockt _read_lock(RR1R((s/usr/lib64/python2.6/io.pyRs    cCsd|_d|_dS(NRi(t _read_buft _read_pos(R((s/usr/lib64/python2.6/io.pyRs cCs,|iiiz|i|SWdQXdS(uRead n bytes. Returns exactly n bytes of data unless the underlying raw IO stream reaches EOF or if the call would block in non-blocking mode. If n is negative, read until EOF or until read() would block. N(RRWRVt_read_unlocked(RR\((s/usr/lib64/python2.6/io.pyRbsc Csd}d}|i}|i}|djp |djo|i||g}d}xPtoH|ii}||jo |}Pn|t|7}|i|qXWdi |p|St||} || jo|i|7_||||!S||g}t |i |} xY| |joK|ii| }||jo |}Pn| t|7} |i|qWt || }di |} | ||_d|_| o | | S|S(NRii(RN( RRRRRR1RbRRmtjoinRRRZ( RR\t nodata_valt empty_valuesRRDtchunkst current_sizetchunktavailtwantedtout((s/usr/lib64/python2.6/io.pyRsH           icCs,|iiiz|i|SWdQXdS(uReturns 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(RRWRVt_peek_unlocked(RR\((s/usr/lib64/python2.6/io.pyRXscCst||i}t|i|i}||joN|i|}|ii|}|o$|i|i||_d|_qn|i|iS(Ni(RZRRRRR1Rb(RR\twantthavetto_readtcurrent((s/usr/lib64/python2.6/io.pyRs  c Csd|djodS|iiiz7|id|it|t|i|iSWdQXdS(u9Reads up to n bytes, with at most one read() system call.iRiN( RRWRVRRRZRRR(RR\((s/usr/lib64/python2.6/io.pyRs   cCs!|iit|i|iS(N(R1RGRRR(R((s/usr/lib64/python2.6/io.pyRGscCsm|iiizR|djo|t|i|i8}n|ii||}|i|SWdQXdS(Ni( RRWRVRRRR1RFR(RRDRE((s/usr/lib64/python2.6/io.pyRFs   N(R R R RRRRRbRRXRRRGRF(((s/usr/lib64/python2.6/io.pyR!s   . R cBsYeZdZed dZdZd dZdZdZ dZ ddZ RS( uA buffer for a writeable sequential RawIO object. The constructor creates a BufferedWriter for the given writeable raw stream. If the buffer_size is not given, it defaults to DEAFULT_BUFFER_SIZE. If max_buffer_size is omitted, it defaults to twice the buffer size. cCsc|iti||||_|djo d|n||_t|_ti |_ dS(Ni( RSRRRRtmax_buffer_sizeRat _write_bufRRt _write_lock(RR1RR((s/usr/lib64/python2.6/io.pyRs    c Cs|iotdnt|totdn|iiiz6t|i |i joBy|i Wqt j o!}t |i |idqXnt|i }|i i|t|i |}t|i |i joy|i Wq}t j og}t|i |ijoEt|i |i}|i |i |_ t |i |i|qyq}Xn|SWdQXdS(Nuwrite to closed fileu$can't write unicode to binary streami(RTRR RRRRWRVRRRt_flush_unlockedRRRtextendR(RRftetbeforetwrittentoverage((s/usr/lib64/python2.6/io.pyRqs, !%cCsY|iiiz>|i|djo|ii}n|ii|SWdQXdS(N(RRWRVRRR1RGRH(RRD((s/usr/lib64/python2.6/io.pyRH<s   cCsC|iotdn|iiiz|iWdQXdS(Nuflush of closed file(RTRRRWRVR(R((s/usr/lib64/python2.6/io.pyRJCs cCs|iotdnd}y?x8|io-|ii|i}|i|4||7}q&WWnJtj o>}|i}|i|4||7}t|i|i|nXdS(Nuflush of closed filei( RTRRR1RqRRRR(RRR\R((s/usr/lib64/python2.6/io.pyRIs      cCs|iit|iS(N(R1RGRR(R((s/usr/lib64/python2.6/io.pyRGXsicCs<|iiiz!|i|ii||SWdQXdS(N(RRWRVRR1RF(RRDRE((s/usr/lib64/python2.6/io.pyRF[s N( R R R RRRRqRHRJRRGRF(((s/usr/lib64/python2.6/io.pyR s     tBufferedRWPaircBseZdZeddZddZdZdZddZ dZ dZ d Z d Z d Zd Zed ZRS(uA 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. The max_buffer_size (for the buffered writer) defaults to twice the buffer size. cCs?|i|it|||_t||||_dS(uEConstructor. The arguments are two RawIO instances. N(RQRSR!treaderR twriter(RRRRR((s/usr/lib64/python2.6/io.pyRrs  cCs'|djo d}n|ii|S(Ni(RRRb(RR\((s/usr/lib64/python2.6/io.pyRb}s  cCs|ii|S(N(RRz(RRf((s/usr/lib64/python2.6/io.pyRzscCs|ii|S(N(RRq(RRf((s/usr/lib64/python2.6/io.pyRqsicCs|ii|S(N(RRX(RR\((s/usr/lib64/python2.6/io.pyRXscCs|ii|S(N(RR(RR\((s/usr/lib64/python2.6/io.pyRscCs |iiS(N(RRP(R((s/usr/lib64/python2.6/io.pyRPscCs |iiS(N(RRR(R((s/usr/lib64/python2.6/io.pyRRscCs |iiS(N(RRJ(R((s/usr/lib64/python2.6/io.pyRJscCs|ii|iidS(N(RRKR(R((s/usr/lib64/python2.6/io.pyRKs cCs|iip |iiS(N(RRR(R((s/usr/lib64/python2.6/io.pyRscCs |iiS(N(RRT(R((s/usr/lib64/python2.6/io.pyRTsN(R R R RRRRbRzRqRXRRPRRRJRKRRvRT(((s/usr/lib64/python2.6/io.pyRas           RcBsqeZdZed dZddZdZd dZd dZ dZ ddZ d Z d Z RS( u<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. The max_buffer_size (for the buffered writer) defaults to twice the buffer size. cCs7|iti|||ti||||dS(N(ROR!RR (RR1RR((s/usr/lib64/python2.6/io.pyRs icCs|i|ioO|djoB|iiiz'|ii|it|idWdQXn|ii||}|iiiz|i WdQX|S(Ni( RJRRRWRVR1RFRRR(RRDRE((s/usr/lib64/python2.6/io.pyRFs -cCs6|io|iit|iSti|SdS(N(RR1RGRR!(R((s/usr/lib64/python2.6/io.pyRGs cCs-|djo|i}nti||S(N(RRGR RH(RRD((s/usr/lib64/python2.6/io.pyRHs cCs1|djo d}n|iti||S(Ni(RRJR!Rb(RR\((s/usr/lib64/python2.6/io.pyRbs   cCs|iti||S(N(RJR!Rz(RRf((s/usr/lib64/python2.6/io.pyRzs cCs|iti||S(N(RJR!RX(RR\((s/usr/lib64/python2.6/io.pyRXs cCs|iti||S(N(RJR!R(RR\((s/usr/lib64/python2.6/io.pyRs cCsf|ioL|iiiz1|ii|it|id|iWdQXnt i ||S(Ni( RRRWRVR1RFRRRR Rq(RRf((s/usr/lib64/python2.6/io.pyRqs  #N(R R R RRRRFRGRHRbRzRXRRq(((s/usr/lib64/python2.6/io.pyRs      t TextIOBasecBsVeZdZddZdZddZdZedZ edZ RS( uBase 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. icCs|iddS(uRead at most n characters from stream. Read from underlying buffer until we have n characters or we hit EOF. If n is negative or omitted, read until EOF. ureadN(RC(RR\((s/usr/lib64/python2.6/io.pyRbscCs|iddS(uWrite string s to stream.uwriteN(RC(Rts((s/usr/lib64/python2.6/io.pyRqscCs|iddS(uTruncate size to pos.utruncateN(RC(RRD((s/usr/lib64/python2.6/io.pyRHscCs|iddS(u_Read until newline or EOF. Returns an empty string if EOF is hit immediately. ureadlineN(RC(R((s/usr/lib64/python2.6/io.pyRgscCsdS(uSubclasses should override.N(R(R((s/usr/lib64/python2.6/io.pyR&scCsdS(uLine endings translated so far. Only line endings translated during reading are considered. Subclasses should override. N(R(R((s/usr/lib64/python2.6/io.pytnewlines sN( R R R RbRqRRHRgRvR&R(((s/usr/lib64/python2.6/io.pyRs    tIncrementalNewlineDecodercBsbeZdZddZedZdZdZdZdZ dZ d Z e d Z RS( u(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. ustrictcCs>tii|d|||_||_d|_t|_dS(NR'i(tcodecstIncrementalDecoderRt translatetdecodertseennlRt pendingcr(RRRR'((s/usr/lib64/python2.6/io.pyRs    cCs,|ii|d|}|io%|p|od|}t|_n|ido| o|d }t|_n|id}|id|}|id|}|i|o|i|o|i B|o|i BO_|i o>|o|i dd}n|o|i dd}q(n|S(Ntfinalu iu u ( RtdecodeRRRcRtcountRt_LFt_CRt_CRLFRtreplace(RtinputRtoutputtcrlftcrtlf((s/usr/lib64/python2.6/io.pyR%s$    . cCsA|ii\}}|dK}|io|dO}n||fS(Ni(RtgetstateR(RRtflag((s/usr/lib64/python2.6/io.pyRAs   cCs=|\}}t|d@|_|ii||d?fdS(Ni(tboolRRtsetstate(RtstateRR((s/usr/lib64/python2.6/io.pyRHs cCs#d|_t|_|iidS(Ni(RRRRtreset(R((s/usr/lib64/python2.6/io.pyRMs  iiic Cs#ddddddddf|iS(Nu u u (u u (u u (u u (u u u (RR(R((s/usr/lib64/python2.6/io.pyRVs(R R R RRRRRRRRRRvR(((s/usr/lib64/python2.6/io.pyRs     R"cBsdeZdZdZd d d edZedZedZ edZ dZ dZ dZ d Zd Zed Zed Zd ZdZdZdZdZdZd dZdZdZdddddZdZdZd dZddZd dZ dZ!d dZ"edZ#RS(!uCharacter 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. 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. ic Cs,|d jotd|fn|djoyti|i}Wnttfj onX|djo<yddk}Wntj o d}qX|i }qnt |t ptd|n|djo d }n%t |t ptd |n||_ ||_ ||_||_| |_|dj|_||_|dj|_|pti|_d|_d|_d|_d |_d|_|i i|_|_|io^|ioQ|i i}|d jo1y|i i!d Wq$t"j oq$Xq(ndS( Nuu u u uillegal newline value: %riuasciiuinvalid encoding: %rustrictuinvalid errors: %ri(Nuu u u (#RRRtdevice_encodingRRR?tlocalet ImportErrortgetpreferredencodingR R R4t_line_bufferingt _encodingt_errorst_readuniversalt_readtranslatet_readnlt_writetranslatetlinesept_writenlt_encodert_decodert_decoded_charst_decoded_chars_usedt _snapshotRMt _seekablet_tellingRRRGt _get_encoderRt LookupError(RR4R&R'R(R2Rtposition((s/usr/lib64/python2.6/io.pyR}sR                  cCs|iS(N(R(R((s/usr/lib64/python2.6/io.pyR&scCs|iS(N(R(R((s/usr/lib64/python2.6/io.pyR'scCs|iS(N(R(R((s/usr/lib64/python2.6/io.pyR2scCs|iS(N(R(R((s/usr/lib64/python2.6/io.pyRMscCs |iiS(N(R4RP(R((s/usr/lib64/python2.6/io.pyRPscCs |iiS(N(R4RR(R((s/usr/lib64/python2.6/io.pyRRscCs|ii|i|_dS(N(R4RJRR(R((s/usr/lib64/python2.6/io.pyRJs cCs)|ip|i|iindS(N(RTRJR4RK(R((s/usr/lib64/python2.6/io.pyRKs  cCs |iiS(N(R4RT(R((s/usr/lib64/python2.6/io.pyRTscCs |iiS(N(R4RB(R((s/usr/lib64/python2.6/io.pyRBscCs |iiS(N(R4R(R((s/usr/lib64/python2.6/io.pyRscCs |iiS(N(R4R(R((s/usr/lib64/python2.6/io.pyRscCs3|iotdnt|tptd|iint|}|ip |i o d|j}|o3|io)|i djo|i d|i }n|i p |i }|i|}|ii||i o"|p d|jo|ind|_|io|iin|S(Nuwrite to closed fileucan't write %s to text streamu u (RTRR RRRAR RRRRRRRtencodeR4RqRJRRRR(RRtlengththaslftencoderRf((s/usr/lib64/python2.6/io.pyRqs$   !  cCs+ti|i}||i|_|iS(N(RtgetincrementalencoderRRR(Rt make_encoder((s/usr/lib64/python2.6/io.pyRscCsNti|i}||i}|iot||i}n||_|S(N(RtgetincrementaldecoderRRRRRR(Rt make_decoderR((s/usr/lib64/python2.6/io.pyt _get_decoders   cCs||_d|_dS(uSet the _decoded_chars buffer.iN(RR(Rtchars((s/usr/lib64/python2.6/io.pyt_set_decoded_chars s cCsT|i}|djo|i|}n|i|||!}|it|7_|S(u'Advance into the _decoded_chars buffer.N(RRRR(RR\toffsetR((s/usr/lib64/python2.6/io.pyt_get_decoded_charss   cCs3|i|jotdn|i|8_dS(u!Rewind the _decoded_chars buffer.u"rewind decoded_chars out of boundsN(RtAssertionError(RR\((s/usr/lib64/python2.6/io.pyt_rewind_decoded_charsscCs|idjotdn|io|ii\}}n|ii|i}| }|i|ii |||io|||f|_ n| S(ur Read and decode the next chunk of data from the BufferedReader. The return value is True unless EOF was reached. The decoded string is placed in self._decoded_chars (replacing its previous value). The entire input chunk is sent to the decoder, though some of it may remain buffered in the decoder, yet to be converted. u no decoderN( RRRRRR4Rt _CHUNK_SIZERRR(Rt dec_buffert dec_flagst input_chunkteof((s/usr/lib64/python2.6/io.pyt _read_chunk s   icCs*||d>B|d>B|d>Bt|d>BS(Ni@iii(R(RRRt bytes_to_feedtneed_eoft chars_to_skip((s/usr/lib64/python2.6/io.pyt _pack_cookieAscCsgt|d\}}t|d\}}t|d\}}t|d\}}|||||fS(Nii@llll(tdivmod(RtbiginttrestRRRRR((s/usr/lib64/python2.6/io.pyt_unpack_cookieKs c Cs$|iptdn|iptdn|i|ii}|i}|djp|idjo|i ot dn|S|i\}}|t |8}|i }|djo|i ||S|i}z+|id|f|}|dd}} } d} x|D]} | d7} | t |i| 7} |i\} }| o9| |jo,|| 7}|| 8}|dd}} } n| |joPq!q!W| t |iddt7} d} | |jotdn|i ||| | |SWd|i|XdS( Nu!underlying stream is not seekableu(telling position disabled by next() callupending decoded textiRiRu'can't reconstruct logical file position(RRRRJR4RGRRRRRRRRRRRR(RRRRt next_inputRt saved_statet start_post start_flagst bytes_fedt chars_decodedRt next_byteR((s/usr/lib64/python2.6/io.pyRGRsP              cCs7|i|djo|i}n|ii|S(N(RJRRGR4RH(RRD((s/usr/lib64/python2.6/io.pyRHs  c Cs|iotdn|iptdn|djo3|djotdnd}|i}n|djor|djotdn|i|iidd}|idd|_ |i o|i i n|S|djotd |fn|djotd |fn|i|i |\}}}}}|ii||idd|_ |i p|p|oB|i p |i|_ |i id |f|d f|_ n|op|ii|} |i|i i| ||| f|_ t|i|jotd n||_ny|ip |i} Wntj on*X|djo| idn | i |S( Nutell on closed fileu!underlying stream is not seekableiiu#can't do nonzero cur-relative seeksiu#can't do nonzero end-relative seeksuu(invalid whence (%r, should be 0, 1 or 2)unegative seek position %rRu#can't restore logical file position(RTRRRRGRJR4RFRRRRRRRRRbRRRRRRR( RtcookieRERRRRRRRR((s/usr/lib64/python2.6/io.pyRFsb                  cCs|djo d}n|ip |i}y |iWntj otdnX|djoC|i|i|ii dt }|i dd|_ |St }|i|}xJt||jo6| o.|i }||i|t|7}qW|SdS(Niuan integer is requirediRu(RRRRyRRRRR4RbRRRRRR(RR\RtresultR((s/usr/lib64/python2.6/io.pyRbs(        "cCs?t|_|i}|pd|_|i|_tn|S(N(RRRgRRRRi(RRj((s/usr/lib64/python2.6/io.pyRks     c Cs|iotdn|djo d}nt|ttfptdn|i}d}|ip |i }d}}xt o|i o>|i d|}|djo|d}Pqt |}n|io|i d|}|i d|}|djo,|djot |}q|d}Pq|djo|d}Pq||jo|d}Pq||djo|d}Pq|d}Pn8|i |i}|djo|t |i}Pn|djot ||jo |}Pnd } x!|io|ioPqqW|io||i7}q|id d|_|SqW|djo||jo |}n|it |||| S( Nuread from closed fileiulimit must be an integeriu iu iu(RTRRR RR`RRRRRRRYRRRRRRRR( RR]RjtstartRRDtendpostnlpostcrpost more_line((s/usr/lib64/python2.6/io.pyRgst                            cCs|io |iiSdS(N(RRR(R((s/usr/lib64/python2.6/io.pyRTsN($R R R RRRRRvR&R'R2RMRPRRRJRKRTRBRRRqRRRRRRRRRGRHRFRbRkRgR(((s/usr/lib64/python2.6/io.pyR"csB  <            !  >  F  WtStringIOcBs,eZdZdddddZdZRS(uAn in-memory stream for text. The initial_value argument sets the value of object. The other arguments are like those of TextIOWrapper's constructor. uuutf-8ustrictu cCstt|itd|d|d||djo t|_n|o>t|tpt|}n|i ||i dndS(NR&R'R(i( tsuperRRRRRRR RRqRF(Rt initial_valueR&R'R(((s/usr/lib64/python2.6/io.pyR_s   cCs)|i|iii|i|iS(N(RJR4RRRR(R((s/usr/lib64/python2.6/io.pyRos (R R R RR(((s/usr/lib64/python2.6/io.pyRXs(+R t __future__RRt __author__t__all__RRsRR|RRttypeRuRRRRR5R6R:RR?tobjectR@RwR}RRRRRRRR!R RRRRRR"R(((s/usr/lib64/python2.6/io.pyt#sR           7HJl   }YBD0L