Simple IO channels library
Project description
Channels
Simple wrapper around file objects and sockets that provides uniform interface to both.
Example:
pipe_chan = PipeChannel(sys.stdin.fileno(), sys.stdout.fileno())
sock_chan = SocketChannel(socket.create_connection(('127.0.0.1', 8080))
Classes
Channel
Channel is the base class for different channels. Every channel implements the following methods:
read(self)
Performs a non-blocking read and returns any bytes available. Raises
EndpointClosedException
if the channel is closed.
write(self, *data)
Writes chunks of bytes to the channel. Raises EndpointClosedException
.
close(self)
Closes the channel and frees up the resources.
get_fd(self)
Returns a file descriptor number that can be used for poll
or
epoll
for reading. Raises NotImplementedError
if (custom) channel
doesn't support reading.
The following channel classes are implemented:
PipeChannel
PipeChannel(faucet=None, sink=None)
faucet
should be a file descriptor open for reading. sink
should
be a file descriptor open for writing. If both are provided, the
channel is bi-directional. Sets faucet
to non-blocking mode.
SocketChannel
SocketChannel(sock)
Wraps a socket for non-blocking IO.
LineChannel
LineChannel(channel)
Accepts another channel. read()
returns one line at time or b''
if
no full line is available. If underlying channel is closed, read()
will keep returning lines until everything is returned (last line
might not be ending with b'\n'
).
TestChannel
(in package channels.testing)
Provides put
and get
methods to to feed data to read
and fetch "written" data respectively.
Poller
Poller is a wrapper for select.poll
that also supports accepting and
keeping track of TCP/Unix clients.
register(self, channel)
Registers the channel for polling.
add_server(self, sock)
Registers a server socket. Poller will accept incoming connections and automatically register clients.
unregister(self, channel)
Removes a registered channel.
close_all(self)
Closes all registered channels and servers.
poll(self, timeout=None)
Performs a single call to select.poll()
. timeout
is the number of
seconds for polling or None
for infinite polling. Return value is a
list of pairs in format of (data, channel)
for channels and ((addr, client_channel), sock)
for server sockets. addr
depends on socket
type.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for yet-another-io-channels-library-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | caf47cc40389c1281bdc117dfcda68852f10dc738f85cc48a816a913273ae5de |
|
MD5 | 39fad0f6182370f3a87b09bc1cb5cfbc |
|
BLAKE2b-256 | 9eb1b49abb508c527b2e58b21e4f400507a56be92540434bddb4983d8608e211 |
Hashes for yet_another_io_channels_library-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0f20cc18c83d21619da15fa430d7c16f56439e6819a2eafe0554a5def05466d |
|
MD5 | 3b3d9f7afa852453f648296fd7474aab |
|
BLAKE2b-256 | f4eb3b551c68ad399bf9fa12c1c290fb4aa2bc1ba2465905a3addbff9d5d2d5d |