Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/acatton/ohneio
Parse protocols, without any I/O
https://github.com/acatton/ohneio
asyncio framework parser python-3
Last synced: 3 months ago
JSON representation
Parse protocols, without any I/O
- Host: GitHub
- URL: https://github.com/acatton/ohneio
- Owner: acatton
- License: isc
- Created: 2016-08-19T21:04:56.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-20T23:51:49.000Z (about 7 years ago)
- Last Synced: 2024-09-29T17:03:22.096Z (3 months ago)
- Topics: asyncio, framework, parser, python-3
- Language: Python
- Homepage: http://ohneio.rtfd.io/
- Size: 38.1 KB
- Stars: 47
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README
- License: LICENSE
Awesome Lists containing this project
README
Ohne I/O
========.. image:: https://travis-ci.org/acatton/ohneio.svg?branch=master
:target: https://travis-ci.org/acatton/ohneioUtility library to write network protocol parser, `sans I/O `_.
`Ohne `_ I/O (without I/O in German) is a library using
`asyncio `_ corouting programming style.This library only supports Python 3.4+ (including Python 3.6 nightly)
``ohneio`` allows you to write protocol parsers the way you would write an asyncio protocol:
.. code-block:: python
>>> import base64
>>> import ohneio
>>>
>>> def wait_for(s):
... while True:
... data = yield from ohneio.peek()
... pos = data.find(s)
... if pos >= 0:
... return pos
... yield from ohneio.wait()
...
>>> def read_until(s):
... pos = yield from wait_for(s)
... data = yield from ohneio.read(pos)
... return data
...
>>> @ohneio.protocol
... def echo_base64(separator):
... while True:
... segment = yield from read_until(separator)
... yield from ohneio.read(len(separator))
... yield from ohneio.write(base64.b64encode(segment) + separator)
...
>>> connection = echo_base64(b'\r\n')
>>> connection.send(b'hello')
>>> connection.read()
b''
>>> connection.send(b'\r\nworld\r\n')
>>> connection.read()
b'aGVsbG8=\r\nd29ybGQ=\r\n'The example above also shows how ``ohneio`` allows you to combine primitives
into bigger parsing functions (like ``wait_for`` and ``read_until``).