Skip to content

Commit

Permalink
Added missing test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Oct 14, 2024
1 parent dd1c1f8 commit fc5ce6c
Show file tree
Hide file tree
Showing 39 changed files with 231 additions and 202 deletions.
2 changes: 1 addition & 1 deletion docs/source/faq/how-to-implement-agent-mib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ A. You need to create MibScalarInstance class instances and register
)
# add anonymous column instances
snmpEngine.get_mib_builder().exportSymbols(
snmpEngine.get_mib_builder().export_symbols(
'_IP-MIB',
_ipAddressAddrType,
_ipAddressAddr,
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ pytest-cov = "^4.1.0"
pytest-asyncio = "^0.21.1"
Sphinx = "^7.0.0"
sphinx-copybutton = "^0.5.2"
furo = "^2023.1.1"
sphinx-notfound-page = "^1.0.0"
sphinx-sitemap-lextudio = "^2.5.2"
sphinx-polyversion = "^1.0.0"
furo = "^2023.1.1"
black = "23.1.0"
pre-commit = "2.21.0"
doc8 = "^1.0.0"
sphinx-notfound-page = "^1.0.0"
flake8 = "5.0.4"
flake8 = "^5.0.4"
flake8-import-order = "^0.18.2"
flake8-docstrings = "^1.7.0"
flake8-rst-docstrings = "^0.3.0"
sphinx-polyversion = "^1.0.0"
pep8-naming = "^0.14.1"
cryptography = "^43.0.1"
pysmi = "^1.3.0"
pep8-naming = "^0.14.1"

[tool.poetry_bumpversion.file."pysnmp/__init__.py"]

Expand Down
6 changes: 3 additions & 3 deletions pysnmp/smi/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def export_symbols(self, modName, *anonymousSyms, **namedSyms):

for symObj in anonymousSyms:
debug.logger & debug.FLAG_BLD and debug.logger(
"exportSymbols: anonymous symbol %s::__pysnmp_%ld"
"export_symbols: anonymous symbol %s::__pysnmp_%ld"
% (modName, self._autoName)
)
mibSymbols["__pysnmp_%ld" % self._autoName] = symObj
Expand All @@ -486,7 +486,7 @@ def export_symbols(self, modName, *anonymousSyms, **namedSyms):
mibSymbols[symName] = symObj

debug.logger & debug.FLAG_BLD and debug.logger(
f"exportSymbols: symbol {modName}::{symName}"
f"export_symbols: symbol {modName}::{symName}"
)

self.lastBuildId += 1
Expand All @@ -504,7 +504,7 @@ def unexport_symbols(self, modName, *symNames):
del mibSymbols[symName]

debug.logger & debug.FLAG_BLD and debug.logger(
f"unexportSymbols: symbol {modName}::{symName}"
f"unexport_symbols: symbol {modName}::{symName}"
)

if not self.mibSymbols[modName]:
Expand Down
21 changes: 21 additions & 0 deletions pysnmp/smi/indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Copyright (c) 2005-2020, Ilya Etingof <[email protected]>
# License: https://www.pysnmp.com/pysnmp/license.html
#
import warnings
from bisect import bisect


Expand Down Expand Up @@ -103,6 +104,26 @@ def get_keys_lengths(self):
self.__order()
return self.__keysLens

# Compatibility API
# compatibility with legacy code
# Old to new attribute mapping
deprecated_attributes = {
"nextKey": "next_key",
"getKeysLens": "get_keys_lengths",
}

def __getattr__(self, attr: str):
if new_attr := self.deprecated_attributes.get(attr):
warnings.warn(
f"{attr} is deprecated. Please use {new_attr} instead.",
DeprecationWarning,
stacklevel=2,
)
return getattr(self, new_attr)
raise AttributeError(
f"'{self.__class__.__name__}' object has no attribute '{attr}'"
)


class OidOrderedDict(OrderedDict):
"""OID-ordered dictionary used for indices."""
Expand Down
2 changes: 1 addition & 1 deletion pysnmp/smi/mibs/ASN1-ENUMERATION.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
#
from pyasn1.type import namedval

mibBuilder.exportSymbols("ASN1-ENUMERATION", NamedValues=namedval.NamedValues)
mibBuilder.export_symbols("ASN1-ENUMERATION", NamedValues=namedval.NamedValues)
2 changes: 1 addition & 1 deletion pysnmp/smi/mibs/ASN1-REFINEMENT.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
from pyasn1.type import constraint

mibBuilder.exportSymbols(
mibBuilder.export_symbols(
"ASN1-REFINEMENT",
ConstraintsUnion=constraint.ConstraintsUnion,
ConstraintsIntersection=constraint.ConstraintsIntersection,
Expand Down
2 changes: 1 addition & 1 deletion pysnmp/smi/mibs/ASN1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pyasn1.type import univ
from pysnmp.proto import rfc1902

mibBuilder.exportSymbols(
mibBuilder.export_symbols(
"ASN1",
ObjectIdentifier=univ.ObjectIdentifier,
# Instead of using base ASN,1 types we use SNMPv2 SMI ones to make
Expand Down
14 changes: 7 additions & 7 deletions pysnmp/smi/mibs/INET-ADDRESS-MIB.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@
#
from pysnmp.smi import error

ObjectIdentifier, Integer, OctetString = mibBuilder.importSymbols(
ObjectIdentifier, Integer, OctetString = mibBuilder.import_symbols(
"ASN1", "ObjectIdentifier", "Integer", "OctetString"
)
(NamedValues,) = mibBuilder.importSymbols("ASN1-ENUMERATION", "NamedValues")
(NamedValues,) = mibBuilder.import_symbols("ASN1-ENUMERATION", "NamedValues")
(
ValueRangeConstraint,
ValueSizeConstraint,
ConstraintsIntersection,
ConstraintsUnion,
SingleValueConstraint,
) = mibBuilder.importSymbols(
) = mibBuilder.import_symbols(
"ASN1-REFINEMENT",
"ValueRangeConstraint",
"ValueSizeConstraint",
"ConstraintsIntersection",
"ConstraintsUnion",
"SingleValueConstraint",
)
NotificationGroup, ModuleCompliance = mibBuilder.importSymbols(
NotificationGroup, ModuleCompliance = mibBuilder.import_symbols(
"SNMPv2-CONF", "NotificationGroup", "ModuleCompliance"
)
(
Expand All @@ -52,7 +52,7 @@
Unsigned32,
ObjectIdentity,
ModuleIdentity,
) = mibBuilder.importSymbols(
) = mibBuilder.import_symbols(
"SNMPv2-SMI",
"Gauge32",
"iso",
Expand All @@ -73,7 +73,7 @@
"ObjectIdentity",
"ModuleIdentity",
)
TextualConvention, DisplayString = mibBuilder.importSymbols(
TextualConvention, DisplayString = mibBuilder.import_symbols(
"SNMPv2-TC", "TextualConvention", "DisplayString"
)
inetAddressMIB = ModuleIdentity((1, 3, 6, 1, 2, 1, 76))
Expand Down Expand Up @@ -257,7 +257,7 @@ class InetVersion(TextualConvention, Integer32):
namedValues = NamedValues(("unknown", 0), ("ipv4", 1), ("ipv6", 2))


mibBuilder.exportSymbols(
mibBuilder.export_symbols(
"INET-ADDRESS-MIB",
inetAddressMIB=inetAddressMIB,
InetVersion=InetVersion,
Expand Down
14 changes: 7 additions & 7 deletions pysnmp/smi/mibs/PYSNMP-MIB.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@
# On host grommit.local platform Darwin version 16.4.0 by user ilya
# Using Python version 3.4.2 (v3.4.2:ab2c023a9432, Oct 5 2014, 20:42:22)
#
Integer, OctetString, ObjectIdentifier = mibBuilder.importSymbols(
Integer, OctetString, ObjectIdentifier = mibBuilder.import_symbols(
"ASN1", "Integer", "OctetString", "ObjectIdentifier"
)
(NamedValues,) = mibBuilder.importSymbols("ASN1-ENUMERATION", "NamedValues")
(NamedValues,) = mibBuilder.import_symbols("ASN1-ENUMERATION", "NamedValues")
(
SingleValueConstraint,
ValueRangeConstraint,
ConstraintsIntersection,
ValueSizeConstraint,
ConstraintsUnion,
) = mibBuilder.importSymbols(
) = mibBuilder.import_symbols(
"ASN1-REFINEMENT",
"SingleValueConstraint",
"ValueRangeConstraint",
"ConstraintsIntersection",
"ValueSizeConstraint",
"ConstraintsUnion",
)
NotificationGroup, ModuleCompliance = mibBuilder.importSymbols(
NotificationGroup, ModuleCompliance = mibBuilder.import_symbols(
"SNMPv2-CONF", "NotificationGroup", "ModuleCompliance"
)
(
Expand All @@ -50,7 +50,7 @@
Integer32,
enterprises,
TimeTicks,
) = mibBuilder.importSymbols(
) = mibBuilder.import_symbols(
"SNMPv2-SMI",
"ModuleIdentity",
"iso",
Expand All @@ -71,7 +71,7 @@
"enterprises",
"TimeTicks",
)
TextualConvention, DisplayString = mibBuilder.importSymbols(
TextualConvention, DisplayString = mibBuilder.import_symbols(
"SNMPv2-TC", "TextualConvention", "DisplayString"
)
pysnmp = ModuleIdentity((1, 3, 6, 1, 4, 1, 20408))
Expand Down Expand Up @@ -105,7 +105,7 @@
pysnmpConformance = MibIdentifier((1, 3, 6, 1, 4, 1, 20408, 5))
pysnmpCompliances = MibIdentifier((1, 3, 6, 1, 4, 1, 20408, 5, 1))
pysnmpGroups = MibIdentifier((1, 3, 6, 1, 4, 1, 20408, 5, 2))
mibBuilder.exportSymbols(
mibBuilder.export_symbols(
"PYSNMP-MIB",
pysnmpCompliances=pysnmpCompliances,
pysnmpObjects=pysnmpObjects,
Expand Down
18 changes: 9 additions & 9 deletions pysnmp/smi/mibs/PYSNMP-SOURCE-MIB.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@
# On host grommit.local platform Darwin version 16.4.0 by user ilya
# Using Python version 3.4.2 (v3.4.2:ab2c023a9432, Oct 5 2014, 20:42:22)
#
Integer, OctetString, ObjectIdentifier = mibBuilder.importSymbols(
Integer, OctetString, ObjectIdentifier = mibBuilder.import_symbols(
"ASN1", "Integer", "OctetString", "ObjectIdentifier"
)
(NamedValues,) = mibBuilder.importSymbols("ASN1-ENUMERATION", "NamedValues")
(NamedValues,) = mibBuilder.import_symbols("ASN1-ENUMERATION", "NamedValues")
(
SingleValueConstraint,
ValueRangeConstraint,
ConstraintsIntersection,
ValueSizeConstraint,
ConstraintsUnion,
) = mibBuilder.importSymbols(
) = mibBuilder.import_symbols(
"ASN1-REFINEMENT",
"SingleValueConstraint",
"ValueRangeConstraint",
"ConstraintsIntersection",
"ValueSizeConstraint",
"ConstraintsUnion",
)
(pysnmpModuleIDs,) = mibBuilder.importSymbols("PYSNMP-MIB", "pysnmpModuleIDs")
(snmpTargetAddrEntry,) = mibBuilder.importSymbols(
(pysnmpModuleIDs,) = mibBuilder.import_symbols("PYSNMP-MIB", "pysnmpModuleIDs")
(snmpTargetAddrEntry,) = mibBuilder.import_symbols(
"SNMP-TARGET-MIB", "snmpTargetAddrEntry"
)
NotificationGroup, ModuleCompliance = mibBuilder.importSymbols(
NotificationGroup, ModuleCompliance = mibBuilder.import_symbols(
"SNMPv2-CONF", "NotificationGroup", "ModuleCompliance"
)
(
Expand All @@ -53,7 +53,7 @@
Bits,
Integer32,
TimeTicks,
) = mibBuilder.importSymbols(
) = mibBuilder.import_symbols(
"SNMPv2-SMI",
"ModuleIdentity",
"iso",
Expand All @@ -73,7 +73,7 @@
"Integer32",
"TimeTicks",
)
TextualConvention, DisplayString, TAddress = mibBuilder.importSymbols(
TextualConvention, DisplayString, TAddress = mibBuilder.import_symbols(
"SNMPv2-TC", "TextualConvention", "DisplayString", "TAddress"
)
pysnmpSourceMIB = ModuleIdentity((1, 3, 6, 1, 4, 1, 20408, 3, 1, 8))
Expand Down Expand Up @@ -129,7 +129,7 @@
)
pysnmpSourceMIBCompliances = MibIdentifier((1, 3, 6, 1, 4, 1, 20408, 3, 1, 8, 2, 1))
pysnmpSourceMIBGroups = MibIdentifier((1, 3, 6, 1, 4, 1, 20408, 3, 1, 8, 2, 2))
mibBuilder.exportSymbols(
mibBuilder.export_symbols(
"PYSNMP-SOURCE-MIB",
pysnmpSourceMIBConformance=pysnmpSourceMIBConformance,
pysnmpSourceMIB=pysnmpSourceMIB,
Expand Down
20 changes: 10 additions & 10 deletions pysnmp/smi/mibs/PYSNMP-USM-MIB.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@
# On host grommit.local platform Darwin version 16.4.0 by user ilya
# Using Python version 3.4.2 (v3.4.2:ab2c023a9432, Oct 5 2014, 20:42:22)
#
Integer, OctetString, ObjectIdentifier = mibBuilder.importSymbols(
Integer, OctetString, ObjectIdentifier = mibBuilder.import_symbols(
"ASN1", "Integer", "OctetString", "ObjectIdentifier"
)
(NamedValues,) = mibBuilder.importSymbols("ASN1-ENUMERATION", "NamedValues")
(NamedValues,) = mibBuilder.import_symbols("ASN1-ENUMERATION", "NamedValues")
(
SingleValueConstraint,
ValueRangeConstraint,
ConstraintsIntersection,
ValueSizeConstraint,
ConstraintsUnion,
) = mibBuilder.importSymbols(
) = mibBuilder.import_symbols(
"ASN1-REFINEMENT",
"SingleValueConstraint",
"ValueRangeConstraint",
"ConstraintsIntersection",
"ValueSizeConstraint",
"ConstraintsUnion",
)
(pysnmpModuleIDs,) = mibBuilder.importSymbols("PYSNMP-MIB", "pysnmpModuleIDs")
(SnmpAdminString,) = mibBuilder.importSymbols("SNMP-FRAMEWORK-MIB", "SnmpAdminString")
(usmUserEntry,) = mibBuilder.importSymbols("SNMP-USER-BASED-SM-MIB", "usmUserEntry")
NotificationGroup, ModuleCompliance = mibBuilder.importSymbols(
(pysnmpModuleIDs,) = mibBuilder.import_symbols("PYSNMP-MIB", "pysnmpModuleIDs")
(SnmpAdminString,) = mibBuilder.import_symbols("SNMP-FRAMEWORK-MIB", "SnmpAdminString")
(usmUserEntry,) = mibBuilder.import_symbols("SNMP-USER-BASED-SM-MIB", "usmUserEntry")
NotificationGroup, ModuleCompliance = mibBuilder.import_symbols(
"SNMPv2-CONF", "NotificationGroup", "ModuleCompliance"
)
(
Expand All @@ -52,7 +52,7 @@
Bits,
Integer32,
TimeTicks,
) = mibBuilder.importSymbols(
) = mibBuilder.import_symbols(
"SNMPv2-SMI",
"ModuleIdentity",
"iso",
Expand All @@ -72,7 +72,7 @@
"Integer32",
"TimeTicks",
)
RowStatus, DisplayString, TextualConvention = mibBuilder.importSymbols(
RowStatus, DisplayString, TextualConvention = mibBuilder.import_symbols(
"SNMPv2-TC", "RowStatus", "DisplayString", "TextualConvention"
)
pysnmpUsmMIB = ModuleIdentity((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1))
Expand Down Expand Up @@ -263,7 +263,7 @@
pysnmpUsmKeyPriv.setDescription("User's non-localized key used for encryption.")
pysnmpUsmMIBCompliances = MibIdentifier((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 2, 1))
pysnmpUsmMIBGroups = MibIdentifier((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 2, 2))
mibBuilder.exportSymbols(
mibBuilder.export_symbols(
"PYSNMP-USM-MIB",
pysnmpUsmCfg=pysnmpUsmCfg,
pysnmpUsmDiscoverable=pysnmpUsmDiscoverable,
Expand Down
4 changes: 2 additions & 2 deletions pysnmp/smi/mibs/RFC1158-MIB.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
MibIdentifier,
Bits,
Counter32,
) = mibBuilder.importSymbols(
) = mibBuilder.import_symbols(
"SNMPv2-SMI",
"Integer32",
"MibScalar",
Expand All @@ -49,6 +49,6 @@
)
if mibBuilder.loadTexts:
snmpOutReadOnlys.setStatus("mandatory")
mibBuilder.exportSymbols(
mibBuilder.export_symbols(
"RFC1158-MIB", snmpOutReadOnlys=snmpOutReadOnlys, snmpInBadTypes=snmpInBadTypes
)
Loading

0 comments on commit fc5ce6c

Please sign in to comment.