# Path: pysnmp/carrier/asynsock/dispatch.py
# class AsynsockDispatcher(AbstractTransportDispatcher):
#     def __init__(self):
#         self.__sockMap = {} # use own map for MT safety
#         self.timeout = 0.5
#         AbstractTransportDispatcher.__init__(self)
# 
#     def getSocketMap(self): return self.__sockMap
#     def setSocketMap(self, sockMap=socket_map): self.__sockMap = sockMap
#     
#     def registerTransport(self, tDomain, t):
#         AbstractTransportDispatcher.registerTransport(self, tDomain, t)
#         t.registerSocket(self.__sockMap)
# 
#     def unregisterTransport(self, tDomain):
#         self.getTransport(tDomain).unregisterSocket(self.__sockMap)
#         AbstractTransportDispatcher.unregisterTransport(self, tDomain)
# 
#     def transportsAreWorking(self):
#         for transport in self.__sockMap.values():
#             if transport.writable():
#                 return 1
#         return 0
#     
#     def runDispatcher(self, timeout=0.0):
#         while self.jobsArePending() or self.transportsAreWorking():
#             poll(timeout and timeout or self.timeout, self.__sockMap)
#             self.handleTimerTick(time())
# 
# Path: pysnmp/carrier/asynsock/dgram/udp.py
# class UdpSocketTransport(DgramSocketTransport):
# 
# Path: pysnmp/carrier/asynsock/dgram/udp6.py
#     AF_INET6 = None
# class Udp6SocketTransport(DgramSocketTransport):
# 
# Path: pysnmp/carrier/asynsock/dgram/unix.py
#     AF_UNIX = None
# class UnixSocketTransport(DgramSocketTransport):
#     def openClientMode(self, iface=None):
#     def openServerMode(self, iface):
#     def closeTransport(self):


from pysnmp.carrier.asynsock.dispatch import AsynsockDispatcher
from pysnmp.carrier.asynsock.dgram import udp, udp6, unix
from pyasn1.codec.ber import encoder
from pysnmp.proto import api
pMod = api.protoModules[api.protoVersion1]
#pMod = api.protoModules[api.protoVersion2c]

# Build PDU
trapPDU =  pMod.TrapPDU()
pMod.apiTrapPDU.setDefaults(trapPDU)

# Traps have quite different semantics across proto versions
if pMod == api.protoModules[api.protoVersion1]:
    pMod.apiTrapPDU.setEnterprise(trapPDU, (1,3,6,1,1,2,3,4,1))
    pMod.apiTrapPDU.setGenericTrap(trapPDU, 'coldStart')

# Build message
trapMsg = pMod.Message()
pMod.apiMessage.setDefaults(trapMsg)
pMod.apiMessage.setCommunity(trapMsg, 'public')
pMod.apiMessage.setPDU(trapMsg, trapPDU)

transportDispatcher = AsynsockDispatcher()

# UDP/IPv4
transportDispatcher.registerTransport(
    udp.domainName, udp.UdpSocketTransport().openClientMode()
    )
transportDispatcher.sendMessage(
    encoder.encode(trapMsg), udp.domainName, ('localhost', 162)
    )

# UDP/IPv6
transportDispatcher.registerTransport(

# Path: pysnmp/carrier/asynsock/dispatch.py
# class AsynsockDispatcher(AbstractTransportDispatcher):
#     def __init__(self):
#         self.__sockMap = {} # use own map for MT safety
#         self.timeout = 0.5
#         AbstractTransportDispatcher.__init__(self)
# 
#     def getSocketMap(self): return self.__sockMap
#     def setSocketMap(self, sockMap=socket_map): self.__sockMap = sockMap
#     
#     def registerTransport(self, tDomain, t):
#         AbstractTransportDispatcher.registerTransport(self, tDomain, t)
#         t.registerSocket(self.__sockMap)
# 
#     def unregisterTransport(self, tDomain):
#         self.getTransport(tDomain).unregisterSocket(self.__sockMap)
#         AbstractTransportDispatcher.unregisterTransport(self, tDomain)
# 
#     def transportsAreWorking(self):
#         for transport in self.__sockMap.values():
#             if transport.writable():
#                 return 1
#         return 0
#     
#     def runDispatcher(self, timeout=0.0):
#         while self.jobsArePending() or self.transportsAreWorking():
#             poll(timeout and timeout or self.timeout, self.__sockMap)
#             self.handleTimerTick(time())
# 
# Path: pysnmp/carrier/asynsock/dgram/udp.py
# class UdpSocketTransport(DgramSocketTransport):
# 
# Path: pysnmp/carrier/asynsock/dgram/udp6.py
#     AF_INET6 = None
# class Udp6SocketTransport(DgramSocketTransport):
# 
# Path: pysnmp/carrier/asynsock/dgram/unix.py
#     AF_UNIX = None
# class UnixSocketTransport(DgramSocketTransport):
#     def openClientMode(self, iface=None):
#     def openServerMode(self, iface):
#     def closeTransport(self):


# Path: examples/v1arch/agent/ntforg.py
from pysnmp.carrier.asynsock.dispatch import AsynsockDispatcher
from pysnmp.carrier.asynsock.dgram import udp, udp6, unix
from pyasn1.codec.ber import encoder
from pysnmp.proto import api

pMod = api.protoModules[api.protoVersion1]
#pMod = api.protoModules[api.protoVersion2c]

# Build PDU
trapPDU =  pMod.TrapPDU()
pMod.apiTrapPDU.setDefaults(trapPDU)

# Traps have quite different semantics across proto versions
if pMod == api.protoModules[api.protoVersion1]:
    pMod.apiTrapPDU.setEnterprise(trapPDU, (1,3,6,1,1,2,3,4,1))
    pMod.apiTrapPDU.setGenericTrap(trapPDU, 'coldStart')

# Build message
trapMsg = pMod.Message()
pMod.apiMessage.setDefaults(trapMsg)
pMod.apiMessage.setCommunity(trapMsg, 'public')
pMod.apiMessage.setPDU(trapMsg, trapPDU)

transportDispatcher = AsynsockDispatcher()

# UDP/IPv4
transportDispatcher.registerTransport(
    udp.domainName, udp.UdpSocketTransport().openClientMode()
    )
transportDispatcher.sendMessage(
    encoder.encode(trapMsg), udp.domainName, ('localhost', 162)
    )

# UDP/IPv6
transportDispatcher.registerTransport(

    udp6.domainName, udp6.Udp6SocketTransport().openClientMode()