/usr/lib/python3/dist-packages/pysnmp/entity/rfc3413/mibvar.py is in python3-pysnmp4 4.2.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | #
# THESE FUNCTIONS ARE OBSOLETE AND MUST NOT BE USED!
# USE pysnmp.entity.rfc3413.oneliner.mibvar INSTEAD
#
# MIB variable pretty printers/parsers
from pyasn1.type import univ
from pysnmp.smi.error import NoSuchObjectError
# Name
def mibNameToOid(mibView, name):
if isinstance(name[0], tuple):
f = lambda x='',y='': (x,y)
modName, symName = f(*name[0])
if modName: # load module if needed
mibView.mibBuilder.loadModules(modName)
else:
mibView.mibBuilder.loadModules() # load all (slow)
if symName:
oid, label, suffix = mibView.getNodeNameByDesc(symName, modName)
else:
oid, label, suffix = mibView.getFirstNodeName(modName)
suffix = name[1:]
modName, symName, _s = mibView.getNodeLocation(oid)
mibNode, = mibView.mibBuilder.importSymbols(
modName, symName
)
if hasattr(mibNode, 'createTest'): # table column XXX
modName, symName, _s = mibView.getNodeLocation(oid[:-1])
rowNode, = mibView.mibBuilder.importSymbols(modName, symName)
return oid, rowNode.getInstIdFromIndices(*suffix)
else: # scalar or incomplete spec
return oid, suffix
elif not isinstance(name, tuple):
name = tuple(univ.ObjectIdentifier(name))
oid, label, suffix = mibView.getNodeNameByOid(name)
return oid, suffix
__scalarSuffix = (univ.Integer(0),)
def oidToMibName(mibView, oid):
if not isinstance(oid, tuple):
oid = tuple(univ.ObjectIdentifier(oid))
_oid, label, suffix = mibView.getNodeNameByOid(oid)
modName, symName, __suffix = mibView.getNodeLocation(_oid)
mibNode, = mibView.mibBuilder.importSymbols(
modName, symName
)
if hasattr(mibNode, 'createTest'): # table column
__modName, __symName, __s = mibView.getNodeLocation(_oid[:-1])
rowNode, = mibView.mibBuilder.importSymbols(__modName, __symName)
return (symName, modName), rowNode.getIndicesFromInstId(suffix)
elif not suffix: # scalar
return (symName, modName), suffix
elif suffix == (0,): # scalar
return (symName, modName), __scalarSuffix
else:
raise NoSuchObjectError(
str='No MIB registered that defines %s object, closest known parent is %s (%s::%s)' % (univ.ObjectIdentifier(oid), univ.ObjectIdentifier(mibNode.name), modName, symName)
)
# Value
def cloneFromMibValue(mibView, modName, symName, value):
mibNode, = mibView.mibBuilder.importSymbols(
modName, symName
)
if hasattr(mibNode, 'syntax'): # scalar
return mibNode.syntax.clone(value)
else:
return # identifier
|