diff options
author | Chris Liechti <cliechti@gmx.net> | 2016-06-11 21:27:15 +0200 |
---|---|---|
committer | Chris Liechti <cliechti@gmx.net> | 2016-06-11 21:27:15 +0200 |
commit | 8643e502f13c8e5a2f5a776deb05bcb9b125828b (patch) | |
tree | 723581229ea94b6c580e2cdf6b98f816c8e9e081 | |
parent | 5d772fcd6969652fb8f2361f1fd5c1c5884e7a80 (diff) | |
download | pyserial-git-8643e502f13c8e5a2f5a776deb05bcb9b125828b.tar.gz |
fix: avoid Python 3 syntax in aio module
fixes #123 and fixes #128
-rw-r--r-- | CHANGES.rst | 1 | ||||
-rw-r--r-- | serial/aio.py | 25 |
2 files changed, 15 insertions, 11 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index fbb8ce2..ffc65d7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -636,6 +636,7 @@ Bugfixes: - [#122] fix bug in FramedPacket - [#127] The Serial class in the .NET/Mono (IronPython) backend does not implement the _reconfigure_port method +- [#123, #128] Avoid Python 3 syntax in aio module Bugfixes (posix): diff --git a/serial/aio.py b/serial/aio.py index 85a1bb8..9dd5215 100644 --- a/serial/aio.py +++ b/serial/aio.py @@ -362,10 +362,7 @@ def create_serial_connection(loop, protocol_factory, *args, **kwargs): @asyncio.coroutine -def open_serial_connection(*, - loop=None, - limit=asyncio.streams._DEFAULT_LIMIT, - **kwargs): +def open_serial_connection(**kwargs): """A wrapper for create_serial_connection() returning a (reader, writer) pair. @@ -379,16 +376,22 @@ def open_serial_connection(*, This function is a coroutine. """ - if loop is None: - loop = asyncio.get_event_loop() + # in order to avoid errors when pySerial is installed uner Python 2, + # avoid Pyhthon 3 syntax here. So do not use this function as a good + # example! + loop = kwargs.get('loop', asyncio.get_event_loop()) + limit = kwargs.get('limit', asyncio.streams._DEFAULT_LIMIT) reader = asyncio.StreamReader(limit=limit, loop=loop) protocol = asyncio.StreamReaderProtocol(reader, loop=loop) - transport, _ = yield from create_serial_connection( - loop=loop, - protocol_factory=lambda: protocol, - **kwargs) + # in Python 3 we would write "yield transport, _ from c()" + for transport, _ in create_serial_connection( + loop=loop, + protocol_factory=lambda: protocol, + **kwargs): + yield transport, _ writer = asyncio.StreamWriter(transport, protocol, reader, loop) - return reader, writer + # in Python 3 we would write "return reader, writer" + raise StopIteration(reader, writer) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |