summaryrefslogtreecommitdiff
path: root/pysnmp/carrier/asyncio/dgram
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2016-04-02 23:43:14 +0200
committerIlya Etingof <etingof@gmail.com>2016-04-02 23:43:14 +0200
commit90bbf397ad3dd49db7f83d541afff51f17e63054 (patch)
tree9f77e3ee610241978873484f83702d9b3c056d9e /pysnmp/carrier/asyncio/dgram
parentfbc9c2679bd04ea3241b294e78e1b66fe993d952 (diff)
downloadpysnmp-git-90bbf397ad3dd49db7f83d541afff51f17e63054.tar.gz
pep8 reformatted
Diffstat (limited to 'pysnmp/carrier/asyncio/dgram')
-rw-r--r--pysnmp/carrier/asyncio/dgram/base.py8
-rw-r--r--pysnmp/carrier/asyncio/dgram/udp.py4
-rw-r--r--pysnmp/carrier/asyncio/dgram/udp6.py6
3 files changed, 15 insertions, 3 deletions
diff --git a/pysnmp/carrier/asyncio/dgram/base.py b/pysnmp/carrier/asyncio/dgram/base.py
index 5c3b78b6..3abcc3a3 100644
--- a/pysnmp/carrier/asyncio/dgram/base.py
+++ b/pysnmp/carrier/asyncio/dgram/base.py
@@ -35,6 +35,7 @@ import traceback
from pysnmp.carrier.asyncio.base import AbstractAsyncioTransport
from pysnmp.carrier import error
from pysnmp import debug
+
try:
import asyncio
except ImportError:
@@ -42,14 +43,16 @@ except ImportError:
loop = asyncio.get_event_loop()
+
class DgramAsyncioProtocol(asyncio.DatagramProtocol, AbstractAsyncioTransport):
"""Base Asyncio datagram Transport, to be used with AsyncioDispatcher"""
sockFamily = None
addressType = lambda x: x
transport = None
- def __init__(self, *args, **kwargs):
+ def __init__(self, sock=None, sockMap=None):
self._writeQ = []
+ self._lport = None
def datagram_received(self, datagram, transportAddress):
if self._cbFun is None:
@@ -95,7 +98,8 @@ class DgramAsyncioProtocol(asyncio.DatagramProtocol, AbstractAsyncioTransport):
return self
def closeTransport(self):
- self._lport.cancel()
+ if self._lport is not None:
+ self._lport.cancel()
if self.transport is not None:
self.transport.close()
AbstractAsyncioTransport.closeTransport(self)
diff --git a/pysnmp/carrier/asyncio/dgram/udp.py b/pysnmp/carrier/asyncio/dgram/udp.py
index aa73fb10..f80de36b 100644
--- a/pysnmp/carrier/asyncio/dgram/udp.py
+++ b/pysnmp/carrier/asyncio/dgram/udp.py
@@ -33,6 +33,7 @@
import socket
from pysnmp.carrier.base import AbstractTransportAddress
from pysnmp.carrier.asyncio.dgram.base import DgramAsyncioProtocol
+
try:
import asyncio
except ImportError:
@@ -42,11 +43,14 @@ loop = asyncio.get_event_loop()
domainName = snmpUDPDomain = (1, 3, 6, 1, 6, 1, 1)
+
class UdpTransportAddress(tuple, AbstractTransportAddress):
pass
+
class UdpAsyncioTransport(DgramAsyncioProtocol):
sockFamily = socket.AF_INET
addressType = UdpTransportAddress
+
UdpTransport = UdpAsyncioTransport
diff --git a/pysnmp/carrier/asyncio/dgram/udp6.py b/pysnmp/carrier/asyncio/dgram/udp6.py
index ad3c28dd..290c03bd 100644
--- a/pysnmp/carrier/asyncio/dgram/udp6.py
+++ b/pysnmp/carrier/asyncio/dgram/udp6.py
@@ -7,6 +7,7 @@
import socket
from pysnmp.carrier.base import AbstractTransportAddress
from pysnmp.carrier.asyncio.dgram.base import DgramAsyncioProtocol
+
try:
import asyncio
except ImportError:
@@ -16,9 +17,11 @@ loop = asyncio.get_event_loop()
domainName = snmpUDP6Domain = (1, 3, 6, 1, 2, 1, 100, 1, 2)
+
class Udp6TransportAddress(tuple, AbstractTransportAddress):
pass
+
class Udp6AsyncioTransport(DgramAsyncioProtocol):
sockFamily = socket.has_ipv6 and socket.AF_INET6 or None
addressType = Udp6TransportAddress
@@ -28,9 +31,10 @@ class Udp6AsyncioTransport(DgramAsyncioProtocol):
return self.addressType((transportAddress[0].split('%')[0],
transportAddress[1],
0, # flowinfo
- 0)) # scopeid
+ 0)) # scopeid
else:
return self.addressType((transportAddress[0],
transportAddress[1], 0, 0))
+
Udp6Transport = Udp6AsyncioTransport