Package paramiko :: 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
 
__del__(self) source code
 
__init__(self)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
iterator
__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
str
next(self)
Returns the next line from the input, or raises StopIteration when EOF is hit.
source code
str
read(self, size=None)
Read at most size bytes from the file (less if we hit the end of the file first).
source code
str
readline(self, size=None)
Read one entire line from the file.
source code
list
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
int
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
iterator
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
  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

Inherited from object: __class__

Method Details

__init__(self)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ 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.

Returns: iterator
an interator.
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 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.

Parameters:
  • size (int) - maximum number of bytes to read
Returns: str
data read from the file, 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.

Parameters:
  • size (int) - maximum length of returned string.
Returns: str
next line of the file, or an empty string if the end of the file has been reached.

Note: Unlike stdio's fgets(), the returned string contains null characters ('\0') if they occurred in the input.

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.

Parameters:
  • sizehint (int) - desired maximum number of bytes to read.
Returns: list
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.

Parameters:
  • offset (int) - position to move to within the file, relative to whence.
  • whence (int) - 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.

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).

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.

Returns: int
file position (in 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.)

Parameters:
  • data (str) - 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.)

Parameters:
  • sequence (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.

Returns: iterator
an iterator.