I/O utilities

The io module provides utility classes for writing cooperative servers and clients in an easy way.

Note

This module is still quite experimental, API changes are expected.

class evergreen.io.BaseStream

Basic class for defining a stream-like transport.

closed

Returns True if the stream is closed, False otherwise. Once the stream is closed an exception will be raised if any operation is attempted.

read_bytes(nbytes)

Read the specified amount of bytes (at most) from the stream.

read_until(delimiter)

Read until the specified delimiter is found.

read_until_regex(regex)

Read until the given regular expression is matched.

write(data)

Write data on the stream. Return True if data was flushed to the underlying resource and False in case the data was buffered and will be sent later.

shutdown()

Close the write side of a stream and flush the pending data.

close()

Close the stream. All further operations will raise an exception. Any buffered data will be lost.

_set_connected()

This method is part of the internal API. It sets the stream state to connected. Before a stream is connected all write operations will be buffered and flushed once the stream is connected.

class evergreen.io.StreamServer

Base class for writing servers which use a stream-like transport.

bind(address)

Bind the server to the specified address. The address will be different depending on the particular server implementation.

serve([backlog])

Start listening for incoming connections. The caller will block until the server is stopped with a call to close.

close()

Close the server. All active connections are also closed.

handle_connection(connection)

Abstract method which subclasses need to implement in order handle incoming connections.

connections

List of currently active connections.

class evergreen.io.StreamConnection

Base class representing a connection handled by a StreamServer.

server

Reference to the StreamServer which accepted the connection.

close()

Close the connection.

_set_accepted(server)

Internal API method: sets the connection state to accepted.

exception evergreen.io.StreamError

Base class for stream related errors.

class evergreen.io.TCPClient

Class representing a TCP client.

sockname

Returns the local address.

peername

Returns the remote endpoint’s address.

connect(target[, source_address])

Start an outgoing connection towards the specified target. If source_address is specified the socket will be bound to it, else the system will pick an appropriate one.

class evergreen.io.TCPServer

Class representing a TCP server.

sockname

Returns the local address where the server is listening.

class evergreen.io.TCPConnection

Class representing a TCP connection handled by a TCP server.

sockname

Returns the local address.

peername

Returns the remote endpoint’s address.

exception evergreen.io.TCPError

Class for representing all TCP related errors.

class evergreen.io.PipeClient

Class representing a named pipe client.

connect(target)

Connects to the specified named pipe.

class evergreen.io.PipeServer

Class representing a named pipe server.

pipename

Returns the name of the pipe to which the server is bound.

class evergreen.io.PipeConnection

Class representing a connection to a named pipe server.

open(fd)

Opens the given file descriptor (or Windows HANDLE) and allows for using it as a regular pipe stream.

class evergreen.io.PipeStream

Class representing generic pipe stream. Currently it can only be used to open an arbitrary file descriptor such as /dev/net/tun and treat it as a pipe stream.

exception evergreen.io.PipeError

Class for representing all Pipe related errors.

class evergreen.io.TTYStream(fd, readable)

Class representing a TTY stream. The specified fd is opened as a TTY, so make sure it’s already a TTY. If you plan on reading from this stream specify readable as True.

winsize

Returns the current window size.

set_raw_mode(enable)

If set to True, sets this TTY handle in raw mode.

class evergreen.io.StdinStream

Convenience class to use stdin as a cooperative stream.

class evergreen.io.StdoutStream

Convenience class to use stdout as a cooperative stream.

class evergreen.io.StderrStream

Convenience class to use stderr as a cooperative stream.

exception evergreen.io.TTYError

Class for representing all TTY related errors.

class evergreen.io.UDPEndpoint

Class representing a UDP endpoint. UDP endpoints can be both servers and clients.

exception evergreen.io.UDPError

Class for representing all UDP related errors.

sockname

Returns the local address.

bind(address)

Bind the endpoint to the specified IPv4 or IPv6 address.

send(data, address)

Write data to the specified address.

receive()

Wait for incoming data. The return value is a tuple consisting of the received data and the source IP address where it was received from.

close()

Close the stream. All further operations will raise an exception.

errno.errorcode()

Mapping between errno codes and their names.

errno.strerror(errorno)

Returns error string representation.

errno.EXXX

All error number constants are defined in the errno submodule.

Previous topic

Futures

Next topic

Monkeypatching support

This Page