summaryrefslogtreecommitdiff
path: root/pysnmp/carrier/asyncio/dgram/base.py
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2019-02-26 08:56:24 +0100
committerGitHub <noreply@github.com>2019-02-26 08:56:24 +0100
commit3f2f132a9fdf7a48ec6131d5498145dded3cfcad (patch)
tree63e6170b35f6b392bf2e3d3feb6996b886e4d36f /pysnmp/carrier/asyncio/dgram/base.py
parent2ad26f8bfef0e39b3789d9e6d4fcbf76820c9867 (diff)
downloadpysnmp-git-3f2f132a9fdf7a48ec6131d5498145dded3cfcad.tar.gz
PEP-8 long lines and dunders (#245)
This patch massively reformats the whole codebase mainly wrapping long lines and eliminating dundered private attributes.
Diffstat (limited to 'pysnmp/carrier/asyncio/dgram/base.py')
-rw-r--r--pysnmp/carrier/asyncio/dgram/base.py46
1 files changed, 36 insertions, 10 deletions
diff --git a/pysnmp/carrier/asyncio/dgram/base.py b/pysnmp/carrier/asyncio/dgram/base.py
index ae5ab3a7..be91a983 100644
--- a/pysnmp/carrier/asyncio/dgram/base.py
+++ b/pysnmp/carrier/asyncio/dgram/base.py
@@ -57,27 +57,38 @@ class DgramAsyncioProtocol(asyncio.DatagramProtocol, AbstractAsyncioTransport):
def __init__(self, sock=None, sockMap=None, loop=None):
self._writeQ = []
self._lport = None
+
if loop is None:
loop = asyncio.get_event_loop()
+
self.loop = loop
def datagram_received(self, datagram, transportAddress):
if self._cbFun is None:
raise error.CarrierError('Unable to call cbFun')
+
else:
self.loop.call_soon(self._cbFun, self, transportAddress, datagram)
def connection_made(self, transport):
self.transport = transport
+
debug.logger & debug.FLAG_IO and debug.logger('connection_made: invoked')
+
while self._writeQ:
outgoingMessage, transportAddress = self._writeQ.pop(0)
- debug.logger & debug.FLAG_IO and debug.logger('connection_made: transportAddress %r outgoingMessage %s' %
- (transportAddress, debug.hexdump(outgoingMessage)))
+
+ debug.logger & debug.FLAG_IO and debug.logger(
+ 'connection_made: transportAddress %r outgoingMessage %s' % (
+ transportAddress, debug.hexdump(outgoingMessage)))
+
try:
- self.transport.sendto(outgoingMessage, self.normalizeAddress(transportAddress))
+ self.transport.sendto(
+ outgoingMessage, self.normalizeAddress(transportAddress))
+
except Exception:
- raise error.CarrierError(';'.join(traceback.format_exception(*sys.exc_info())))
+ raise error.CarrierError(
+ ';'.join(traceback.format_exception(*sys.exc_info())))
def connection_lost(self, exc):
debug.logger & debug.FLAG_IO and debug.logger('connection_lost: invoked')
@@ -89,14 +100,17 @@ class DgramAsyncioProtocol(asyncio.DatagramProtocol, AbstractAsyncioTransport):
c = self.loop.create_datagram_endpoint(
lambda: self, local_addr=iface, family=self.SOCK_FAMILY
)
+
# Avoid deprecation warning for asyncio.async()
if IS_PYTHON_344_PLUS:
self._lport = asyncio.ensure_future(c)
+
else: # pragma: no cover
self._lport = getattr(asyncio, 'async')(c)
except Exception:
raise error.CarrierError(';'.join(traceback.format_exception(*sys.exc_info())))
+
return self
def openServerMode(self, iface):
@@ -104,36 +118,48 @@ class DgramAsyncioProtocol(asyncio.DatagramProtocol, AbstractAsyncioTransport):
c = self.loop.create_datagram_endpoint(
lambda: self, local_addr=iface, family=self.SOCK_FAMILY
)
+
# Avoid deprecation warning for asyncio.async()
if IS_PYTHON_344_PLUS:
self._lport = asyncio.ensure_future(c)
+
else: # pragma: no cover
self._lport = getattr(asyncio, 'async')(c)
+
except Exception:
raise error.CarrierError(';'.join(traceback.format_exception(*sys.exc_info())))
+
return self
def closeTransport(self):
if self._lport is not None:
self._lport.cancel()
+
if self.transport is not None:
self.transport.close()
+
AbstractAsyncioTransport.closeTransport(self)
def sendMessage(self, outgoingMessage, transportAddress):
- debug.logger & debug.FLAG_IO and debug.logger('sendMessage: %s transportAddress %r outgoingMessage %s' % (
- (self.transport is None and "queuing" or "sending"),
- transportAddress, debug.hexdump(outgoingMessage)
- ))
+ debug.logger & debug.FLAG_IO and debug.logger(
+ 'sendMessage: %s transportAddress %r outgoingMessage '
+ '%s' % (self.transport is None and "queuing" or "sending",
+ transportAddress, debug.hexdump(outgoingMessage)))
+
if self.transport is None:
self._writeQ.append((outgoingMessage, transportAddress))
+
else:
try:
- self.transport.sendto(outgoingMessage, self.normalizeAddress(transportAddress))
+ self.transport.sendto(
+ outgoingMessage, self.normalizeAddress(transportAddress))
+
except Exception:
- raise error.CarrierError(';'.join(traceback.format_exception(*sys.exc_info())))
+ raise error.CarrierError(
+ ';'.join(traceback.format_exception(*sys.exc_info())))
def normalizeAddress(self, transportAddress):
if not isinstance(transportAddress, self.ADDRESS_TYPE):
transportAddress = self.ADDRESS_TYPE(transportAddress)
+
return transportAddress