Package paramiko :: Module file :: Class BufferedFile
[frames] | no frames]

Class BufferedFile

source code

object --+
         |
        BufferedFile
Known Subclasses:

Reusable base class to implement Python-style file buffering around a simpler stream.

Instance Methods
 
__init__(self)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
__del__(self) source code
 
__iter__(self)
Returns an iterator that can be used to iterate over the lines in this file.
source code
 
close(self)
Close the file.
source code
 
flush(self)
Write out any data in the write buffer.
source code
 
next(self)
Returns the next line from the input, or raises `~exceptions.StopIteration` when EOF is hit.
source code
str
__next__(self)
Returns the next line from the input, or raises StopIteration when EOF is hit.
source code
 
read(self, size=None)
Read at most ``size`` bytes from the file (less if we hit the end of the file first).
source code
 
readline(self, size=None)
Read one entire line from the file.
source code
 
readlines(self, sizehint=None)
Read all remaining lines using `readline` and return them as a list.
source code
 
seek(self, offset, whence=0)
Set the file's current position, like stdio's ``fseek``.
source code
 
tell(self)
Return the file's current position.
source code
 
write(self, data)
Write data to the file.
source code
 
writelines(self, sequence)
Write a sequence of strings to the file.
source code
 
xreadlines(self)
Identical to ``iter(f)``.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables
  SEEK_SET = 0
  SEEK_CUR = 1
  SEEK_END = 2
  FLAG_READ = 1
  FLAG_WRITE = 2
  FLAG_APPEND = 4
  FLAG_BINARY = 16
  FLAG_BUFFERED = 32
  FLAG_LINE_BUFFERED = 64
  FLAG_UNIVERSAL_NEWLINE = 128
Properties
  closed

Inherited from object: __class__

Method Details

__init__(self)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

__iter__(self)

source code 

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.

close(self)

source code 

Close the file. Future read and write operations will fail.

flush(self)

source code 

Write out any data in the write buffer. This may do nothing if write buffering is not turned on.

next(self)

source code 

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.

:return: a line (`str`) read from the file.

__next__(self)

source code 

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.

Returns: str
a line read from the file.
Raises:
  • StopIteration - when the end of the file is reached.

read(self, size=None)

source code 

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
:return:
    data read from the file (as bytes), or an empty string if EOF was
    encountered immediately

readline(self, size=None)

source code 

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.
:return:
    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

readlines(self, sizehint=None)

source code 

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. :return: `list` of lines read from the file.

seek(self, offset, whence=0)

source code 

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.

tell(self)

source code 

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 (`number <int>` of bytes).

write(self, data)

source code 

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

writelines(self, sequence)

source code 

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.

xreadlines(self)

source code 

Identical to ``iter(f)``. This is a deprecated file interface that predates Python iterator support.


Property Details

closed

Get Method:
unreachable.closed(self)