SMI parser#
SNMP MIBs are written in two kinds of special language - SMIv1 and SMIv2. The first SMI version is obsolete, most MIBs by now are written in SMIv2 grammar. There are also efforts aimed at improving SMIv2, but those MIBs are in great minority at the time of this writing.
PySMI is designed to handle both SMIv1 and SMIv2. The way it is done is that SMIv2 is considered the most basic and complete, whereas SMIv1 is a specialization of SMIv2 syntax.
For a user to acquire SMIv2 parser the parserFactory function should be called with the SMI dialect object.
The parser object should be passed to the MibCompiler object.
- pysmi.parser.smi.parserFactory(**grammarOptions)#
Factory function producing custom specializations of base SmiV2Parser class.
- Keyword Arguments:
grammarOptions – a list of (bool) typed optional keyword parameters enabling particular set of SMIv2 grammar relaxations.
- Returns:
Specialized copy of SmiV2Parser class.
Notes
The following SMIv2 grammar relaxation parameters are defined:
supportSmiV1Keywords - parses SMIv1 grammar
supportIndex - tolerates ASN.1 types in INDEX clause
commaAtTheEndOfImport - tolerates stray comma at the end of IMPORT section
commaAtTheEndOfSequence - tolerates stray comma at the end of sequence of elements in MIB
mixOfCommasAndSpaces - tolerate a mix of comma and spaces in MIB enumerations
uppercaseIdentifier - tolerate uppercased MIB identifiers
lowcaseIdentifier - tolerate lowercase MIB identifiers
curlyBracesAroundEnterpriseInTrap - tolerate curly braces around enterprise ID in TRAP MACRO
noCells - tolerate missing cells (XXX)
Examples:
>>> from pysmi.parser import smi >>> SmiV1Parser = smi.parserFactory(supportSmiV1Keywords=True, supportIndex=True)
Note
Please, note that parserFactory function returns a class, not class instance. Make sure to instantiate it when passing to MibCompiler class constructor.