Skip to content

Commit

Permalink
Prepare 0.18.0
Browse files Browse the repository at this point in the history
Fix examples
Make connection_lost() async
  • Loading branch information
Neil Booth committed May 9, 2019
1 parent 6c27b6f commit 9414652
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 20 deletions.
2 changes: 1 addition & 1 deletion aiorpcx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .websocket import *


_version_str = '0.17.0'
_version_str = '0.18.0'
_version = tuple(int(part) for part in _version_str.split('.'))


Expand Down
2 changes: 1 addition & 1 deletion aiorpcx/rawsocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def process_messages(self):
pass
finally:
self._closed_event.set()
self.session.connection_lost()
await self.session.connection_lost()

async def receive_message(self):
return await self._framer.receive_message()
Expand Down
6 changes: 3 additions & 3 deletions aiorpcx/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def session_kind(self):
'''Either client or server.'''
return self.transport.kind

def connection_lost(self):
async def connection_lost(self):
pass

def data_received(self, data):
Expand Down Expand Up @@ -501,8 +501,8 @@ async def _send_concurrent(self, message, future, request_count):
if len(self._req_times) >= self.recalibrate_count:
self._recalc_concurrency()

def connection_lost(self):
super().connection_lost()
async def connection_lost(self):
await super().connection_lost()
# Cancel pending requests and message processing
self.connection.cancel_pending_requests()

Expand Down
2 changes: 1 addition & 1 deletion aiorpcx/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async def process_messages(self):
except websockets.ConnectionClosed:
pass
finally:
self.session.connection_lost()
await self.session.connection_lost()

# API exposed to session
async def write(self, framed_message):
Expand Down
29 changes: 28 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
ChangeLog
=========

.. note:: The aiorpcX API changes regularly and is still unstable
.. note:: The aiorpcX API changes regularly and is still unstable. I hope to finalize it
for a 1.0 release in the coming months.


Version 0.18.0 (09 May 2020)
----------------------------

* Add *websocket* support as client and server by using Aymeric Augustin's excellent
`websockets <https://github.com/aaugustin/websockets/>`_ package.

Unfortunately this required changing several APIs. The code now distinguishes the
previous TCP and SSL based-connections as *raw sockets* from the new websockets. The
old Connector and Server classes are gone. Use `connect_rs()` and `serve_rs()` to
connect a client and start a server for raw sockets; and `connect_ws()` and `serve_ws()`
to do the same for websockets.

SessionBase no longer inherits `asyncio.Protocol` as it is now transport-independent.
Sessions no longer take a framer in their constructor: websocket messages are already
framed, so instead a framer is passed to `connect_rs()` and `serve_rs()` if the default
`NewlineFramer` is not wanted.

A session is only instantiated when a connection handshake is completed, so
`connection_made()` is no longer a method. `connection_lost()` and `abort()` are now
coroutines; if overriding either be sure to call the base class implementation.

`is_send_buffer_full()` was removed.
* Updated and added new examples
* JSON RPC message handling was made more efficient by using futures instead of events
internally

Version 0.17.0 (22 Apr 2020)
----------------------------

Expand Down
6 changes: 3 additions & 3 deletions examples/client.py → examples/client_rs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import aiorpcx


async def connect(host, port):
async with aiorpcx.connect(host, port) as session:
async def main(host, port):
async with aiorpcx.connect_rs(host, port) as session:
# A good request with standard argument passing
result = await session.send_request('echo', ["Howdy"])
print(result)
Expand Down Expand Up @@ -37,4 +37,4 @@ async def connect(host, port):
print(f'batch result #{n}: {result}')


asyncio.get_event_loop().run_until_complete(connect('localhost', 8888))
asyncio.get_event_loop().run_until_complete(main('localhost', 8888))
File renamed without changes.
6 changes: 3 additions & 3 deletions examples/server.py → examples/server_rs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
print(f'connection from {self.remote_address()}')

def connection_lost(self):
super().connection_lost()
async def connection_lost(self):
await super().connection_lost()
print(f'{self.remote_address()} disconnected')

async def handle_request(self, request):
Expand All @@ -34,5 +34,5 @@ async def handle_request(self, request):


loop = asyncio.get_event_loop()
loop.run_until_complete(aiorpcx.serve(ServerSession, 'localhost', 8888))
loop.run_until_complete(aiorpcx.serve_rs(ServerSession, 'localhost', 8888))
loop.run_forever()
4 changes: 2 additions & 2 deletions examples/ws_server.py → examples/server_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
print(f'connection from {self.remote_address()}')

def connection_lost(self):
super().connection_lost()
async def connection_lost(self):
await super().connection_lost()
print(f'{self.remote_address()} disconnected')

async def handle_request(self, request):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def find_version(filename):
name='aiorpcX',
version=version,
python_requires='>=3.6',
install_requires=['attrs'],
install_requires=['websockets'],
packages=['aiorpcx'],
description='Generic async RPC implementation, including JSON-RPC',
author='Neil Booth',
Expand Down
8 changes: 4 additions & 4 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ async def current_server(self):
await sleep(0)
return self.sessions[0]

def connection_lost(self):
super().connection_lost()
async def connection_lost(self):
await super().connection_lost()
self.sessions.remove(self)

async def handle_request(self, request):
Expand Down Expand Up @@ -751,8 +751,8 @@ async def current_server(self):
await sleep(0.001)
return self._current_session

def connection_lost(self):
super().connection_lost()
async def connection_lost(self):
await super().connection_lost()
MessageServer._current_session = None

async def handle_message(self, message):
Expand Down

0 comments on commit 9414652

Please sign in to comment.