-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved all the channel-related stuff from yet-another-runner package.
- Loading branch information
0 parents
commit 4479e3b
Showing
20 changed files
with
997 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# dotenv | ||
.env | ||
|
||
# virtualenv | ||
.venv | ||
venv/ | ||
ENV/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
sudo: false | ||
language: python | ||
python: | ||
- "3.4" | ||
- "3.5" | ||
- "3.6" | ||
|
||
install: "pip install -r requirements-travis.txt" | ||
script: "nosetests --with-coverage" | ||
after_success: codecov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). | ||
|
||
## Unreleased | ||
### Added | ||
- License | ||
- Readme | ||
- This changelog | ||
- Channel class | ||
- PipeChannel class | ||
- SocketChannel class | ||
- LineChannel class | ||
- TestChannel class | ||
- Poller class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Ilya Konovalov | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.PHONY: test | ||
|
||
test: | ||
nosetests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# Channels [](https://travis-ci.org/aragaer/channels) [](https://codecov.io/gh/aragaer/channels) [](https://bettercodehub.com/) [](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&[email protected]&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. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .channel import Channel, PipeChannel, SocketChannel, LineChannel, EndpointClosedException |
Oops, something went wrong.