# Path: pysnmp/carrier/twisted/base.py
# class AbstractTwistedTransport:
#     """Base Twisted Transport, to be used with TwistedDispatcher"""
#     def __init__(self):
#         self._writeQ = []
# 
#     # AbstractTwistedTransport API
#     
#     def registerCbFun(self, cbFun):
#         self._cbFun = cbFun
# 
#     def unregisterCbFun(self):
#         self._cbFun = None
# 
#     def closeTransport(self):
#         self.unregisterCbFun()
# 
# Path: pysnmp/debug.py
# class Debug:
#     def __init__(self, *flags):
#     def __str__(self):
#     def __call__(self, msg):
#     def __and__(self, flag):
#     def __rand__(self, flag):
# def setLogger(l):
# def hexdump(octets):


import sys
from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
from pysnmp.carrier.twisted.base import AbstractTwistedTransport
from pysnmp.carrier import error
from pysnmp import debug
# Implements twisted-based generic DGRAM transport

class DgramTwistedTransport(DatagramProtocol, AbstractTwistedTransport):
    """Base Twisted datagram Transport, to be used with TwistedDispatcher"""

    # Twisted Datagram API
    
    def datagramReceived(self, datagram, transportAddress):
        if self._cbFun is None:
            raise error.CarrierError('Unable to call cbFun')
        else:
            # Callback fun is called through callLater() in attempt
            # to make Twisted timed calls work under high load.
            reactor.callLater(0, self._cbFun, self, transportAddress, datagram)

    def startProtocol(self):

# Path: pysnmp/carrier/twisted/base.py
# class AbstractTwistedTransport:
#     """Base Twisted Transport, to be used with TwistedDispatcher"""
#     def __init__(self):
#         self._writeQ = []
# 
#     # AbstractTwistedTransport API
#     
#     def registerCbFun(self, cbFun):
#         self._cbFun = cbFun
# 
#     def unregisterCbFun(self):
#         self._cbFun = None
# 
#     def closeTransport(self):
#         self.unregisterCbFun()
# 
# Path: pysnmp/debug.py
# class Debug:
#     def __init__(self, *flags):
#     def __str__(self):
#     def __call__(self, msg):
#     def __and__(self, flag):
#     def __rand__(self, flag):
# def setLogger(l):
# def hexdump(octets):


# Path: pysnmp/carrier/twisted/dgram/base.py
import sys
from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
from pysnmp.carrier.twisted.base import AbstractTwistedTransport
from pysnmp.carrier import error
from pysnmp import debug

# Implements twisted-based generic DGRAM transport

class DgramTwistedTransport(DatagramProtocol, AbstractTwistedTransport):
    """Base Twisted datagram Transport, to be used with TwistedDispatcher"""

    # Twisted Datagram API
    
    def datagramReceived(self, datagram, transportAddress):
        if self._cbFun is None:
            raise error.CarrierError('Unable to call cbFun')
        else:
            # Callback fun is called through callLater() in attempt
            # to make Twisted timed calls work under high load.
            reactor.callLater(0, self._cbFun, self, transportAddress, datagram)

    def startProtocol(self):

        debug.logger & debug.flagIO and debug.logger('startProtocol: invoked')