Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes and improvements regarding support of real-world MIBs #3

Merged
merged 18 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading