def parserFactory(**grammarOptions):
classAttr = {}<EOL>for option in grammarOptions:<EOL><INDENT>if grammarOptions[option]:<EOL><INDENT>if option not in relaxedGrammar:<EOL><INDENT>raise error.PySmiError('<STR_LIT>' % option)<EOL><DEDENT>for func in relaxedGrammar[option]:<EOL><INDENT>if sys.version_info[<NUM_LIT:0>] > <NUM_LIT:2>:<EOL><INDENT>classAttr[func.__name__] = func<EOL><DEDENT>else:<EOL><INDENT>classAttr[func.func_name] = func<EOL><DEDENT><DEDENT><DEDENT><DEDENT>classAttr['<STR_LIT>'] = lexerFactory(**grammarOptions)<EOL>return type('<STR_LIT>', (SmiV2Parser,), classAttr)<EOL>
Factory function producing custom specializations of base *SmiV2Parser*
       class.

       Keyword Args:
           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)