Package wtf :: Module stream :: Class GenericStream
[hide private]
[frames] | no frames]

Class GenericStream

source code

object --+
         |
        GenericStream
Known Subclasses:

Represents a buffered stream
Instance Methods [hide private]
 
__del__(self) source code
 
__iter__(self)
Iterator generator
source code
str
_bufferedread(self, size)
Read a specified amount of bytes (at max) from the stream
source code
 
_unread(self, tounread)
Pushes tounread octets back
source code
 
close(self)
Close the stream
source code
 
fileno(self)
Determine underlying fileno
source code
 
flush(self, _passdown=True)
Flush the write buffer
source code
bool
isatty(self)
Does the stream refer to a tty?
source code
 
next(self)
Return the next line or block
source code
str
read(self, size=-1)
Reads a specified amount of bytes (at max) from the stream
source code
str
read_exact(self, size=-1)
Read exactly size bytes from stream, except on EOF
source code
str
readline(self, size=0)
Read a line from the stream
source code
 
readlines(self, size=0)
Returns all lines as a list
source code
 
write(self, data)
Write data into the stream
source code
 
writelines(self, lines)
Write lines to the stream
source code
 
xreadlines(self)
Iterator of the lines
source code

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

Static Methods [hide private]
a new object with type S, a subtype of T

__new__(cls, stream, buffering=-1, blockiter=1, read_exact=False)
Construction
source code
Class Variables [hide private]
int _DEFAULT_CHUNK_SIZE = 8192
Default buffer size
Instance Variables [hide private]
int _blockiter
Block iteration size (1: block = line)
int _chunk_size
Actual buffer size to use
bool _closed = True
Is the stream closed?
callable _flush
underlying flush function
file _octet_stream = None
The stream to actually fetch the data from
list _rbuffer
read buffer
list _wbuffer
write buffer
bool softspace = False
Softspace parameter
Properties [hide private]
bool closed
Is the stream is closed?
str name
The name of the stream, if any

Inherited from object: __class__

Method Details [hide private]

__new__(cls, stream, buffering=-1, blockiter=1, read_exact=False)
Static Method

source code 
Construction
Parameters:
  • stream (file) - The low level stream
  • buffering (int) - The buffer specification: (< 0: default buffer size, ==0: unbuffered, >0: this very buffer size)
  • blockiter (int) - iteration block spec (<= 0: default chunk, 1: line, > 1: this blocksize)
  • read_exact (bool) - Try reading up to the requested size? If False, a simple .read(size) will always yield the chunk size at max. This is normal behaviour on slow calls, e.g. sockets. However, some software expects to get the maximum (or even the exact value) bytes. In this case use a stream with read_exact set to True.
Returns:
a new object with type S, a subtype of T

Overrides: object.__new__

_bufferedread(self, size)

source code 
Read a specified amount of bytes (at max) from the stream
Parameters:
  • size (int) - The maximum number of bytes to read (< 0 means to slurp the whole stream; == 0 means to return the current buffer or the next buffer it the current buffer is empty)
Returns: str
The read bytes; if empty you've hit EOF
Raises:
  • ValueError - The stream is closed

_unread(self, tounread)

source code 
Pushes tounread octets back
Parameters:
  • tounread (str) - The buffer to push back

close(self)

source code 

Close the stream

The call is passed to the underlying octet stream.

flush(self, _passdown=True)

source code 
Flush the write buffer
Parameters:
  • _passdown (bool) - Call flush() on the underlying stream, too

isatty(self)

source code 
Does the stream refer to a tty?
Returns: bool
Does the stream refer to a tty?

read(self, size=-1)

source code 
Reads a specified amount of bytes (at max) from the stream
Parameters:
  • size (int) - The maximum number of bytes to read (< 0 means to slurp the whole stream; == 0 means to return the current buffer or the next buffer it the current buffer is empty)
Returns: str
The read bytes; if empty you've hit EOF
Raises:
  • ValueError - The stream is closed

read_exact(self, size=-1)

source code 
Read exactly size bytes from stream, except on EOF
Parameters:
  • size (int) - expected number of bytes
Returns: str
The read bytes

readline(self, size=0)

source code 
Read a line from the stream
Parameters:
  • size (int) - The maximum number of bytes to read (<= 0 means to read until the next newline or EOF, which is the default behaviour)
Returns: str
The read bytes including the newline; if empty you've hit EOF

readlines(self, size=0)

source code 
Returns all lines as a list
Parameters:
  • size (int) - Maximum size for a single line.

write(self, data)

source code 
Write data into the stream
Parameters:
  • data (str) - The data to write

writelines(self, lines)

source code 
Write lines to the stream
Parameters:
  • lines (iterable) - The list of lines to write

xreadlines(self)

source code 
Iterator of the lines

Deprecated: Use the iterator API instead


Property Details [hide private]

closed

Is the stream is closed?
Get Method:
unreachable.fget(self)
Type:
bool

name

The name of the stream, if any
Get Method:
unreachable.fget(self)
Type:
str