Current File : //usr/lib/python2.7/site-packages/paramiko/file.pyc
�
=OXc@szddlmZmZmZmZmZddlmZmZm	Z	m
Z
mZddlm
Z
de
fd��YZdS(i����(tlinefeed_byte_valuetcrlftcr_bytet
linefeed_bytet
cr_byte_value(tBytesIOtPY2tutbtbytes_types(tClosingContextManagertBufferedFilecBs[eZdZdZdZdZdZdZdZdZ	dZ
dZdZd	Z
d
�Zd�Zd�Zd
�Zd�Zer�d�Zn	d�Zd�Zd�Zd�Zd�Zd&d�Zd&d�Zd&d�Zdd�Zd�Zd�Z d�Z!d�Z"e#d��Z$d�Z%d�Z&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@i�cCsed|_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|j�dS(N(tclose(R((s1/usr/lib/python2.7/site-packages/paramiko/file.pyt__del__<scCs|jrtd��n|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|j�t|_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|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((s1/usr/lib/python2.7/site-packages/paramiko/file.pyR RscCs|j�}|st�n|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�}|st�n|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.pytwritable�scCstS(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.pytseekable�scCs/|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.pytreadinto�scCsX|jrtd��n|j|j@s7td��n|dksO|dkr|j}t�|_|jt|�7_x�t	ry|j
|j�}Wntk
r�d}nX|dks�t|�dkr�Pn||7}|j
t|�7_
|jt|�7_q|W|S|t|j�kr[|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 ``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�|jrtd��n|j|j@s7td��n|j}t}x�tr�|jr�|j|j@r�t	|�dkr�|dt
kr�|d}|jt�n
|jt
�t|_n|dk	r|dkrt	|�|kr|||_|| }t}Pn|t	|�}n	|j}t|ksL|j|j@rPt
|krPPny|j|�}Wntk
r|d}nX|dks�t	|�dkr�t�|_|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	|j�dkrO|	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 readingiii����N(RR3RR)RRR!RtFLAG_UNIVERSAL_NEWLINER/Rt_record_newlineRRRRRR4R5RRtFLAG_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
	
cCstd��dS(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 <int>` of bytes).
        (R(R((s1/usr/lib/python2.7/site-packages/paramiko/file.pyttelldscCs1t|�}|jr$td��n|j|j@sCtd��n|j|j@sd|j|�dS|jj|�|j|j	@r|j
t�}|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 (``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
writelines�s	
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
xreadlines�scCs|jS(N(R(R((s1/usr/lib/python2.7/site-packages/paramiko/file.pytclosed�scCs
t��dS(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.pyR4�scCstd��dS(sI
        (subclass override)
        Write data into the stream.
        swrite not implementedN(R3(RR1((s1/usr/lib/python2.7/site-packages/paramiko/file.pyt_write�scCsdS(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_size�s	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.
        iiRZt+twtaRtUN(RRRR6RPR)R+tFLAG_APPENDRYRRRR>R<RR
(Rtmodetbufsize((s1/usr/lib/python2.7/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/RXRR_RRRR(RR1tcount((s1/usr/lib/python2.7/site-packages/paramiko/file.pyR"�s
cCs�|j|j@sdS|jdkr/||_nZ|j|kret|jt�re|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.pyRsN								
	
	
	;[	
	"	
				
(	N(tparamiko.commonRRRRRtparamiko.py3compatRRRRR	t
paramiko.utilR
R(((s1/usr/lib/python2.7/site-packages/paramiko/file.pyt<module>s((