=OXc@szddlmZmZmZmZmZddlmZmZm Z m Z m Z ddl m Z de fdYZdS(i(tlinefeed_byte_valuetcrlftcr_bytet linefeed_bytet cr_byte_value(tBytesIOtPY2tutbt bytes_types(tClosingContextManagert BufferedFilecBs[eZdZdZdZdZdZdZdZdZ dZ dZ dZ d Z d Zd Zd Zd ZdZerdZn dZdZdZdZdZd&dZd&dZd&dZddZdZdZ dZ!dZ"e#dZ$dZ%dZ&d Z'd!d"d#Z(d$Z)d%Z*RS('sc Reusable base class to implement Python-style file buffering around a simpler stream. i iiiiii i@icCsed|_d|_|j|_t|_t|_t |_ t |_ d|_ |_ d|_dS(Ni(tNonetnewlinest_flagst_DEFAULT_BUFSIZEt_bufsizeRt_wbuffertbytest_rbuffertFalset_at_trailing_crt_closedt_post_realpost_size(tself((s1/usr/lib/python2.7/site-packages/paramiko/file.pyt__init__-s       cCs|jdS(N(tclose(R((s1/usr/lib/python2.7/site-packages/paramiko/file.pyt__del__<scCs|jrtdn|S(s 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. :raises ValueError: if the file is closed. sI/O operation on closed file(Rt ValueError(R((s1/usr/lib/python2.7/site-packages/paramiko/file.pyt__iter__?s cCs|jt|_dS(sN Close the file. Future read and write operations will fail. N(tflushtTrueR(R((s1/usr/lib/python2.7/site-packages/paramiko/file.pyRKs cCs&|j|jjt|_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.7/site-packages/paramiko/file.pyR Rs cCs|j}|stn|S(s_ Returns the next line from the input, or raises `~exceptions.StopIteration` when EOF is hit. Unlike Python file objects, it's okay to mix calls to `next` and `readline`. :raises StopIteration: when the end of the file is reached. :returns: a line (`str`) read from the file. (treadlinet StopIteration(Rtline((s1/usr/lib/python2.7/site-packages/paramiko/file.pytnext\s  cCs|j}|stn|S(sV Returns the next line from the input, or raises `.StopIteration` when EOF is hit. Unlike python file objects, it's okay to mix calls to `.next` and `.readline`. :raises StopIteration: when the end of the file is reached. :returns: a line (`str`) read from the file. (R$R%(RR&((s1/usr/lib/python2.7/site-packages/paramiko/file.pyt__next__ks  cCs|j|j@|jkS(s Check if the file can be read from. :returns: `True` if the file can be read from. If `False`, `read` will raise an exception. (Rt FLAG_READ(R((s1/usr/lib/python2.7/site-packages/paramiko/file.pytreadablezscCs|j|j@|jkS(s Check if the file can be written to. :returns: `True` if the file can be written to. If `False`, `write` will raise an exception. (Rt FLAG_WRITE(R((s1/usr/lib/python2.7/site-packages/paramiko/file.pytwritablescCstS(s Check if the file supports random access. :returns: `True` if the file supports random access. If `False`, `seek` will raise an exception. (R(R((s1/usr/lib/python2.7/site-packages/paramiko/file.pytseekablescCs/|jt|}||t|*t|S(s Read up to ``len(buff)`` bytes into :class:`bytearray` *buff* and return the number of bytes read. :returns: The number of bytes read. (treadtlen(Rtbufftdata((s1/usr/lib/python2.7/site-packages/paramiko/file.pytreadintoscCsX|jrtdn|j|j@s7tdn|dksO|dkr|j}t|_|jt|7_xt r y|j |j }Wnt k rd}nX|dkst|dkrPn||7}|j t|7_ |jt|7_q|W|S|t|jkr[|j| }|j||_|jt|7_|Sxt|j|kr!|t|j}|j|j@rt|j|}ny|j |}Wnt k rd}nX|dkst|dkrPn|j|7_|j t|7_ q^W|j| }|j||_|jt|7_|S(s Read at most ``size`` bytes from the file (less if we hit the end of the file first). If the ``size`` argument is negative or omitted, read all the remaining data in the file. .. note:: ``'b'`` mode flag is ignored (``self.FLAG_BINARY`` in ``self._flags``), because SSH treats all files as binary, since we have no idea what encoding the file is in, or even if the file is text data. :param int size: maximum number of bytes to read :returns: data read from the file (as bytes), or an empty string if EOF was encountered immediately sFile is closedsFile is not open for readingiN(RtIOErrorRR)R RRRR/R!t_readRtEOFErrorRt FLAG_BUFFEREDtmaxR(Rtsizetresulttnew_datat read_size((s1/usr/lib/python2.7/site-packages/paramiko/file.pyR.sP           c Cs|jrtdn|j|j@s7tdn|j}t}xtr|jr|j|j@rt |dkr|dt kr|d}|j t n |j t t|_n|dk r|dkrt ||kr|||_|| }t}Pn|t |}n |j}t|ksL|j|j@rPt |krPPny|j|}Wntk r|d}nX|dkst |dkrt|_|jt |7_|j|j@r|St|S||7}|jt |7_qIW|jt}|j|j@r[|jt }|dkr[||ksO|dkr[|}q[n|dkr|jt |7_|j|j@r|St|S|d}||tkr|t |kr||t kr|d7}n|r|||jn|||_|||!} || t}t |jdkrO| t krOt|_n |j | |jt |7_|j|j@r|St|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 ``fgets``, the returned string contains null characters (``'\0'``) if they occurred in the input. :param int size: maximum length of returned string. :returns: next line of the file, or an empty string if the end of the file has been reached. If the file was opened in binary (``'b'``) mode: bytes are returned Else: the encoding of the file is assumed to be UTF-8 and character strings (`str`) are returned sFile is closedsFile not open for readingiiiN(RR3RR)RRR!RtFLAG_UNIVERSAL_NEWLINER/Rt_record_newlineRRR RRR4R5RRt FLAG_BINARYRRtfindR( RR8R&t truncatedtnR:tpostrpostxpostlf((s1/usr/lib/python2.7/site-packages/paramiko/file.pyR$sh   +      (    $   2 $ !  cCsxg}d}xetrs|j}t|dkr7Pn|j||t|7}|dk r||krPqqW|S(s Read all remaining lines using `readline` and return them as a list. If the optional ``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 int sizehint: desired maximum number of bytes to read. :returns: `list` of lines read from the file. iN(R!R$R/tappendR (Rtsizehinttlinest byte_countR&((s1/usr/lib/python2.7/site-packages/paramiko/file.pyt readlines:s    cCstddS(s Set the file's current position, like stdio's ``fseek``. Not all file objects support seeking. .. note:: If a file is opened in append mode (``'a'`` or ``'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 int offset: position to move to within the file, relative to ``whence``. :param int whence: type of movement: 0 = absolute; 1 = relative to the current position; 2 = relative to the end of the file. :raises IOError: if the file doesn't support random access. sFile does not support seeking.N(R3(Rtoffsettwhence((s1/usr/lib/python2.7/site-packages/paramiko/file.pytseekPscCs|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. :returns: file position (`number ` of bytes). (R(R((s1/usr/lib/python2.7/site-packages/paramiko/file.pyttelldscCs1t|}|jr$tdn|j|j@sCtdn|j|j@sd|j|dS|jj||j|j @r|j t }|dkr|jj }|t |t |7}|j||d t|_|jj||dndS|jj|jkr-|jndS(s* Write data to the file. If write buffering is on (``bufsize`` was specified and non-zero), some or all of the data may not actually be written yet. (Use `flush` or `close` to force buffered data to be written out.) :param str data: data to write sFile is closedsFile not open for writingNii(RRR3RR+R6R"RtwritetFLAG_LINE_BUFFEREDtrfindRR#R/RRNRR (RR1tlast_newline_postwbuf((s1/usr/lib/python2.7/site-packages/paramiko/file.pyROns*      cCs"x|D]}|j|qWdS(sH 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 `readlines`; `writelines` does not add line separators.) :param iterable sequence: an iterable sequence of strings. N(RO(RtsequenceR&((s1/usr/lib/python2.7/site-packages/paramiko/file.pyt writeliness cCs|S(s Identical to ``iter(f)``. This is a deprecated file interface that predates Python iterator support. ((R((s1/usr/lib/python2.7/site-packages/paramiko/file.pyt xreadlinesscCs|jS(N(R(R((s1/usr/lib/python2.7/site-packages/paramiko/file.pytclosedscCs tdS(s (subclass override) Read data from the stream. Return ``None`` or raise ``EOFError`` to indicate EOF. N(R5(RR8((s1/usr/lib/python2.7/site-packages/paramiko/file.pyR4scCstddS(sI (subclass override) Write data into the stream. swrite not implementedN(R3(RR1((s1/usr/lib/python2.7/site-packages/paramiko/file.pyt_writescCsdS(si (subclass override) Return the size of the file. This is called from within `_set_mode` if the file is opened in append mode, so the file position can be tracked and `seek` and `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.7/site-packages/paramiko/file.pyt _get_sizes tricCs|j|_|dkr!d}n|dkrI|j|j|jBO_nf|dkr||_|j|jO_|j|jM_n)|dkr|j|j|jBM_nd|ksd|kr|j|jO_nd|ksd|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. iiRZt+twtaRtUN(RRRR6RPR)R+t FLAG_APPENDRYRRRR>R<R R (Rtmodetbufsize((s1/usr/lib/python2.7/site-packages/paramiko/file.pyt _set_modes0          cCsxt|dkr|j|}||}|j|j@rc|j|7_|j|_|_q|j|7_|j|7_qWdS(Ni(R/RXRR_RRRR (RR1tcount((s1/usr/lib/python2.7/site-packages/paramiko/file.pyR"s cCs|j|j@sdS|jdkr/||_nZ|j|kret|jtre|j|f|_n$||jkr|j|f7_ndS(N(RR<R R t isinstanceR (Rtnewline((s1/usr/lib/python2.7/site-packages/paramiko/file.pyR=s !N(+t__name__t __module__t__doc__RtSEEK_SETtSEEK_CURtSEEK_ENDR)R+R_R>R6RPR<RRRRR RR'R(R*R,R-R2R R.R$RJRMRNRORURVtpropertyRWR4RXRYRbR"R=(((s1/usr/lib/python2.7/site-packages/paramiko/file.pyR sN       ; [   "    ( N(tparamiko.commonRRRRRtparamiko.py3compatRRRRR t paramiko.utilR R (((s1/usr/lib/python2.7/site-packages/paramiko/file.pyts((