Skip to content

Commit

Permalink
Merge pull request #3 from dcvmoole/improved-mib-support
Browse files Browse the repository at this point in the history
Various fixes and improvements regarding support of real-world MIBs
  • Loading branch information
lextm authored Sep 2, 2024
2 parents a6d4281 + 88d214c commit cddb4fc
Show file tree
Hide file tree
Showing 28 changed files with 2,525 additions and 263 deletions.
20 changes: 19 additions & 1 deletion pysmi/codegen/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
# License: https://www.pysnmp.com/pysmi/license.html
#
import sys
from keyword import iskeyword
from pysmi import error

# Prefix added to symbols that happen to be Python keywords. The leading
# underscore ensures that there is no overlap with any other symbols.
RESERVED_KEYWORDS_PREFIX = "_pysmi_"


def dorepr(s):
return repr(s)
Expand Down Expand Up @@ -222,7 +227,7 @@ class AbstractCodeGen:
"RFC1065-SMI": commonSyms["RFC1155-SMI/RFC1065-SMI"],
"RFC1155-SMI": commonSyms["RFC1155-SMI/RFC1065-SMI"],
"RFC1158-MIB": updateDict(
dict(commonSyms["RFC1155-SMI/RFC1065-SMI"]),
dict(commonSyms["RFC1158-MIB/RFC1213-MIB"]),
(
("nullSpecific", [("SNMPv2-SMI", "zeroDotZero")]),
("ipRoutingTable", [("RFC1213-MIB", "ipRouteTable")]),
Expand Down Expand Up @@ -272,6 +277,13 @@ class AbstractCodeGen:
"RFC-1215": {"TRAP-TYPE": [("SNMPv2-SMI", "TRAP-TYPE")]},
}

smiv1IdxTypes = ["INTEGER", "OCTET STRING", "IpAddress", "NetworkAddress"]

# Name prefix and starting number of fake index object types, as generated
# the fly to support SMIv1-only index types (e.g., "INDEX { INTEGER }").
fakeIdxPrefix = "pysmiFakeCol"
fakeIdxNumber = 1

def genCode(self, ast, symbolTable, **kwargs):
raise NotImplementedError()

Expand Down Expand Up @@ -300,3 +312,9 @@ def str2int(self, s):
raise error.PySmiSemanticError("empty hex string to int conversion")
else:
return int(s)

@staticmethod
def transOpers(symbol):
if iskeyword(symbol):
symbol = RESERVED_KEYWORDS_PREFIX + symbol
return symbol.replace("-", "_")
Loading

0 comments on commit cddb4fc

Please sign in to comment.