summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2018-07-04 09:31:03 +0200
committerIlya Etingof <etingof@gmail.com>2018-07-04 09:31:03 +0200
commit91fe21ab60f8da7b28f2d5f6954f11a310ff9573 (patch)
tree8d36974186a3f96be83662ba84944de26bc877d5
parent3a8d4ec10b320fbb126164fc7567e97dd941d041 (diff)
downloadpysnmp-git-91fe21ab60f8da7b28f2d5f6954f11a310ff9573.tar.gz
Fix scoping bug in asyncio wrapper
Probably introduced by commit 2b27b49db77ff6fdad311e122da7c1305fccc095
-rw-r--r--pysnmp/carrier/asyncio/dgram/base.py10
-rw-r--r--pysnmp/carrier/asyncio/dispatch.py4
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())