# Channels [![Build Status](https://travis-ci.com/aragaer/channels.svg?branch=master)](https://travis-ci.com/aragaer/channels) [![codecov](https://codecov.io/gh/aragaer/channels/branch/master/graph/badge.svg)](https://codecov.io/gh/aragaer/channels) [![BCH compliance](https://bettercodehub.com/edge/badge/aragaer/channels?branch=master)](https://bettercodehub.com/results/aragaer/channels) [![donate using paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=aragaer@gmail.com&lc=RU&item_name=CHANNELS¤cy_code=USD&bn=PP-DonationsBF:btn_donate_SM.gif:NonHosted)
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.
Every channel has a `buffering` property (read-only). It is equal to
`'line'` for line-buffered channels. It should be `'bytes'` otherwise
but any value other than `'line'` works.
The following channel classes are implemented:
### PipeChannel
`PipeChannel(faucet=None, sink=None, *, buffering='bytes')`
`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.
If `buffering` is set to `'line'` the channel uses line-buffering for
reading. Every `read` call will return `b''` if there is no complete
line available even if there is any data at all. If channel is closed
but there is data in buffer, calls to `read` will return lines from
buffer until it is exhausted. Last line maybe an incomplete line (no
`'\n'` in the end).
### SocketChannel
`SocketChannel(sock, *, buffering='bytes')`
Wraps a socket for non-blocking IO. See PipeChannel for more info on
`buffering` parameter.
### TestChannel
(in package channels.testing)
`TestChannel(*, buffering='bytes')`
See PipeChannel for more info on `buffering` parameter.
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.
`Poller(*, buffering='bytes')`
Creates a poller object. All accepted client channels inherit the
`buffering` parameter.
`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. Silently does nothing if channel is not
registered.
`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. For line-based channels single `poll` call will return one
result for every line available.
Raw data
{
"_id": null,
"home_page": "https://github.com/aragaer/channels",
"name": "yet-another-io-channels-library",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "socket pipe",
"author": "Ilya Konovalov",
"author_email": "aragaer@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/eb/e2/512a537cdb2dbd6fef19d4b87275d4ca14b5c1581abf4880cd6b2094aad4/yet-another-io-channels-library-0.2.2.tar.gz",
"platform": "UNIX",
"description": "# Channels [![Build Status](https://travis-ci.com/aragaer/channels.svg?branch=master)](https://travis-ci.com/aragaer/channels) [![codecov](https://codecov.io/gh/aragaer/channels/branch/master/graph/badge.svg)](https://codecov.io/gh/aragaer/channels) [![BCH compliance](https://bettercodehub.com/edge/badge/aragaer/channels?branch=master)](https://bettercodehub.com/results/aragaer/channels) [![donate using paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=aragaer@gmail.com&lc=RU&item_name=CHANNELS¤cy_code=USD&bn=PP-DonationsBF:btn_donate_SM.gif:NonHosted)\n\nSimple wrapper around file objects and sockets that provides uniform\ninterface to both.\n\nExample:\n\n pipe_chan = PipeChannel(sys.stdin.fileno(), sys.stdout.fileno())\n\tsock_chan = SocketChannel(socket.create_connection(('127.0.0.1', 8080))\n\n## Classes\n\n### Channel\nChannel is the base class for different channels. Every channel\nimplements the following methods:\n\n`read(self)`\n\nPerforms a non-blocking read and returns any bytes available. Raises\n`EndpointClosedException` if the channel is closed.\n\n`write(self, *data)`\n\nWrites chunks of bytes to the channel. Raises `EndpointClosedException`.\n\n`close(self)`\n\nCloses the channel and frees up the resources.\n\n`get_fd(self)`\n\nReturns a file descriptor number that can be used for `poll` or\n`epoll` for reading. Raises `NotImplementedError` if (custom) channel\ndoesn't support reading.\n\nEvery channel has a `buffering` property (read-only). It is equal to\n`'line'` for line-buffered channels. It should be `'bytes'` otherwise\nbut any value other than `'line'` works.\n\nThe following channel classes are implemented:\n\n### PipeChannel\n\n`PipeChannel(faucet=None, sink=None, *, buffering='bytes')`\n\n`faucet` should be a file descriptor open for reading. `sink` should\nbe a file descriptor open for writing. If both are provided, the\nchannel is bi-directional. Sets `faucet` to non-blocking mode.\n\nIf `buffering` is set to `'line'` the channel uses line-buffering for\nreading. Every `read` call will return `b''` if there is no complete\nline available even if there is any data at all. If channel is closed\nbut there is data in buffer, calls to `read` will return lines from\nbuffer until it is exhausted. Last line maybe an incomplete line (no\n`'\\n'` in the end).\n\n### SocketChannel\n\n`SocketChannel(sock, *, buffering='bytes')`\n\nWraps a socket for non-blocking IO. See PipeChannel for more info on\n`buffering` parameter.\n\n### TestChannel\n\n(in package channels.testing)\n\n`TestChannel(*, buffering='bytes')`\n\nSee PipeChannel for more info on `buffering` parameter.\n\nProvides `put` and `get` methods to to feed data to `read` and fetch\n\"written\" data respectively.\n\n### Poller\nPoller is a wrapper for `select.poll` that also supports accepting and\nkeeping track of TCP/Unix clients.\n\n`Poller(*, buffering='bytes')`\n\nCreates a poller object. All accepted client channels inherit the\n`buffering` parameter.\n\n`register(self, channel)`\n\nRegisters the channel for polling.\n\n`add_server(self, sock)`\n\nRegisters a server socket. Poller will accept incoming connections and\nautomatically register clients.\n\n`unregister(self, channel)`\n\nRemoves a registered channel. Silently does nothing if channel is not\nregistered.\n\n`close_all(self)`\n\nCloses all registered channels and servers.\n\n`poll(self, timeout=None)`\n\nPerforms a single call to `select.poll()`. `timeout` is the number of\nseconds for polling or `None` for infinite polling. Return value is a\nlist of pairs in format of `(data, channel)` for channels and `((addr,\nclient_channel), sock)` for server sockets. `addr` depends on socket\ntype. For line-based channels single `poll` call will return one\nresult for every line available.\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Simple IO channels library",
"version": "0.2.2",
"project_urls": {
"Homepage": "https://github.com/aragaer/channels"
},
"split_keywords": [
"socket",
"pipe"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "67b97abf8ac1e8629eba2055ba9f07de93b18786cc6953f699d1785088b5d806",
"md5": "f1625d78791c6920a6ab55440424b163",
"sha256": "478d757b9c657e6378b385ea743ecbf48e903d5ae4d1dfa2390331a41e23f1e1"
},
"downloads": -1,
"filename": "yet_another_io_channels_library-0.2.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f1625d78791c6920a6ab55440424b163",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 6489,
"upload_time": "2018-11-05T16:39:29",
"upload_time_iso_8601": "2018-11-05T16:39:29.000856Z",
"url": "https://files.pythonhosted.org/packages/67/b9/7abf8ac1e8629eba2055ba9f07de93b18786cc6953f699d1785088b5d806/yet_another_io_channels_library-0.2.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ebe2512a537cdb2dbd6fef19d4b87275d4ca14b5c1581abf4880cd6b2094aad4",
"md5": "a6078f87bc758f1cd90220a3974f869d",
"sha256": "00b1c077e13955248afe3f6d7bac86643a18d28d9f1d595a6daf9f993cd0edc1"
},
"downloads": -1,
"filename": "yet-another-io-channels-library-0.2.2.tar.gz",
"has_sig": false,
"md5_digest": "a6078f87bc758f1cd90220a3974f869d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4754,
"upload_time": "2018-11-05T16:39:30",
"upload_time_iso_8601": "2018-11-05T16:39:30.032765Z",
"url": "https://files.pythonhosted.org/packages/eb/e2/512a537cdb2dbd6fef19d4b87275d4ca14b5c1581abf4880cd6b2094aad4/yet-another-io-channels-library-0.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2018-11-05 16:39:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "aragaer",
"github_project": "channels",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "yet-another-io-channels-library"
}