yet-another-io-channels-library


Nameyet-another-io-channels-library JSON
Version 0.2.4.post1 PyPI version JSON
download
home_pageNone
SummarySimple IO channels library
upload_time2024-06-02 19:04:54
maintainerNone
docs_urlNone
authorIlya Konovalov
requires_python<4.0,>=3.4
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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&currency_code=USD&bn=PP-DonationsBF:btn_donate_SM.gif:NonHosted)

Simple wrapper around file objects and sockets that provides uniform
interface to both.

Example:

```python
from channels import PipeChannel, SocketChannel

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:

```python
read(self)
```

Performs a non-blocking read and returns any bytes available. Raises
`EndpointClosedException` if the channel is closed.

```python
write(self, *data)
```

Writes chunks of bytes to the channel. Raises `EndpointClosedException`.

```python
close(self)
```

Closes the channel and frees up the resources.

```python
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

```python
from channels import 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

```python
from channels import 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`)

```python
from channels.testing import TestChannel

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

(in package `channels.poller`)

Poller is a wrapper for `select.poll` that also supports accepting and
keeping track of TCP/Unix clients.

```python
from channels.poller import Poller

Poller(*, buffering='bytes')
```

Creates a poller object. All accepted client channels inherit the
`buffering` parameter.

```python
register(self, channel)
```

Registers the channel for polling.

```python
add_server(self, sock)
```

Registers a server socket. Poller will accept incoming connections and
automatically register clients.

```python
unregister(self, channel)
```

Removes a registered channel. Silently does nothing if channel is not
registered.

```python
close_all(self)
```

Closes all registered channels and servers.

```python
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": null,
    "name": "yet-another-io-channels-library",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.4",
    "maintainer_email": null,
    "keywords": null,
    "author": "Ilya Konovalov",
    "author_email": "aragaer@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/96/95/5595d7f48d3a386cd13b79b88b487d23f57e28a652325d1afbdbab7e38a7/yet_another_io_channels_library-0.2.4.post1.tar.gz",
    "platform": null,
    "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&currency_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```python\nfrom channels import PipeChannel, SocketChannel\n\npipe_chan = PipeChannel(sys.stdin.fileno(), sys.stdout.fileno())\nsock_chan = SocketChannel(socket.create_connection(('127.0.0.1', 8080))\n```\n\n## Classes\n\n### Channel\n\nChannel is the base class for different channels. Every channel\nimplements the following methods:\n\n```python\nread(self)\n```\n\nPerforms a non-blocking read and returns any bytes available. Raises\n`EndpointClosedException` if the channel is closed.\n\n```python\nwrite(self, *data)\n```\n\nWrites chunks of bytes to the channel. Raises `EndpointClosedException`.\n\n```python\nclose(self)\n```\n\nCloses the channel and frees up the resources.\n\n```python\nget_fd(self)\n```\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```python\nfrom channels import PipeChannel\n\nPipeChannel(faucet=None, sink=None, *, buffering='bytes')\n```\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```python\nfrom channels import SocketChannel\n\nSocketChannel(sock, *, buffering='bytes')\n```\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```python\nfrom channels.testing import TestChannel\n\nTestChannel(*, buffering='bytes')\n```\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\n\n(in package `channels.poller`)\n\nPoller is a wrapper for `select.poll` that also supports accepting and\nkeeping track of TCP/Unix clients.\n\n```python\nfrom channels.poller import Poller\n\nPoller(*, buffering='bytes')\n```\n\nCreates a poller object. All accepted client channels inherit the\n`buffering` parameter.\n\n```python\nregister(self, channel)\n```\n\nRegisters the channel for polling.\n\n```python\nadd_server(self, sock)\n```\n\nRegisters a server socket. Poller will accept incoming connections and\nautomatically register clients.\n\n```python\nunregister(self, channel)\n```\n\nRemoves a registered channel. Silently does nothing if channel is not\nregistered.\n\n```python\nclose_all(self)\n```\n\nCloses all registered channels and servers.\n\n```python\npoll(self, timeout=None)\n```\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",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Simple IO channels library",
    "version": "0.2.4.post1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "91bdffe32d7bf0ba157878db255721332ad18e681f2567d6eda3ea6286dfda3f",
                "md5": "3483283e34995f68306e7860fd1e7b53",
                "sha256": "0f8a1e861108e39700e2827e83ef77b3dfef5804e5dc156d597c0ff86a12d265"
            },
            "downloads": -1,
            "filename": "yet_another_io_channels_library-0.2.4.post1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3483283e34995f68306e7860fd1e7b53",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.4",
            "size": 6287,
            "upload_time": "2024-06-02T19:04:52",
            "upload_time_iso_8601": "2024-06-02T19:04:52.957066Z",
            "url": "https://files.pythonhosted.org/packages/91/bd/ffe32d7bf0ba157878db255721332ad18e681f2567d6eda3ea6286dfda3f/yet_another_io_channels_library-0.2.4.post1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "96955595d7f48d3a386cd13b79b88b487d23f57e28a652325d1afbdbab7e38a7",
                "md5": "be9a938085b2c43dfa33f70130377578",
                "sha256": "e2f7c6b7dbbf4c4eeb2374f66183f1e16bc34d8d48306bb8d9d3080eb39dcb83"
            },
            "downloads": -1,
            "filename": "yet_another_io_channels_library-0.2.4.post1.tar.gz",
            "has_sig": false,
            "md5_digest": "be9a938085b2c43dfa33f70130377578",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.4",
            "size": 5059,
            "upload_time": "2024-06-02T19:04:54",
            "upload_time_iso_8601": "2024-06-02T19:04:54.139656Z",
            "url": "https://files.pythonhosted.org/packages/96/95/5595d7f48d3a386cd13b79b88b487d23f57e28a652325d1afbdbab7e38a7/yet_another_io_channels_library-0.2.4.post1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-02 19:04:54",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "yet-another-io-channels-library"
}
        
Elapsed time: 0.62409s