# Path: pysmi/lexer/smi.py
# def lexerFactory(**grammarOptions):
#     classAttr = {}
# 
#     for option in grammarOptions:
#         if grammarOptions[option]:
#             if option not in relaxedGrammar:
#                 raise error.PySmiError('Unknown lexer relaxation option: %s' % option)
# 
#             for func in relaxedGrammar[option]:
#                 if sys.version_info[0] > 2:
#                     classAttr[func.__name__] = func()
#                 else:
#                     classAttr[func.func_name] = func()
# 
#     return type('SmiLexer', (SmiV2Lexer,), classAttr)
# 
# Path: pysmi/parser/base.py
# class AbstractParser(object):
#     def reset(self):
#         raise NotImplementedError()
# 
#     def parse(self, data, **kwargs):
#         raise NotImplementedError()
# 
# 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/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):


import os
import sys
import ply.yacc as yacc
from pysmi.lexer.smi import lexerFactory
from pysmi.parser.base import AbstractParser
from pysmi import error
from pysmi import debug
# noinspection PyMethodMayBeStatic,PyIncorrectDocstring
class SmiV2Parser(AbstractParser):
    defaultLexer = lexerFactory()

    def __init__(self, startSym='mibFile', tempdir=''):
        if tempdir:
            tempdir = os.path.join(tempdir, startSym)
            try:
                os.makedirs(tempdir)
            except OSError:
                if sys.exc_info()[1].errno != 17:
                    raise error.PySmiError('Failed to create cache directory %s: %s' % (tempdir, sys.exc_info()[1]))

        self.lexer = self.defaultLexer(tempdir=tempdir)

        # tokens are required for parser
        self.tokens = self.lexer.tokens

        if YACC_VERSION < [3, 0]:
            self.parser = yacc.yacc(module=self,
                                    start=startSym,
                                    write_tables=bool(tempdir),
                                    debug=False,
                                    outputdir=tempdir)
        else:
            if debug.logger & debug.flagParser:
                logger = debug.logger.getCurrentLogger()
            else:
                logger = yacc.NullLogger()


# Path: pysmi/lexer/smi.py
# def lexerFactory(**grammarOptions):
#     classAttr = {}
# 
#     for option in grammarOptions:
#         if grammarOptions[option]:
#             if option not in relaxedGrammar:
#                 raise error.PySmiError('Unknown lexer relaxation option: %s' % option)
# 
#             for func in relaxedGrammar[option]:
#                 if sys.version_info[0] > 2:
#                     classAttr[func.__name__] = func()
#                 else:
#                     classAttr[func.func_name] = func()
# 
#     return type('SmiLexer', (SmiV2Lexer,), classAttr)
# 
# Path: pysmi/parser/base.py
# class AbstractParser(object):
#     def reset(self):
#         raise NotImplementedError()
# 
#     def parse(self, data, **kwargs):
#         raise NotImplementedError()
# 
# 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/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/parser/smi.py
import os
import sys
import ply.yacc as yacc
from pysmi.lexer.smi import lexerFactory
from pysmi.parser.base import AbstractParser
from pysmi import error
from pysmi import debug

# noinspection PyMethodMayBeStatic,PyIncorrectDocstring
class SmiV2Parser(AbstractParser):
    defaultLexer = lexerFactory()

    def __init__(self, startSym='mibFile', tempdir=''):
        if tempdir:
            tempdir = os.path.join(tempdir, startSym)
            try:
                os.makedirs(tempdir)
            except OSError:
                if sys.exc_info()[1].errno != 17:
                    raise error.PySmiError('Failed to create cache directory %s: %s' % (tempdir, sys.exc_info()[1]))

        self.lexer = self.defaultLexer(tempdir=tempdir)

        # tokens are required for parser
        self.tokens = self.lexer.tokens

        if YACC_VERSION < [3, 0]:
            self.parser = yacc.yacc(module=self,
                                    start=startSym,
                                    write_tables=bool(tempdir),
                                    debug=False,
                                    outputdir=tempdir)
        else:
            if debug.logger & debug.flagParser:
                logger = debug.logger.getCurrentLogger()
            else:
                logger = yacc.NullLogger()


            if debug.logger & debug.flagGrammar: