# Path: pysmi/writer/base.py
# class AbstractWriter(object):
#     def setOptions(self, **kwargs):
#         for k in kwargs:
#             setattr(self, k, kwargs[k])
#         return self
# 
#     def putData(self, mibname, data, comments=(), dryRun=False):
#         raise NotImplementedError()
# 
#     def getData(self, filename):
#         raise NotImplementedError()
# 
# Path: pysmi/debug.py
# class Printer(object):
#     class NullHandler(logging.Handler):
# class Debug(object):
#     def __init__(self, logger=None, handler=None, formatter=None):
#     def __call__(self, msg):
#     def __str__(self):
#     def getCurrentLogger(self):
#         def emit(self, record):
#     def __init__(self, *flags, **options):
#     def __str__(self):
#     def __call__(self, msg):
#     def __and__(self, flag):
#     def __rand__(self, flag):
#     def getCurrentPrinter(self):
#     def getCurrentLogger(self):
# def setLogger(l):
# 
# Path: pysmi/error.py
# class PySmiError(Exception):
# class PySmiLexerError(PySmiError):
# class PySmiParserError(PySmiLexerError):
# class PySmiSyntaxError(PySmiParserError):
# class PySmiSearcherError(PySmiError):
# class PySmiFileNotModifiedError(PySmiSearcherError):
# class PySmiFileNotFoundError(PySmiSearcherError):
# class PySmiReaderError(PySmiError):
# class PySmiReaderFileNotModifiedError(PySmiReaderError):
# class PySmiReaderFileNotFoundError(PySmiReaderError):
# class PySmiCodegenError(PySmiError):
# class PySmiSemanticError(PySmiCodegenError):
# class PySmiWriterError(PySmiError):
#     def __init__(self, *args, **kwargs):
#     def __repr__(self):
#     def __str__(self):
#     def __str__(self):


import sys
from pysmi.writer.base import AbstractWriter
from pysmi import debug
from pysmi import error
       .. function:: cbFun(mibname, contents, cbCtx)

    """

    def __init__(self, cbFun, cbCtx=None):
        """Creates an instance of *CallbackWriter* class.

        Args:
            cbFun (callable): user-supplied callable
        Keyword Args:
            cbCtx: user-supplied object passed intact to user callback
        """
        self._cbFun = cbFun
        self._cbCtx = cbCtx

    def __str__(self):
        return '%s{"%s"}' % (self.__class__.__name__, self._cbFun)

    def putData(self, mibname, data, comments=(), dryRun=False):
        if dryRun:
            debug.logger & debug.flagWriter and debug.logger('dry run mode')
            return

        try:
            self._cbFun(mibname, data, self._cbCtx)

        except Exception:
            raise error.PySmiWriterError(
                'user callback %s failure writing %s: %s' % (self._cbFun, mibname, sys.exc_info()[1]), writer=self)


# Path: pysmi/writer/base.py
# class AbstractWriter(object):
#     def setOptions(self, **kwargs):
#         for k in kwargs:
#             setattr(self, k, kwargs[k])
#         return self
# 
#     def putData(self, mibname, data, comments=(), dryRun=False):
#         raise NotImplementedError()
# 
#     def getData(self, filename):
#         raise NotImplementedError()
# 
# Path: pysmi/debug.py
# class Printer(object):
#     class NullHandler(logging.Handler):
# class Debug(object):
#     def __init__(self, logger=None, handler=None, formatter=None):
#     def __call__(self, msg):
#     def __str__(self):
#     def getCurrentLogger(self):
#         def emit(self, record):
#     def __init__(self, *flags, **options):
#     def __str__(self):
#     def __call__(self, msg):
#     def __and__(self, flag):
#     def __rand__(self, flag):
#     def getCurrentPrinter(self):
#     def getCurrentLogger(self):
# def setLogger(l):
# 
# Path: pysmi/error.py
# class PySmiError(Exception):
# class PySmiLexerError(PySmiError):
# class PySmiParserError(PySmiLexerError):
# class PySmiSyntaxError(PySmiParserError):
# class PySmiSearcherError(PySmiError):
# class PySmiFileNotModifiedError(PySmiSearcherError):
# class PySmiFileNotFoundError(PySmiSearcherError):
# class PySmiReaderError(PySmiError):
# class PySmiReaderFileNotModifiedError(PySmiReaderError):
# class PySmiReaderFileNotFoundError(PySmiReaderError):
# class PySmiCodegenError(PySmiError):
# class PySmiSemanticError(PySmiCodegenError):
# class PySmiWriterError(PySmiError):
#     def __init__(self, *args, **kwargs):
#     def __repr__(self):
#     def __str__(self):
#     def __str__(self):


# Path: pysmi/writer/callback.py
import sys
from pysmi.writer.base import AbstractWriter
from pysmi import debug
from pysmi import error

       .. function:: cbFun(mibname, contents, cbCtx)

    """

    def __init__(self, cbFun, cbCtx=None):
        """Creates an instance of *CallbackWriter* class.

        Args:
            cbFun (callable): user-supplied callable
        Keyword Args:
            cbCtx: user-supplied object passed intact to user callback
        """
        self._cbFun = cbFun
        self._cbCtx = cbCtx

    def __str__(self):
        return '%s{"%s"}' % (self.__class__.__name__, self._cbFun)

    def putData(self, mibname, data, comments=(), dryRun=False):
        if dryRun:
            debug.logger & debug.flagWriter and debug.logger('dry run mode')
            return

        try:
            self._cbFun(mibname, data, self._cbCtx)

        except Exception:
            raise error.PySmiWriterError(
                'user callback %s failure writing %s: %s' % (self._cbFun, mibname, sys.exc_info()[1]), writer=self)


        debug.logger & debug.flagWriter and debug.logger('user callback for %s succeeded' % mibname)