# Path: pysnmp/smi/error.py
# class NoSuchInstanceError(MibOperationError): pass
# 
# Path: pysnmp/proto/errind.py
# class ErrorIndication:
# class ParseError(ErrorIndication): pass
# class UnsupportedMsgProcessingModel(ErrorIndication): pass
# class UnknownPDUHandler(ErrorIndication): pass
# class UnsupportedPDUtype(ErrorIndication): pass
# class RequestTimedOut(ErrorIndication): pass
# class EmptyResponse(ErrorIndication): pass
# class NonReportable(ErrorIndication): pass
# class DataMismatch(ErrorIndication): pass
# class EngineIDMismatch(ErrorIndication): pass
# class UnknownEngineID(ErrorIndication): pass
# class TooBig(ErrorIndication): pass
# class LoopTerminated(ErrorIndication):pass
# class InvalidMsg(ErrorIndication):pass
# class UnknownCommunityName(ErrorIndication): pass
# class NoEncryption(ErrorIndication): pass
# class EncryptionError(ErrorIndication): pass
# class DecryptionError(ErrorIndication): pass
# class NoAuthentication(ErrorIndication): pass
# class AuthenticationError(ErrorIndication): pass
# class AuthenticationFailure(ErrorIndication): pass
# class UnsupportedAuthProtocol(ErrorIndication): pass
# class UnsupportedPrivProtocol(ErrorIndication): pass
# class UnknownSecurityName(ErrorIndication): pass
# class UnsupportedSecurityModel(ErrorIndication): pass
# class UnsupportedSecurityLevel(ErrorIndication): pass
# class NotInTimeWindow(ErrorIndication): pass
# class NoSuchView(ErrorIndication): pass
# class NoAccessEntry(ErrorIndication): pass
# class NoGroupName(ErrorIndication): pass
# class NoSuchContext(ErrorIndication): pass
# class NotInView(ErrorIndication): pass
# class AccessAllowed(ErrorIndication): pass
# class OtherError(ErrorIndication): pass
# class OidNotIncreasing(ErrorIndication): pass
#     def __init__(self, descr=None):
#     def __eq__(self, other): return self.__value == other
#     def __ne__(self, other): return self.__value != other
#     def __lt__(self, other): return self.__value < other
#     def __le__(self, other): return self.__value <= other
#     def __gt__(self, other): return self.__value > other
#     def __ge__(self, other): return self.__value >= other
#     def __str__(self): return self.__descr
# 
# 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):


from pysnmp.smi.error import NoSuchInstanceError
from pysnmp.proto import errind, error
from pysnmp import debug
# View-based Access Control Model

accessModelID = 3

__powOfTwoSeq = [128, 64, 32, 16, 8, 4, 2, 1]

# 3.2
def isAccessAllowed(
    snmpEngine,
    securityModel,
    securityName,
    securityLevel,
    viewType,
    contextName,
    variableName):
    mibInstrumController = snmpEngine.msgAndPduDsp.mibInstrumController

    debug.logger & debug.flagACL and debug.logger('isAccessAllowed: securityModel %s, securityName %s, securityLevel %s, viewType %s, contextName %s for variableName %s' % (securityModel, securityName, securityLevel, viewType, contextName, variableName))

    # 3.2.1
    vacmContextEntry, = mibInstrumController.mibBuilder.importSymbols('SNMP-VIEW-BASED-ACM-MIB', 'vacmContextEntry')
    tblIdx = vacmContextEntry.getInstIdFromIndices(contextName)
    try:
        vacmContextName = vacmContextEntry.getNode(
            vacmContextEntry.name + (1,) + tblIdx
            ).syntax
    except NoSuchInstanceError:

# Path: pysnmp/smi/error.py
# class NoSuchInstanceError(MibOperationError): pass
# 
# Path: pysnmp/proto/errind.py
# class ErrorIndication:
# class ParseError(ErrorIndication): pass
# class UnsupportedMsgProcessingModel(ErrorIndication): pass
# class UnknownPDUHandler(ErrorIndication): pass
# class UnsupportedPDUtype(ErrorIndication): pass
# class RequestTimedOut(ErrorIndication): pass
# class EmptyResponse(ErrorIndication): pass
# class NonReportable(ErrorIndication): pass
# class DataMismatch(ErrorIndication): pass
# class EngineIDMismatch(ErrorIndication): pass
# class UnknownEngineID(ErrorIndication): pass
# class TooBig(ErrorIndication): pass
# class LoopTerminated(ErrorIndication):pass
# class InvalidMsg(ErrorIndication):pass
# class UnknownCommunityName(ErrorIndication): pass
# class NoEncryption(ErrorIndication): pass
# class EncryptionError(ErrorIndication): pass
# class DecryptionError(ErrorIndication): pass
# class NoAuthentication(ErrorIndication): pass
# class AuthenticationError(ErrorIndication): pass
# class AuthenticationFailure(ErrorIndication): pass
# class UnsupportedAuthProtocol(ErrorIndication): pass
# class UnsupportedPrivProtocol(ErrorIndication): pass
# class UnknownSecurityName(ErrorIndication): pass
# class UnsupportedSecurityModel(ErrorIndication): pass
# class UnsupportedSecurityLevel(ErrorIndication): pass
# class NotInTimeWindow(ErrorIndication): pass
# class NoSuchView(ErrorIndication): pass
# class NoAccessEntry(ErrorIndication): pass
# class NoGroupName(ErrorIndication): pass
# class NoSuchContext(ErrorIndication): pass
# class NotInView(ErrorIndication): pass
# class AccessAllowed(ErrorIndication): pass
# class OtherError(ErrorIndication): pass
# class OidNotIncreasing(ErrorIndication): pass
#     def __init__(self, descr=None):
#     def __eq__(self, other): return self.__value == other
#     def __ne__(self, other): return self.__value != other
#     def __lt__(self, other): return self.__value < other
#     def __le__(self, other): return self.__value <= other
#     def __gt__(self, other): return self.__value > other
#     def __ge__(self, other): return self.__value >= other
#     def __str__(self): return self.__descr
# 
# 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/proto/acmod/rfc3415.py
from pysnmp.smi.error import NoSuchInstanceError
from pysnmp.proto import errind, error
from pysnmp import debug

# View-based Access Control Model

accessModelID = 3

__powOfTwoSeq = [128, 64, 32, 16, 8, 4, 2, 1]

# 3.2
def isAccessAllowed(
    snmpEngine,
    securityModel,
    securityName,
    securityLevel,
    viewType,
    contextName,
    variableName):
    mibInstrumController = snmpEngine.msgAndPduDsp.mibInstrumController

    debug.logger & debug.flagACL and debug.logger('isAccessAllowed: securityModel %s, securityName %s, securityLevel %s, viewType %s, contextName %s for variableName %s' % (securityModel, securityName, securityLevel, viewType, contextName, variableName))

    # 3.2.1
    vacmContextEntry, = mibInstrumController.mibBuilder.importSymbols('SNMP-VIEW-BASED-ACM-MIB', 'vacmContextEntry')
    tblIdx = vacmContextEntry.getInstIdFromIndices(contextName)
    try:
        vacmContextName = vacmContextEntry.getNode(
            vacmContextEntry.name + (1,) + tblIdx
            ).syntax
    except NoSuchInstanceError:

        raise error.StatusInformation(errorIndication=errind.noSuchContext)    