ó õùPc@s0dZddlmZdefd„ƒ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|_|j|_tƒ|_d|_t|_ t|_ d|_ |_ d|_ dS(Nit(tNonetnewlinest_flagst_DEFAULT_BUFSIZEt_bufsizeRt_wbuffert_rbuffertFalset_at_trailing_crt_closedt_post_realpost_size(tself((s(..\python\site-packages\paramiko\file.pyt__init__.s       cCs|jƒdS(N(tclose(R((s(..\python\site-packages\paramiko\file.pyt__del__=scCs|jrtdƒ‚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((s(..\python\site-packages\paramiko\file.pyt__iter__@s cCs|jƒt|_dS(sN Close the file. Future read and write operations will fail. N(tflushtTrueR (R((s(..\python\site-packages\paramiko\file.pyROs cCs&|j|jjƒƒ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((s(..\python\site-packages\paramiko\file.pyRVs cCs|jƒ}|st‚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((s(..\python\site-packages\paramiko\file.pytnext_s  cCsU|jrtdƒ‚n|j|j@s7tdƒ‚n|dksO|dkr |j}d|_|jt|ƒ7_xtry|j |j ƒ}Wnt k r®d}nX|dksÍt|ƒdkrÑPn||7}|j t|ƒ7_ |jt|ƒ7_qyW|S|t|jƒkrX|j| }|j||_|jt|ƒ7_|SxÄt|jƒ|kr|t|jƒ}|j|j @r¨t|j|ƒ}ny|j |ƒ}Wnt k rÔd}nX|dksót|ƒdkr÷Pn|j|7_|j t|ƒ7_ q[W|j| }|j||_|jt|ƒ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((s(..\python\site-packages\paramiko\file.pytreadosP           c Cs |jrtdƒ‚n|j|j@s7tdƒ‚n|j}x¦trè|jr·|j|j@r·t|ƒdkr·|ddkrž|d}|j dƒn |j dƒt |_n|d k r$|dkr$t|ƒ|kr|||_|| }|j t|ƒ7_ |S|t|ƒ}n |j }d|ksU|j|j@rYd|krYPny|j|ƒ}Wntk r…d }nX|d ks¤t|ƒdkrÆd|_|j t|ƒ7_ |S||7}|jt|ƒ7_qCW|jdƒ}|j|j@rG|jdƒ}|dkrG||ks;|dkrG|}qGn|d}||dkr|t|ƒkr||dkr|d7}n|||_|||!}|| d}t|jƒdkrå|dkråt|_n |j |ƒ|j 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((s(..\python\site-packages\paramiko\file.pyR¥s`   +      (    $  2   !  cCsxg}d}xetrs|jƒ}t|ƒdkr7Pn|j|ƒ|t|ƒ7}|dk r||krPqqW|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((s(..\python\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((s(..\python\site-packages\paramiko\file.pytseek scCs|jS(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((s(..\python\site-packages\paramiko\file.pyttell s cCs%|jrtdƒ‚n|j|j@s7tdƒ‚n|j|j@sX|j|ƒdS|jj|ƒ|j|j@rü|j dƒ}|dkrø|jj ƒ}|t |ƒt |ƒ7}|j||d ƒt ƒ|_|jj||dƒndS|jj ƒ|jkr!|jƒ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((s(..\python\site-packages\paramiko\file.pyR<+s(     cCs"x|D]}|j|ƒ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((s(..\python\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((s(..\python\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%((s(..\python\site-packages\paramiko\file.pyR!iscCstdƒ‚dS(sL I{(subclass override)} Write data into the stream. swrite not implementedN(R(RR?((s(..\python\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((s(..\python\site-packages\paramiko\file.pyt _get_sizexs triÿÿÿÿcCs¢|j|_|dkr!d}n|dkrI|j|j|jBO_nf|dkr†||_|j|jO_|j|jM_n)|dkr¯|j|j|jBM_nd|ksÇd|krÜ|j|jO_nd|ksôd|kr |j|jO_nd|krS|j|j|jBO_|jƒ|_ |j |_ |_ nd|krt|j|j O_nd|krž|j|j 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((s(..\python\site-packages\paramiko\file.pyt _set_mode‡s0          cCs‰x‚t|ƒdkr„|j|ƒ}||}|j|j@rc|j|7_|j|_|_q|j|7_|j|7_qWdS(Ni(R RERRMRR RR(RR?tcount((s(..\python\site-packages\paramiko\file.pyR¯s cCs|j|j@sdS|jdkr/||_n]t|jƒtkrh|j|krh|j|f|_n$||jkrŒ|j|f7_ndS(N(RR*RRttypetstr(Rtnewline((s(..\python\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+(((s(..\python\site-packages\paramiko\file.pyRs@      6 O   "     ( N(RXt cStringIORtobjectR(((s(..\python\site-packages\paramiko\file.pyts