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.
Basic class for defining a stream-like transport.
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 the specified amount of bytes (at most) from the stream.
Read until the specified delimiter is found.
Read until the given regular expression is matched.
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.
Close the write side of a stream and flush the pending data.
Close the stream. All further operations will raise an exception. Any buffered data will be lost.
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.
Base class for writing servers which use a stream-like transport.
Bind the server to the specified address. The address will be different depending on the particular server implementation.
Start listening for incoming connections. The caller will block until the server is stopped with a call to close.
Close the server. All active connections are also closed.
Abstract method which subclasses need to implement in order handle incoming connections.
List of currently active connections.
Base class representing a connection handled by a StreamServer.
Reference to the StreamServer which accepted the connection.
Close the connection.
Internal API method: sets the connection state to accepted.
Base class for stream related errors.
Class representing a TCP client.
Returns the local address.
Returns the remote endpoint’s 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 representing a TCP server.
Returns the local address where the server is listening.
Class representing a TCP connection handled by a TCP server.
Returns the local address.
Returns the remote endpoint’s address.
Class for representing all TCP related errors.
Class representing a named pipe client.
Connects to the specified named pipe.
Class representing a named pipe server.
Returns the name of the pipe to which the server is bound.
Class representing a connection to a named pipe server.
Opens the given file descriptor (or Windows HANDLE) and allows for using it as a regular pipe stream.
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.
Class for representing all Pipe related errors.
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.
Returns the current window size.
If set to True, sets this TTY handle in raw mode.
Convenience class to use stdin as a cooperative stream.
Convenience class to use stdout as a cooperative stream.
Convenience class to use stderr as a cooperative stream.
Class for representing all TTY related errors.
Class representing a UDP endpoint. UDP endpoints can be both servers and clients.
Class for representing all UDP related errors.
Returns the local address.
Bind the endpoint to the specified IPv4 or IPv6 address.
Write data to the specified address.
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 the stream. All further operations will raise an exception.
Mapping between errno codes and their names.
Returns error string representation.
All error number constants are defined in the errno submodule.