From b67f586eef4a6983003bdf688c5b8112a0daebcf Mon Sep 17 00:00:00 2001 From: Alexander Workin Date: Tue, 15 Aug 2023 13:50:08 -0500 Subject: [PATCH] Added strict mode. --- pysmi/codegen/intermediate.py | 8 +++++--- pysmi/scripts/mibdump.py | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pysmi/codegen/intermediate.py b/pysmi/codegen/intermediate.py index 7673a8d..9586a95 100644 --- a/pysmi/codegen/intermediate.py +++ b/pysmi/codegen/intermediate.py @@ -74,6 +74,7 @@ class IntermediateCodeGen(AbstractCodeGen): indent = " " * 4 fakeidx = 1000 # starting index for fake symbols + strictCompliance = True def __init__(self): self._rows = set() @@ -180,9 +181,10 @@ def regSym( if moduleIdentity: if self._moduleIdentityOid: - # TODO: maybe we should show a warning here - # raise error.PySmiSemanticError("Duplicate module identity") - pass + if self.strictCompliance: + raise error.PySmiSemanticError("Duplicate module identity") + else: + pass else: self._moduleIdentityOid = outDict["oid"] diff --git a/pysmi/scripts/mibdump.py b/pysmi/scripts/mibdump.py index a31426c..c8b678a 100644 --- a/pysmi/scripts/mibdump.py +++ b/pysmi/scripts/mibdump.py @@ -37,6 +37,7 @@ def start(): # Defaults verboseFlag = True + strictFlag = False mibSources = [] doFuzzyMatchingFlag = True mibSearchers = [] @@ -60,6 +61,7 @@ def start(): Usage: {} [--help] [--version] [--quiet] + [--strict] [--debug=<{}>] [--mib-source=] [--mib-searcher=] @@ -97,6 +99,7 @@ def start(): "help", "version", "quiet", + "strict", "debug=", "mib-source=", "mib-searcher=", @@ -157,6 +160,9 @@ def start(): if opt[0] == "--quiet": verboseFlag = False + if opt[0] == "--strict": + strictFlag = True + if opt[0] == "--debug": debug.setLogger(debug.Debug(*opt[1].split(","))) @@ -294,6 +300,7 @@ def start(): searchers.append(StubSearcher(*mibStubs)) codeGenerator = PySnmpCodeGen() + codeGenerator.strictCompliance = strictFlag fileWriter = PyFileWriter(dstDirectory).setOptions( pyCompile=pyCompileFlag, pyOptimizationLevel=pyOptimizationLevel @@ -331,6 +338,7 @@ def start(): ] codeGenerator = JsonCodeGen() + codeGenerator.strictCompliance = strictFlag fileWriter = FileWriter(dstDirectory).setOptions(suffix=".json")