summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCameron <cam.parry@gmail.com>2018-04-22 02:43:45 +1000
committerIlya Etingof <etingof@gmail.com>2018-04-21 18:47:40 +0200
commit4938e8e383d207fa83cdbfd17186acaef97e6de4 (patch)
treeaa44c9f28ad91b588213465c9451b05ede7050e2
parent1021d56e1b1472c570d395d73d1c1c73bbf7761a (diff)
downloadpysnmp-git-4938e8e383d207fa83cdbfd17186acaef97e6de4.tar.gz
asyncio.async deprecated since 3.4.4 (#143)
* asyncio.async deprecated since 3.4.4
-rw-r--r--pysnmp/carrier/asyncio/dgram/base.py12
-rw-r--r--pysnmp/carrier/asyncio/dispatch.py10
2 files changed, 18 insertions, 4 deletions
diff --git a/pysnmp/carrier/asyncio/dgram/base.py b/pysnmp/carrier/asyncio/dgram/base.py
index 886f8801..a819a9c9 100644
--- a/pysnmp/carrier/asyncio/dgram/base.py
+++ b/pysnmp/carrier/asyncio/dgram/base.py
@@ -31,6 +31,7 @@
# THE POSSIBILITY OF SUCH DAMAGE.
#
import sys
+import platform
import traceback
from pysnmp.carrier.asyncio.base import AbstractAsyncioTransport
from pysnmp.carrier import error
@@ -77,13 +78,20 @@ 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
)
- self._lport = asyncio.async(c)
+ # Avoid deprecation warning for asyncio.async()
+ if python344:
+ 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 d45fdb6b..4fbafd1a 100644
--- a/pysnmp/carrier/asyncio/dispatch.py
+++ b/pysnmp/carrier/asyncio/dispatch.py
@@ -31,6 +31,7 @@
# THE POSSIBILITY OF SUCH DAMAGE.
#
import sys
+import platform
import traceback
from pysnmp.carrier.base import AbstractTransportDispatcher
from pysnmp.error import PySnmpError
@@ -40,6 +41,7 @@ try:
except ImportError:
import trollius as asyncio
+python344 = platform.python_version_tuple() >= ('3', '4', '4')
class AsyncioDispatcher(AbstractTransportDispatcher):
"""AsyncioDispatcher based on asyncio event loop"""
@@ -66,10 +68,14 @@ class AsyncioDispatcher(AbstractTransportDispatcher):
raise
except Exception:
raise PySnmpError(';'.join(traceback.format_exception(*sys.exc_info())))
-
+
def registerTransport(self, tDomain, transport):
if self.loopingcall is None and self.getTimerResolution() > 0:
- self.loopingcall = asyncio.async(self.handle_timeout())
+ # Avoid deprecation warning for asyncio.async()
+ if python344:
+ self.loopingcall = asyncio.ensure_future(self.handle_timeout())
+ else: # pragma: no cover
+ self.loopingcall = asyncio.async(self.handle_timeout())
AbstractTransportDispatcher.registerTransport(
self, tDomain, transport
)