Package grizzled :: Package io :: Class PushbackFile
[hide private]
[frames] | no frames]

Class PushbackFile

source code

object --+
         |
        PushbackFile

A file-like wrapper object that permits pushback.
Instance Methods [hide private]
 
__init__(self, f)
Create a new PushbackFile object to wrap a file-like object.
source code
 
write(self, buf)
Write the specified buffer to the file.
source code
 
pushback(self, s)
Push a character or string back onto the input stream.
source code
 
unread(self, s)
Push a character or string back onto the input stream.
source code
 
read(self, n=-1)
Read n bytes from the open file.
source code
str
readline(self, length=-1)
Read the next line from the file.
source code
list
readlines(self, sizehint=0)
Read all remaining lines in the file.
source code
 
__iter__(self) source code
str
next(self)
A file object is its own iterator.
source code
 
close(self)
Close the file.
source code
 
flush(self)
Force a flush.
source code
 
truncate(self, size=-1)
Truncate the underlying file.
source code
int
tell(self)
Return the file's current position, if applicable.
source code
 
seek(self, offset, whence=0)
Set the file's current position.
source code
int
fileno(self)
Return the integer file descriptor used by the underlying file.
source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, f)
(Constructor)

source code 
Create a new PushbackFile object to wrap a file-like object.
Parameters:
  • f (file) - A file-like object that contains both a write() method and a flush() method.
Overrides: object.__init__

write(self, buf)

source code 
Write the specified buffer to the file. This method throws an unconditional exception, since PushbackFile objects are read-only.
Parameters:
  • buf (str or bytes) - buffer to write
Raises:
  • NotImplementedError - unconditionally

pushback(self, s)

source code 
Push a character or string back onto the input stream.
Parameters:
  • s (str) - the string to push back onto the input stream

unread(self, s)

source code 
Push a character or string back onto the input stream.
Parameters:
  • s (str) - the string to push back onto the input stream

read(self, n=-1)

source code 
Read n bytes from the open file.
Parameters:
  • n (int) - Number of bytes to read. A negative number instructs read() to read all remaining bytes.
Returns:
the bytes read

readline(self, length=-1)

source code 
Read the next line from the file.
Parameters:
  • length (int) - a length hint, or negative if you don't care
Returns: str
the line

readlines(self, sizehint=0)

source code 
Read all remaining lines in the file.
Returns: list
list of lines

next(self)

source code 
A file object is its own iterator.
Returns: str
the next line from the file
Raises:

close(self)

source code 
Close the file. A no-op in this class.

flush(self)

source code 
Force a flush. This method throws an unconditional exception, since PushbackFile objects are read-only.
Raises:
  • NotImplementedError - unconditionally

truncate(self, size=-1)

source code 
Truncate the underlying file. This method throws an unconditional exception, since PushbackFile objects are read-only.
Parameters:
  • size (int) - Where to truncate. If less than 0, then file's current position is used
Raises:
  • NotImplementedError - unconditionally

tell(self)

source code 
Return the file's current position, if applicable. This method throws an unconditional exception, since PushbackFile objects are read-only.
Returns: int
Current file position
Raises:
  • NotImplementedError - unconditionally

seek(self, offset, whence=0)

source code 
Set the file's current position. This method throws an unconditional exception, since PushbackFile objects are not seekable.
Parameters:
  • offset (int) - where to seek
  • whence (int) - see above
Raises:
  • NotImplementedError - unconditionally

fileno(self)

source code 
Return the integer file descriptor used by the underlying file.
Returns: int
the file descriptor