Ñò pØcJc@s0dZddklZdefd„ƒYZdS(s BufferedFile. iÿÿÿÿ(tStringIOt BufferedFilecBseZdZdZdZdZdZdZdZdZ dZ dZ dZ d Z d „Zd „Zd „Zd „Zd„Zd„Zd d„Zd d„Zd d„Zdd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zddd„Z d„Z!d„Z"RS(!sc Reusable base class to implement python-style file buffering around a simpler stream. i iiiiii i@i€cCsbd|_d|_|i|_tƒ|_d|_t|_ t|_ d|_ |_ d|_ dS(Nit(tNonetnewlinest_flagst_DEFAULT_BUFSIZEt_bufsizeRt_wbuffert_rbuffertFalset_at_trailing_crt_closedt_post_realpost_size(tself((s1/usr/lib/python2.6/site-packages/paramiko/file.pyt__init__.s       cCs|iƒdS(N(tclose(R((s1/usr/lib/python2.6/site-packages/paramiko/file.pyt__del__=scCs|iotdƒ‚n|S(s6 Returns an iterator that can be used to iterate over the lines in this file. This iterator happens to return the file itself, since a file is its own iterator. @raise ValueError: if the file is closed. @return: an interator. @rtype: iterator sI/O operation on closed file(R t ValueError(R((s1/usr/lib/python2.6/site-packages/paramiko/file.pyt__iter__@s cCs|iƒt|_dS(sN Close the file. Future read and write operations will fail. N(tflushtTrueR (R((s1/usr/lib/python2.6/site-packages/paramiko/file.pyROs cCs&|i|iiƒƒtƒ|_dS(s{ Write out any data in the write buffer. This may do nothing if write buffering is not turned on. N(t _write_allRtgetvalueR(R((s1/usr/lib/python2.6/site-packages/paramiko/file.pyRVs cCs!|iƒ}|p t‚n|S(sH Returns the next line from the input, or raises L{StopIteration} when EOF is hit. Unlike python file objects, it's okay to mix calls to C{next} and L{readline}. @raise StopIteration: when the end of the file is reached. @return: a line read from the file. @rtype: str (treadlinet StopIteration(Rtline((s1/usr/lib/python2.6/site-packages/paramiko/file.pytnext_s  c Csn|iotdƒ‚n|i|i@ptdƒ‚n|djp |djoÆ|i}d|_|it|ƒ7_x—toy|i |i ƒ}Wnt j o d}nX|djpt|ƒdjoPn||7}|i t|ƒ7_ |it|ƒ7_qW|S|t|iƒjo7|i| }|i||_|it|ƒ7_|SxÍt|iƒ|jo¶|t|iƒ}|i|i @ot|i|ƒ}ny|i |ƒ}Wnt j o d}nX|djpt|ƒdjoPn|i|7_|i t|ƒ7_ qkW|i| }|i||_|it|ƒ7_|S(sž Read at most C{size} bytes from the file (less if we hit the end of the file first). If the C{size} argument is negative or omitted, read all the remaining data in the file. @param size: maximum number of bytes to read @type size: int @return: data read from the file, or an empty string if EOF was encountered immediately @rtype: str sFile is closedsFile is not open for readingiRN(R tIOErrorRt FLAG_READRR R tlenRt_readRtEOFErrorRt FLAG_BUFFEREDtmaxR(Rtsizetresulttnew_datat read_size((s1/usr/lib/python2.6/site-packages/paramiko/file.pytreadosT          c Cs2|iotdƒ‚n|i|i@ptdƒ‚n|i}x¼to´|ioj|i|i@oYt|ƒdjoF|ddjo|d}|i dƒn|i dƒt |_n|d j oe|djoXt|ƒ|jo1|||_|| }|i t|ƒ7_ |S|t|ƒ}n |i }d|jp|i|i@od|joPny|i|ƒ}Wntj o d }nX|d jpt|ƒdjo#d|_|i t|ƒ7_ |S||7}|it|ƒ7_qGW|idƒ}|i|i@oD|idƒ}|djo$||jp |djo |}qgn|d}||djo2|t|ƒjo||djo|d7}n|||_|||!}|| d}t|iƒdjo|djo t|_n|i |ƒ|i t|ƒ7_ |S( s  Read one entire line from the file. A trailing newline character is kept in the string (but may be absent when a file ends with an incomplete line). If the size argument is present and non-negative, it is a maximum byte count (including the trailing newline) and an incomplete line may be returned. An empty string is returned only when EOF is encountered immediately. @note: Unlike stdio's C{fgets()}, the returned string contains null characters (C{'\0'}) if they occurred in the input. @param size: maximum length of returned string. @type size: int @return: next line of the file, or an empty string if the end of the file has been reached. @rtype: str sFile is closedsFile not open for readingis is s RN(R RRRR RR tFLAG_UNIVERSAL_NEWLINER t_record_newlineR RR RR!R"Rtfind( RR%RtnR'tpostrpostxpostlf((s1/usr/lib/python2.6/site-packages/paramiko/file.pyR¥sb  .      +    ' 5  #  cCsg}d}xltod|iƒ}t|ƒdjoPn|i|ƒ|t|ƒ7}|dj o||joPqqW|S(sÚ Read all remaining lines using L{readline} and return them as a list. If the optional C{sizehint} argument is present, instead of reading up to EOF, whole lines totalling approximately sizehint bytes (possibly after rounding up to an internal buffer size) are read. @param sizehint: desired maximum number of bytes to read. @type sizehint: int @return: list of lines read from the file. @rtype: list iN(RRR tappendR(RtsizehinttlinestbytesR((s1/usr/lib/python2.6/site-packages/paramiko/file.pyt readlinesôs    cCstdƒ‚dS(s¹ Set the file's current position, like stdio's C{fseek}. Not all file objects support seeking. @note: If a file is opened in append mode (C{'a'} or C{'a+'}), any seek operations will be undone at the next write (as the file position will move back to the end of the file). @param offset: position to move to within the file, relative to C{whence}. @type offset: int @param whence: type of movement: 0 = absolute; 1 = relative to the current position; 2 = relative to the end of the file. @type whence: int @raise IOError: if the file doesn't support random access. sFile does not support seeking.N(R(Rtoffsettwhence((s1/usr/lib/python2.6/site-packages/paramiko/file.pytseek scCs|iS(sý Return the file's current position. This may not be accurate or useful if the underlying file doesn't support random access, or was opened in append mode. @return: file position (in bytes). @rtype: int (R (R((s1/usr/lib/python2.6/site-packages/paramiko/file.pyttell s cCs1|iotdƒ‚n|i|i@ptdƒ‚n|i|i@p|i|ƒdS|ii|ƒ|i|i@o‡|i dƒ}|djof|ii ƒ}|t |ƒt |ƒ7}|i||d ƒt ƒ|_|ii||dƒndS|ii ƒ|ijo|iƒndS(s@ Write data to the file. If write buffering is on (C{bufsize} was specified and non-zero), some or all of the data may not actually be written yet. (Use L{flush} or L{close} to force buffered data to be written out.) @param data: data to write. @type data: str sFile is closedsFile not open for writingNs ii(R RRt FLAG_WRITER#RRtwritetFLAG_LINE_BUFFEREDtrfindRR RR:RR(Rtdatatlast_newline_postwbuf((s1/usr/lib/python2.6/site-packages/paramiko/file.pyR<+s(    cCs"x|D]}|i|ƒqWdS(sb Write a sequence of strings to the file. The sequence can be any iterable object producing strings, typically a list of strings. (The name is intended to match L{readlines}; C{writelines} does not add line separators.) @param sequence: an iterable sequence of strings. @type sequence: sequence N(R<(RtsequenceR((s1/usr/lib/python2.6/site-packages/paramiko/file.pyt writelinesMs cCs|S(s¶ Identical to C{iter(f)}. This is a deprecated file interface that predates python iterator support. @return: an iterator. @rtype: iterator ((R((s1/usr/lib/python2.6/site-packages/paramiko/file.pyt xreadlines[scCs tƒ‚dS(s‰ I{(subclass override)} Read data from the stream. Return C{None} or raise C{EOFError} to indicate EOF. N(R"(RR%((s1/usr/lib/python2.6/site-packages/paramiko/file.pyR!iscCstdƒ‚dS(sL I{(subclass override)} Write data into the stream. swrite not implementedN(R(RR?((s1/usr/lib/python2.6/site-packages/paramiko/file.pyt_writeqscCsdS(so I{(subclass override)} Return the size of the file. This is called from within L{_set_mode} if the file is opened in append mode, so the file position can be tracked and L{seek} and L{tell} will work correctly. If the file is a stream that can't be randomly accessed, you don't need to override this method, i((R((s1/usr/lib/python2.6/site-packages/paramiko/file.pyt _get_sizexs triÿÿÿÿcCs¶|i|_|djo d}n|djo|i|i|iBO_nk|djo2||_|i|iO_|i|iM_n,|djo|i|i|iBM_nd|jp d|jo|i|iO_nd|jp d|jo|i|iO_nd|jo?|i|i|iBO_|iƒ|_ |i |_ |_ nd|jo|i|i O_nd|jo|i|i O_d |_nd S( sM Subclasses call this method to initialize the BufferedFile. iiRGt+twtatbtUN(RRRR#R=RR;t FLAG_APPENDRFRR Rt FLAG_BINARYR*RR(Rtmodetbufsize((s1/usr/lib/python2.6/site-packages/paramiko/file.pyt _set_mode‡s0          cCsx†t|ƒdjor|i|ƒ}||}|i|i@o&|i|7_|i|_|_q|i|7_|i|7_qWdS(Ni(R RERRMRR RR(RR?tcount((s1/usr/lib/python2.6/site-packages/paramiko/file.pyR¯s cCs™|i|i@pdS|idjo ||_nct|iƒtjo&|i|jo|i|f|_n'||ijo|i|f7_ndS(N(RR*RRttypetstr(Rtnewline((s1/usr/lib/python2.6/site-packages/paramiko/file.pyR+½s &N(#t__name__t __module__t__doc__RtSEEK_SETtSEEK_CURtSEEK_ENDRR;RMRNR#R=R*RRRRRRRR)RR6R9R:R<RCRDR!RERFRQRR+(((s1/usr/lib/python2.6/site-packages/paramiko/file.pyRs@      6 O   "     ( N(RXt cStringIORtobjectR(((s1/usr/lib/python2.6/site-packages/paramiko/file.pyts