Package paramiko :: Class BufferedFile
[show private | hide private]
[frames | no frames]

Type BufferedFile

object --+
         |
        BufferedFile

Known Subclasses:
SFTPFile

Reusable base class to implement python-style file buffering around a simpler stream.
Method Summary
  __init__(self)
  __del__(self)
iterator __iter__(self)
Returns an iterator that can be used to iterate over the lines in this file.
  close(self)
Close the file.
  flush(self)
Write out any data in the write buffer.
str next(self)
Returns the next line from the input, or raises StopIteration when EOF is hit.
str read(self, size)
Read at most size bytes from the file (less if we hit the end of the file first).
str readline(self, size)
Read one entire line from the file.
list readlines(self, sizehint)
Read all remaining lines using readline and return them as a list.
  seek(self, offset, whence)
Set the file's current position, like stdio's fseek.
int tell(self)
Return the file's current position.
  write(self, data)
Write data to the file.
  writelines(self, sequence)
Write a sequence of strings to the file.
iterator xreadlines(self)
Identical to iter(f).
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Class Variable Summary
int SEEK_CUR = 1                                                                     
int SEEK_END = 2                                                                     
int SEEK_SET = 0                                                                     

Method Details

__iter__(self)

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:
an interator.
           (type=iterator)
Raises:
ValueError - if the file is closed.

close(self)

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

flush(self)

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

next(self)

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:
a line read from the file.
           (type=str)
Raises:
StopIteration - when the end of the file is reached.

read(self, size=None)

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 - maximum number of bytes to read.
           (type=int)
Returns:
data read from the file, or an empty string if EOF was encountered immediately.
           (type=str)

readline(self, size=None)

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 - maximum length of returned string.
           (type=int)
Returns:
next line of the file, or an empty string if the end of the file has been reached.
           (type=str)

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

readlines(self, sizehint=None)

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 - desired maximum number of bytes to read.
           (type=int)
Returns:
list of lines read from the file.
           (type=list)

seek(self, offset, whence=0)

Set the file's current position, like stdio's fseek. Not all file objects support seeking.
Parameters:
offset - position to move to within the file, relative to whence.
           (type=int)
whence - type of movement: 0 = absolute; 1 = relative to the current position; 2 = relative to the end of the file.
           (type=int)
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)

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 (in bytes).
           (type=int)

write(self, data)

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 - data to write.
           (type=str)

writelines(self, sequence)

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 - an iterable sequence of strings.
           (type=sequence)

xreadlines(self)

Identical to iter(f). This is a deprecated file interface that predates python iterator support.
Returns:
an iterator.
           (type=iterator)

Class Variable Details

SEEK_CUR

Type:
int
Value:
1                                                                     

SEEK_END

Type:
int
Value:
2                                                                     

SEEK_SET

Type:
int
Value:
0                                                                     

Generated by Epydoc 2.1 on Sun Dec 4 11:16:47 2005 http://epydoc.sf.net