| Home | Trees | Indices | Help |
|---|
|
|
object --+
|
BufferedFile
Reusable base class to implement Python-style file buffering around a simpler stream.
| Instance Methods | |||
|
|||
|
|||
|
|||
| str |
|
||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
Inherited from |
|||
| Class Variables | |
FLAG_APPEND = 4
|
|
FLAG_BINARY = 16
|
|
FLAG_BUFFERED = 32
|
|
FLAG_LINE_BUFFERED = 64
|
|
FLAG_READ = 1
|
|
FLAG_UNIVERSAL_NEWLINE = 128
|
|
FLAG_WRITE = 2
|
|
SEEK_CUR = 1
|
|
SEEK_END = 2
|
|
SEEK_SET = 0
|
|
| Properties | |
| closed | |
|
Inherited from |
|
| Method Details |
x.__init__(...) initializes x; see help(type(x)) for signature
|
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. |
Returns the next line from the input, or raises
|
Close the file. Future read and write operations will fail. |
Write out any data in the write buffer. This may do nothing if write buffering is not turned on. |
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. |
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
|
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
|
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. |
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.
|
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 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 |
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. |
Identical to ``iter(f)``. This is a deprecated file interface that predates Python iterator support. |
| Property Details |
closed
|
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Thu May 7 11:49:47 2015 | http://epydoc.sourceforge.net |