diff options
Diffstat (limited to 'pysnmp/carrier')
-rw-r--r-- | pysnmp/carrier/asyncio/base.py | 2 | ||||
-rw-r--r-- | pysnmp/carrier/asyncio/dgram/base.py | 23 | ||||
-rw-r--r-- | pysnmp/carrier/asyncio/dgram/udp.py | 4 | ||||
-rw-r--r-- | pysnmp/carrier/asyncio/dgram/udp6.py | 4 | ||||
-rw-r--r-- | pysnmp/carrier/asyncore/base.py | 28 | ||||
-rw-r--r-- | pysnmp/carrier/asyncore/dgram/base.py | 56 | ||||
-rw-r--r-- | pysnmp/carrier/asyncore/dgram/udp.py | 6 | ||||
-rw-r--r-- | pysnmp/carrier/asyncore/dgram/udp6.py | 6 | ||||
-rw-r--r-- | pysnmp/carrier/asyncore/dgram/unix.py | 6 | ||||
-rw-r--r-- | pysnmp/carrier/asyncore/dispatch.py | 6 | ||||
-rw-r--r-- | pysnmp/carrier/base.py | 6 | ||||
-rw-r--r-- | pysnmp/carrier/sockfix.py | 2 | ||||
-rw-r--r-- | pysnmp/carrier/sockmsg.py | 5 | ||||
-rw-r--r-- | pysnmp/carrier/twisted/base.py | 2 | ||||
-rw-r--r-- | pysnmp/carrier/twisted/dgram/base.py | 8 | ||||
-rw-r--r-- | pysnmp/carrier/twisted/dgram/udp.py | 4 | ||||
-rw-r--r-- | pysnmp/carrier/twisted/dgram/unix.py | 7 | ||||
-rw-r--r-- | pysnmp/carrier/twisted/dispatch.py | 4 |
18 files changed, 94 insertions, 85 deletions
diff --git a/pysnmp/carrier/asyncio/base.py b/pysnmp/carrier/asyncio/base.py index ce1b644f..4ee21ead 100644 --- a/pysnmp/carrier/asyncio/base.py +++ b/pysnmp/carrier/asyncio/base.py @@ -35,5 +35,5 @@ from pysnmp.carrier.base import AbstractTransport class AbstractAsyncioTransport(AbstractTransport): - protoTransportDispatcher = AsyncioDispatcher + PROTO_TRANSPORT_DISPATCHER = AsyncioDispatcher """Base Asyncio Transport, to be used with AsyncioDispatcher""" diff --git a/pysnmp/carrier/asyncio/dgram/base.py b/pysnmp/carrier/asyncio/dgram/base.py index a845fa1e..7cc0b589 100644 --- a/pysnmp/carrier/asyncio/dgram/base.py +++ b/pysnmp/carrier/asyncio/dgram/base.py @@ -47,8 +47,9 @@ 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""" - sockFamily = None - addressType = lambda x: x + SOCK_FAMILY = None + ADDRESS_TYPE = lambda x: x + transport = None def __init__(self, sock=None, sockMap=None, loop=None): @@ -66,25 +67,25 @@ class DgramAsyncioProtocol(asyncio.DatagramProtocol, AbstractAsyncioTransport): def connection_made(self, transport): self.transport = transport - debug.logger & debug.flagIO and debug.logger('connection_made: invoked') + debug.logger & debug.FLAG_IO and debug.logger('connection_made: invoked') while self._writeQ: outgoingMessage, transportAddress = self._writeQ.pop(0) - debug.logger & debug.flagIO 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)) except Exception: raise error.CarrierError(';'.join(traceback.format_exception(*sys.exc_info()))) def connection_lost(self, exc): - debug.logger & debug.flagIO and debug.logger('connection_lost: invoked') + debug.logger & debug.FLAG_IO and debug.logger('connection_lost: invoked') # AbstractAsyncioTransport API def openClientMode(self, iface=None): try: c = self.loop.create_datagram_endpoint( - lambda: self, local_addr=iface, family=self.sockFamily + lambda: self, local_addr=iface, family=self.SOCK_FAMILY ) # Avoid deprecation warning for asyncio.async() if IS_PYTHON_344_PLUS: @@ -99,7 +100,7 @@ class DgramAsyncioProtocol(asyncio.DatagramProtocol, AbstractAsyncioTransport): def openServerMode(self, iface): try: c = self.loop.create_datagram_endpoint( - lambda: self, local_addr=iface, family=self.sockFamily + lambda: self, local_addr=iface, family=self.SOCK_FAMILY ) # Avoid deprecation warning for asyncio.async() if IS_PYTHON_344_PLUS: @@ -118,7 +119,7 @@ class DgramAsyncioProtocol(asyncio.DatagramProtocol, AbstractAsyncioTransport): AbstractAsyncioTransport.closeTransport(self) def sendMessage(self, outgoingMessage, transportAddress): - debug.logger & debug.flagIO and debug.logger('sendMessage: %s transportAddress %r outgoingMessage %s' % ( + 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) )) @@ -131,6 +132,6 @@ class DgramAsyncioProtocol(asyncio.DatagramProtocol, AbstractAsyncioTransport): raise error.CarrierError(';'.join(traceback.format_exception(*sys.exc_info()))) def normalizeAddress(self, transportAddress): - if not isinstance(transportAddress, self.addressType): - transportAddress = self.addressType(transportAddress) + if not isinstance(transportAddress, self.ADDRESS_TYPE): + transportAddress = self.ADDRESS_TYPE(transportAddress) return transportAddress diff --git a/pysnmp/carrier/asyncio/dgram/udp.py b/pysnmp/carrier/asyncio/dgram/udp.py index 41ada723..b13d4202 100644 --- a/pysnmp/carrier/asyncio/dgram/udp.py +++ b/pysnmp/carrier/asyncio/dgram/udp.py @@ -42,8 +42,8 @@ class UdpTransportAddress(tuple, AbstractTransportAddress): class UdpAsyncioTransport(DgramAsyncioProtocol): - sockFamily = socket.AF_INET - addressType = UdpTransportAddress + SOCK_FAMILY = socket.AF_INET + ADDRESS_TYPE = UdpTransportAddress UdpTransport = UdpAsyncioTransport diff --git a/pysnmp/carrier/asyncio/dgram/udp6.py b/pysnmp/carrier/asyncio/dgram/udp6.py index bc03b447..f3708852 100644 --- a/pysnmp/carrier/asyncio/dgram/udp6.py +++ b/pysnmp/carrier/asyncio/dgram/udp6.py @@ -17,8 +17,8 @@ class Udp6TransportAddress(tuple, AbstractTransportAddress): class Udp6AsyncioTransport(DgramAsyncioProtocol): - sockFamily = socket.has_ipv6 and socket.AF_INET6 or None - addressType = Udp6TransportAddress + SOCK_FAMILY = socket.has_ipv6 and socket.AF_INET6 or None + ADDRESS_TYPE = Udp6TransportAddress def normalizeAddress(self, transportAddress): if '%' in transportAddress[0]: # strip zone ID diff --git a/pysnmp/carrier/asyncore/base.py b/pysnmp/carrier/asyncore/base.py index e4824f32..035dcbab 100644 --- a/pysnmp/carrier/asyncore/base.py +++ b/pysnmp/carrier/asyncore/base.py @@ -14,37 +14,37 @@ from pysnmp import debug class AbstractSocketTransport(asyncore.dispatcher, AbstractTransport): - protoTransportDispatcher = AsyncoreDispatcher - sockFamily = sockType = None - retryCount = 0 - retryInterval = 0 - bufferSize = 131070 + PROTO_TRANSPORT_DISPATCHER = AsyncoreDispatcher + SOCK_FAMILY = SOCK_TYPE = None + RETRY_COUNT = 0 + RETRY_INTERVAL = 0 + BUFFER_SIZE = 131070 # noinspection PyUnusedLocal def __init__(self, sock=None, sockMap=None): asyncore.dispatcher.__init__(self) if sock is None: - if self.sockFamily is None: + if self.SOCK_FAMILY is None: raise error.CarrierError( 'Address family %s not supported' % self.__class__.__name__ ) - if self.sockType is None: + if self.SOCK_TYPE is None: raise error.CarrierError( 'Socket type %s not supported' % self.__class__.__name__ ) try: - sock = socket.socket(self.sockFamily, self.sockType) + sock = socket.socket(self.SOCK_FAMILY, self.SOCK_TYPE) except socket.error as exc: raise error.CarrierError('socket() failed: %s' % exc) try: for b in socket.SO_RCVBUF, socket.SO_SNDBUF: bsize = sock.getsockopt(socket.SOL_SOCKET, b) - if bsize < self.bufferSize: - sock.setsockopt(socket.SOL_SOCKET, b, self.bufferSize) - debug.logger & debug.flagIO and debug.logger('%s: socket %d buffer size increased from %d to %d for buffer %d' % (self.__class__.__name__, sock.fileno(), bsize, self.bufferSize, b)) + if bsize < self.BUFFER_SIZE: + sock.setsockopt(socket.SOL_SOCKET, b, self.BUFFER_SIZE) + debug.logger & debug.FLAG_IO and debug.logger('%s: socket %d buffer size increased from %d to %d for buffer %d' % (self.__class__.__name__, sock.fileno(), bsize, self.BUFFER_SIZE, b)) except Exception as exc: - debug.logger & debug.flagIO and debug.logger('%s: socket buffer size option mangling failure for buffer: %s' % (self.__class__.__name__, exc)) + debug.logger & debug.FLAG_IO and debug.logger('%s: socket buffer size option mangling failure for buffer: %s' % (self.__class__.__name__, exc)) # The socket map is managed by the AsyncoreDispatcher on # which this transport is registered. Here we just prepare @@ -82,8 +82,10 @@ class AbstractSocketTransport(asyncore.dispatcher, AbstractTransport): self.close() # asyncore API + def handle_close(self): raise error.CarrierError('Transport unexpectedly closed') def handle_error(self): - raise + exc = sys.exc_info()[1] + raise exc diff --git a/pysnmp/carrier/asyncore/dgram/base.py b/pysnmp/carrier/asyncore/dgram/base.py index e9ffc9b0..f103e781 100644 --- a/pysnmp/carrier/asyncore/dgram/base.py +++ b/pysnmp/carrier/asyncore/dgram/base.py @@ -12,23 +12,23 @@ from pysnmp.carrier import sockfix, sockmsg, error from pysnmp import debug # Ignore these socket errors -sockErrors = {errno.ESHUTDOWN: True, - errno.ENOTCONN: True, - errno.ECONNRESET: False, - errno.ECONNREFUSED: False, - errno.EAGAIN: False, - errno.EWOULDBLOCK: False} +SOCK_ERRORS = {errno.ESHUTDOWN: True, + errno.ENOTCONN: True, + errno.ECONNRESET: False, + errno.ECONNREFUSED: False, + errno.EAGAIN: False, + errno.EWOULDBLOCK: False} if hasattr(errno, 'EBADFD'): # bad FD may happen upon FD closure on n-1 select() event - sockErrors[errno.EBADFD] = True + SOCK_ERRORS[errno.EBADFD] = True class DgramSocketTransport(AbstractSocketTransport): - sockType = socket.SOCK_DGRAM - retryCount = 3 - retryInterval = 1 - addressType = lambda x: x + SOCK_TYPE = socket.SOCK_DGRAM + RETRY_COUNT = 3 + RETRY_INTERVAL = 1 + ADDRESS_TYPE = lambda x: x def __init__(self, sock=None, sockMap=None): self.__outQueue = [] @@ -36,7 +36,7 @@ class DgramSocketTransport(AbstractSocketTransport): def __recvfrom(s, sz): d, a = s.recvfrom(sz) - return d, self.addressType(a) + return d, self.ADDRESS_TYPE(a) self._recvfrom = __recvfrom AbstractSocketTransport.__init__(self, sock, sockMap) @@ -64,7 +64,7 @@ class DgramSocketTransport(AbstractSocketTransport): ) except socket.error as exc: raise error.CarrierError('setsockopt() for SO_BROADCAST failed: %s' % exc) - debug.logger & debug.flagIO and debug.logger('enableBroadcast: %s option SO_BROADCAST on socket %s' % (flag and "enabled" or "disabled", self.socket.fileno())) + debug.logger & debug.FLAG_IO and debug.logger('enableBroadcast: %s option SO_BROADCAST on socket %s' % (flag and "enabled" or "disabled", self.socket.fileno())) return self def enablePktInfo(self, flag=1): @@ -82,10 +82,10 @@ class DgramSocketTransport(AbstractSocketTransport): except socket.error as exc: raise error.CarrierError('setsockopt() for %s failed: %s' % (self.socket.family == socket.AF_INET6 and "IPV6_RECVPKTINFO" or "IP_PKTINFO", exc)) - self._sendto = sockmsg.getSendTo(self.addressType) - self._recvfrom = sockmsg.getRecvFrom(self.addressType) + self._sendto = sockmsg.getSendTo(self.ADDRESS_TYPE) + self._recvfrom = sockmsg.getRecvFrom(self.ADDRESS_TYPE) - debug.logger & debug.flagIO and debug.logger('enablePktInfo: %s option %s on socket %s' % (self.socket.family == socket.AF_INET6 and "IPV6_RECVPKTINFO" or "IP_PKTINFO", flag and "enabled" or "disabled", self.socket.fileno())) + debug.logger & debug.FLAG_IO and debug.logger('enablePktInfo: %s option %s on socket %s' % (self.socket.family == socket.AF_INET6 and "IPV6_RECVPKTINFO" or "IP_PKTINFO", flag and "enabled" or "disabled", self.socket.fileno())) return self def enableTransparent(self, flag=1): @@ -105,18 +105,18 @@ class DgramSocketTransport(AbstractSocketTransport): except OSError: raise error.CarrierError('IP_TRANSPARENT socket option requires superuser priveleges') - debug.logger & debug.flagIO and debug.logger('enableTransparent: %s option IP_TRANSPARENT on socket %s' % (flag and "enabled" or "disabled", self.socket.fileno())) + debug.logger & debug.FLAG_IO and debug.logger('enableTransparent: %s option IP_TRANSPARENT on socket %s' % (flag and "enabled" or "disabled", self.socket.fileno())) return self def sendMessage(self, outgoingMessage, transportAddress): self.__outQueue.append( (outgoingMessage, self.normalizeAddress(transportAddress)) ) - debug.logger & debug.flagIO and debug.logger('sendMessage: outgoingMessage queued (%d octets) %s' % (len(outgoingMessage), debug.hexdump(outgoingMessage))) + debug.logger & debug.FLAG_IO and debug.logger('sendMessage: outgoingMessage queued (%d octets) %s' % (len(outgoingMessage), debug.hexdump(outgoingMessage))) def normalizeAddress(self, transportAddress): - if not isinstance(transportAddress, self.addressType): - transportAddress = self.addressType(transportAddress) + if not isinstance(transportAddress, self.ADDRESS_TYPE): + transportAddress = self.ADDRESS_TYPE(transportAddress) if not transportAddress.getLocalAddress(): transportAddress.setLocalAddress(self.getLocalAddress()) @@ -140,17 +140,17 @@ class DgramSocketTransport(AbstractSocketTransport): def handle_write(self): outgoingMessage, transportAddress = self.__outQueue.pop(0) - debug.logger & debug.flagIO and debug.logger('handle_write: transportAddress %r -> %r outgoingMessage (%d octets) %s' % (transportAddress.getLocalAddress(), transportAddress, len(outgoingMessage), debug.hexdump(outgoingMessage))) + debug.logger & debug.FLAG_IO and debug.logger('handle_write: transportAddress %r -> %r outgoingMessage (%d octets) %s' % (transportAddress.getLocalAddress(), transportAddress, len(outgoingMessage), debug.hexdump(outgoingMessage))) if not transportAddress: - debug.logger & debug.flagIO and debug.logger('handle_write: missing dst address, loosing outgoing msg') + debug.logger & debug.FLAG_IO and debug.logger('handle_write: missing dst address, loosing outgoing msg') return try: self._sendto( self.socket, outgoingMessage, transportAddress ) except socket.error as exc: - if exc.args[0] in sockErrors: - debug.logger & debug.flagIO and debug.logger('handle_write: ignoring socket error %s' % exc) + if exc.args[0] in SOCK_ERRORS: + debug.logger & debug.FLAG_IO and debug.logger('handle_write: ignoring socket error %s' % exc) else: raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, exc)) @@ -161,7 +161,7 @@ class DgramSocketTransport(AbstractSocketTransport): try: incomingMessage, transportAddress = self._recvfrom(self.socket, 65535) transportAddress = self.normalizeAddress(transportAddress) - debug.logger & debug.flagIO and debug.logger( + debug.logger & debug.FLAG_IO and debug.logger( 'handle_read: transportAddress %r -> %r incomingMessage (%d octets) %s' % (transportAddress, transportAddress.getLocalAddress(), len(incomingMessage), debug.hexdump(incomingMessage))) if not incomingMessage: self.handle_close() @@ -170,9 +170,9 @@ class DgramSocketTransport(AbstractSocketTransport): self._cbFun(self, transportAddress, incomingMessage) return except socket.error as exc: - if exc.args[0] in sockErrors: - debug.logger & debug.flagIO and debug.logger('handle_read: known socket error %s' % exc) - sockErrors[exc.args[0]] and self.handle_close() + if exc.args[0] in SOCK_ERRORS: + debug.logger & debug.FLAG_IO and debug.logger('handle_read: known socket error %s' % exc) + SOCK_ERRORS[exc.args[0]] and self.handle_close() return else: raise error.CarrierError('recvfrom() failed: %s' % exc) diff --git a/pysnmp/carrier/asyncore/dgram/udp.py b/pysnmp/carrier/asyncore/dgram/udp.py index 08ae5ceb..60bc32a9 100644 --- a/pysnmp/carrier/asyncore/dgram/udp.py +++ b/pysnmp/carrier/asyncore/dgram/udp.py @@ -8,7 +8,7 @@ from socket import AF_INET from pysnmp.carrier.base import AbstractTransportAddress from pysnmp.carrier.asyncore.dgram.base import DgramSocketTransport -domainName = snmpUDPDomain = (1, 3, 6, 1, 6, 1, 1) +DOMAIN_NAME = SNMP_UDP_DOMAIN = (1, 3, 6, 1, 6, 1, 1) class UdpTransportAddress(tuple, AbstractTransportAddress): @@ -16,8 +16,8 @@ class UdpTransportAddress(tuple, AbstractTransportAddress): class UdpSocketTransport(DgramSocketTransport): - sockFamily = AF_INET - addressType = UdpTransportAddress + SOCK_FAMILY = AF_INET + ADDRESS_TYPE = UdpTransportAddress UdpTransport = UdpSocketTransport diff --git a/pysnmp/carrier/asyncore/dgram/udp6.py b/pysnmp/carrier/asyncore/dgram/udp6.py index 900ef3c7..ee99674d 100644 --- a/pysnmp/carrier/asyncore/dgram/udp6.py +++ b/pysnmp/carrier/asyncore/dgram/udp6.py @@ -9,7 +9,7 @@ from pysnmp.carrier.base import AbstractTransportAddress from pysnmp.carrier.asyncore.dgram.base import DgramSocketTransport import socket -domainName = snmpUDP6Domain = (1, 3, 6, 1, 2, 1, 100, 1, 2) +DOMAIN_NAME = SNMP_UDP6_DOMAIN = (1, 3, 6, 1, 2, 1, 100, 1, 2) class Udp6TransportAddress(tuple, AbstractTransportAddress): @@ -17,8 +17,8 @@ class Udp6TransportAddress(tuple, AbstractTransportAddress): class Udp6SocketTransport(DgramSocketTransport): - sockFamily = socket.has_ipv6 and socket.AF_INET6 or None - addressType = Udp6TransportAddress + SOCK_FAMILY = socket.has_ipv6 and socket.AF_INET6 or None + ADDRESS_TYPE = Udp6TransportAddress def normalizeAddress(self, transportAddress): if '%' in transportAddress[0]: # strip zone ID diff --git a/pysnmp/carrier/asyncore/dgram/unix.py b/pysnmp/carrier/asyncore/dgram/unix.py index 15f68b2b..486c84f8 100644 --- a/pysnmp/carrier/asyncore/dgram/unix.py +++ b/pysnmp/carrier/asyncore/dgram/unix.py @@ -14,7 +14,7 @@ except ImportError: from pysnmp.carrier.base import AbstractTransportAddress from pysnmp.carrier.asyncore.dgram.base import DgramSocketTransport -domainName = snmpLocalDomain = (1, 3, 6, 1, 2, 1, 100, 1, 13) +DOMAIN_NAME = SNMP_LOCAL_DOMAIN = (1, 3, 6, 1, 2, 1, 100, 1, 13) random.seed() @@ -24,8 +24,8 @@ class UnixTransportAddress(str, AbstractTransportAddress): class UnixSocketTransport(DgramSocketTransport): - sockFamily = AF_UNIX - addressType = UnixTransportAddress + SOCK_FAMILY = AF_UNIX + ADDRESS_TYPE = UnixTransportAddress _iface = '' def openClientMode(self, iface=None): diff --git a/pysnmp/carrier/asyncore/dispatch.py b/pysnmp/carrier/asyncore/dispatch.py index 221c596c..3517bdff 100644 --- a/pysnmp/carrier/asyncore/dispatch.py +++ b/pysnmp/carrier/asyncore/dispatch.py @@ -35,8 +35,7 @@ class AsyncoreDispatcher(AbstractTransportDispatcher): def transportsAreWorking(self): for transport in self.__sockMap.values(): if transport.writable(): - return 1 - return 0 + return True def runDispatcher(self, timeout=0.0): while self.jobsArePending() or self.transportsAreWorking(): @@ -45,6 +44,7 @@ class AsyncoreDispatcher(AbstractTransportDispatcher): use_poll=True, map=self.__sockMap, count=1) except KeyboardInterrupt: raise - except: + + except Exception: raise PySnmpError('poll error: %s' % ';'.join(format_exception(*exc_info()))) self.handleTimerTick(time()) diff --git a/pysnmp/carrier/base.py b/pysnmp/carrier/base.py index 017a1520..12dfc86b 100644 --- a/pysnmp/carrier/base.py +++ b/pysnmp/carrier/base.py @@ -211,13 +211,13 @@ class AbstractTransportAddress(object): class AbstractTransport(object): - protoTransportDispatcher = None - addressType = AbstractTransportAddress + PROTO_TRANSPORT_DISPATCHER = None + ADDRESS_TYPE = AbstractTransportAddress _cbFun = None @classmethod def isCompatibleWithDispatcher(cls, transportDispatcher): - return isinstance(transportDispatcher, cls.protoTransportDispatcher) + return isinstance(transportDispatcher, cls.PROTO_TRANSPORT_DISPATCHER) def registerCbFun(self, cbFun): if self._cbFun: diff --git a/pysnmp/carrier/sockfix.py b/pysnmp/carrier/sockfix.py index fab6d1aa..edfc1631 100644 --- a/pysnmp/carrier/sockfix.py +++ b/pysnmp/carrier/sockfix.py @@ -22,7 +22,7 @@ for symbol, value in SYMBOLS.items(): if not hasattr(socket, symbol): setattr(socket, symbol, value) - debug.logger & debug.flagIO and debug.logger( + debug.logger & debug.FLAG_IO and debug.logger( 'WARNING: the socket module on this platform misses option %s. ' 'Assuming its value is %d.' % (symbol, value) ) diff --git a/pysnmp/carrier/sockmsg.py b/pysnmp/carrier/sockmsg.py index 4ff55a91..deab4b6d 100644 --- a/pysnmp/carrier/sockmsg.py +++ b/pysnmp/carrier/sockmsg.py @@ -27,6 +27,7 @@ if sys.version_info[:2] < (3, 3): def getSendTo(addressType): raise error.CarrierError('sendmsg()/recvmsg() interface is not supported by this OS and/or Python version') + else: import ctypes import ipaddress @@ -91,7 +92,7 @@ else: _to = (str(addr), s.getsockname()[1]) break - debug.logger & debug.flagIO and debug.logger( + debug.logger & debug.FLAG_IO and debug.logger( 'recvfrom: received %d octets from %s to %s; ' 'iov blob %r' % (len(data), _from, _to, ancdata)) @@ -120,7 +121,7 @@ else: _f.ipi6_addr = in6_addr.from_buffer_copy(addr.packed) ancdata = [(socket.SOL_IPV6, socket.IPV6_PKTINFO, memoryview(_f).tobytes())] - debug.logger & debug.flagIO and debug.logger( + debug.logger & debug.FLAG_IO and debug.logger( 'sendto: sending %d octets to %s; address %r; ' 'iov blob %r' % (len(_data), _to, addr, ancdata)) diff --git a/pysnmp/carrier/twisted/base.py b/pysnmp/carrier/twisted/base.py index d8b75bc7..91883d7d 100644 --- a/pysnmp/carrier/twisted/base.py +++ b/pysnmp/carrier/twisted/base.py @@ -17,7 +17,7 @@ from pysnmp.carrier.base import AbstractTransport class AbstractTwistedTransport(AbstractTransport): - protoTransportDispatcher = TwistedDispatcher + PROTO_TRANSPORT_DISPATCHER = TwistedDispatcher def __init__(self, sock=None, sockMap=None): self._writeQ = [] diff --git a/pysnmp/carrier/twisted/dgram/base.py b/pysnmp/carrier/twisted/dgram/base.py index 4386b702..42eb7c04 100644 --- a/pysnmp/carrier/twisted/dgram/base.py +++ b/pysnmp/carrier/twisted/dgram/base.py @@ -26,20 +26,20 @@ class DgramTwistedTransport(DatagramProtocol, AbstractTwistedTransport): reactor.callLater(0, self._cbFun, self, transportAddress, datagram) def startProtocol(self): - debug.logger & debug.flagIO and debug.logger('startProtocol: invoked') + debug.logger & debug.FLAG_IO and debug.logger('startProtocol: invoked') while self._writeQ: outgoingMessage, transportAddress = self._writeQ.pop(0) - debug.logger & debug.flagIO and debug.logger('startProtocol: transportAddress %r outgoingMessage %s' % (transportAddress, debug.hexdump(outgoingMessage))) + debug.logger & debug.FLAG_IO and debug.logger('startProtocol: transportAddress %r outgoingMessage %s' % (transportAddress, debug.hexdump(outgoingMessage))) try: self.transport.write(outgoingMessage, transportAddress) except Exception as exc: raise error.CarrierError('Twisted exception: %s' % exc) def stopProtocol(self): - debug.logger & debug.flagIO and debug.logger('stopProtocol: invoked') + debug.logger & debug.FLAG_IO and debug.logger('stopProtocol: invoked') def sendMessage(self, outgoingMessage, transportAddress): - debug.logger & debug.flagIO and debug.logger('startProtocol: %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('startProtocol: %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: diff --git a/pysnmp/carrier/twisted/dgram/udp.py b/pysnmp/carrier/twisted/dgram/udp.py index bdb93cdd..eb47bb24 100644 --- a/pysnmp/carrier/twisted/dgram/udp.py +++ b/pysnmp/carrier/twisted/dgram/udp.py @@ -10,7 +10,7 @@ from pysnmp.carrier.base import AbstractTransportAddress from pysnmp.carrier.twisted.dgram.base import DgramTwistedTransport from pysnmp.carrier import error -domainName = snmpUDPDomain = (1, 3, 6, 1, 6, 1, 1) +DOMAIN_NAME = SNMP_UDP_DOMAIN = (1, 3, 6, 1, 6, 1, 1) class UdpTransportAddress(tuple, AbstractTransportAddress): @@ -18,7 +18,7 @@ class UdpTransportAddress(tuple, AbstractTransportAddress): class UdpTwistedTransport(DgramTwistedTransport): - addressType = UdpTransportAddress + ADDRESS_TYPE = UdpTransportAddress _lport = None # AbstractTwistedTransport API diff --git a/pysnmp/carrier/twisted/dgram/unix.py b/pysnmp/carrier/twisted/dgram/unix.py index fe9c459b..24fdc5c7 100644 --- a/pysnmp/carrier/twisted/dgram/unix.py +++ b/pysnmp/carrier/twisted/dgram/unix.py @@ -10,13 +10,15 @@ from pysnmp.carrier.base import AbstractTransportAddress from pysnmp.carrier.twisted.dgram.base import DgramTwistedTransport from pysnmp.carrier import error -domainName = snmpLocalDomain = (1, 3, 6, 1, 2, 1, 100, 1, 13) +DOMAIN_NAME = SNMP_LOCAL_DOMAIN = (1, 3, 6, 1, 2, 1, 100, 1, 13) + class UnixTransportAddress(str, AbstractTransportAddress): pass + class UnixTwistedTransport(DgramTwistedTransport): - addressType = UnixTransportAddress + ADDRESS_TYPE = UnixTransportAddress _lport = None # AbstractTwistedTransport API @@ -43,4 +45,5 @@ class UnixTwistedTransport(DgramTwistedTransport): d.addCallback(lambda x: None) DgramTwistedTransport.closeTransport(self) + UnixTransport = UnixTwistedTransport diff --git a/pysnmp/carrier/twisted/dispatch.py b/pysnmp/carrier/twisted/dispatch.py index def16f6f..cacc20b4 100644 --- a/pysnmp/carrier/twisted/dispatch.py +++ b/pysnmp/carrier/twisted/dispatch.py @@ -34,9 +34,11 @@ class TwistedDispatcher(AbstractTransportDispatcher): if not reactor.running: try: reactor.run() + except KeyboardInterrupt: raise - except: + + except Exception: raise PySnmpError('reactor error: %s' % ';'.join(traceback.format_exception(*sys.exc_info()))) # jobstarted/jobfinished might be okay as-is |