Skip to content

Fix MIB compilation with Python reserved keywords #68

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 10 additions & 2 deletions pysmi/codegen/intermediate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
unicode = str
long = int

RESERVED_KEYWORDS_PREFIX = 'pysmi_'


class IntermediateCodeGen(AbstractCodeGen):
"""Turns MIB AST into an intermediate representation.
Expand Down Expand Up @@ -1005,10 +1007,16 @@ def genCode(self, ast, symbolTable, **kwargs):
self.handlersTable[declr[0]](self, self.prepData(declr[1:]))

for sym in self.symbolTable[self.moduleName[0]]['_symtable_order']:
if sym not in self._out:
true_sym = sym

if sym.startswith(RESERVED_KEYWORDS_PREFIX):
# Removing prefix added for reserved keywords
true_sym = sym[len(RESERVED_KEYWORDS_PREFIX):]

if true_sym not in self._out:
raise error.PySmiCodegenError('No generated code for symbol %s' % sym)

outDict[sym] = self._out[sym]
outDict[sym] = self._out[true_sym]

outDict['meta'] = OrderedDict()
outDict['meta']['module'] = self.moduleName[0]
Expand Down