From 91fe21ab60f8da7b28f2d5f6954f11a310ff9573 Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Wed, 4 Jul 2018 09:31:03 +0200 Subject: [PATCH] Fix scoping bug in asyncio wrapper Probably introduced by commit 2b27b49db77ff6fdad311e122da7c1305fccc095 --- pysnmp/carrier/asyncio/dgram/base.py | 10 +++++----- pysnmp/carrier/asyncio/dispatch.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pysnmp/carrier/asyncio/dgram/base.py b/pysnmp/carrier/asyncio/dgram/base.py index a819a9c9..e06e8ee5 100644 --- a/pysnmp/carrier/asyncio/dgram/base.py +++ b/pysnmp/carrier/asyncio/dgram/base.py @@ -42,6 +42,8 @@ try: except ImportError: import trollius as asyncio +IS_PYTHON_344_PLUS = platform.python_version_tuple() >= ('3', '4', '4') + class DgramAsyncioProtocol(asyncio.DatagramProtocol, AbstractAsyncioTransport): """Base Asyncio datagram Transport, to be used with AsyncioDispatcher""" @@ -78,20 +80,18 @@ class DgramAsyncioProtocol(asyncio.DatagramProtocol, AbstractAsyncioTransport): debug.logger & debug.flagIO and debug.logger('connection_lost: invoked') # AbstractAsyncioTransport API - - python344 = platform.python_version_tuple() >= ('3', '4', '4') - + def openClientMode(self, iface=None): try: c = self.loop.create_datagram_endpoint( lambda: self, local_addr=iface, family=self.sockFamily ) # Avoid deprecation warning for asyncio.async() - if python344: + if IS_PYTHON_344_PLUS: self._lport = asyncio.ensure_future(c) else: # pragma: no cover self._lport = asyncio.async(c) - + except Exception: raise error.CarrierError(';'.join(traceback.format_exception(*sys.exc_info()))) return self diff --git a/pysnmp/carrier/asyncio/dispatch.py b/pysnmp/carrier/asyncio/dispatch.py index 4fbafd1a..2ba4cf4d 100644 --- a/pysnmp/carrier/asyncio/dispatch.py +++ b/pysnmp/carrier/asyncio/dispatch.py @@ -41,7 +41,7 @@ try: except ImportError: import trollius as asyncio -python344 = platform.python_version_tuple() >= ('3', '4', '4') +IS_PYTHON_344_PLUS = platform.python_version_tuple() >= ('3', '4', '4') class AsyncioDispatcher(AbstractTransportDispatcher): """AsyncioDispatcher based on asyncio event loop""" @@ -72,7 +72,7 @@ class AsyncioDispatcher(AbstractTransportDispatcher): def registerTransport(self, tDomain, transport): if self.loopingcall is None and self.getTimerResolution() > 0: # Avoid deprecation warning for asyncio.async() - if python344: + if IS_PYTHON_344_PLUS: self.loopingcall = asyncio.ensure_future(self.handle_timeout()) else: # pragma: no cover self.loopingcall = asyncio.async(self.handle_timeout())