def compile(self, *mibnames, **options):
processed = {}<EOL>parsedMibs = {}<EOL>failedMibs = {}<EOL>borrowedMibs = {}<EOL>builtMibs = {}<EOL>symbolTableMap = {}<EOL>mibsToParse = [x for x in mibnames]<EOL>canonicalMibNames = {}<EOL>while mibsToParse:<EOL><INDENT>mibname = mibsToParse.pop(<NUM_LIT:0>)<EOL>if mibname in parsedMibs:<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % mibname)<EOL>continue<EOL><DEDENT>if mibname in failedMibs:<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % mibname)<EOL>continue<EOL><DEDENT>for source in self._sources:<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % source)<EOL>try:<EOL><INDENT>fileInfo, fileData = source.getData(mibname)<EOL>for mibTree in self._parser.parse(fileData):<EOL><INDENT>mibInfo, symbolTable = self._symbolgen.genCode(<EOL>mibTree, symbolTableMap<EOL>)<EOL>symbolTableMap[mibInfo.name] = symbolTable<EOL>parsedMibs[mibInfo.name] = fileInfo, mibInfo, mibTree<EOL>if mibname in failedMibs:<EOL><INDENT>del failedMibs[mibname]<EOL><DEDENT>mibsToParse.extend(mibInfo.imported)<EOL>if fileInfo.name in mibnames:<EOL><INDENT>if mibInfo.name not in canonicalMibNames:<EOL><INDENT>canonicalMibNames[mibInfo.name] = []<EOL><DEDENT>canonicalMibNames[mibInfo.name].append(fileInfo.name)<EOL><DEDENT>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % (<EOL>mibInfo.name, mibname, fileInfo.path, '<STR_LIT:U+002CU+0020>'.join(mibInfo.imported) or '<STR_LIT>'))<EOL><DEDENT>break<EOL><DEDENT>except error.PySmiReaderFileNotFoundError:<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % (mibname, source))<EOL>continue<EOL><DEDENT>except error.PySmiError:<EOL><INDENT>exc_class, exc, tb = sys.exc_info()<EOL>exc.source = source<EOL>exc.mibname = mibname<EOL>exc.msg += '<STR_LIT>' % mibname<EOL>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % (<EOL>options.get('<STR_LIT>') and '<STR_LIT>' or '<STR_LIT>', exc, source))<EOL>failedMibs[mibname] = exc<EOL>processed[mibname] = statusFailed.setOptions(error=exc)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>exc = error.PySmiError('<STR_LIT>' % mibname)<EOL>exc.mibname = mibname<EOL>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % mibname)<EOL>if mibname not in failedMibs:<EOL><INDENT>failedMibs[mibname] = exc<EOL><DEDENT>if mibname not in processed:<EOL><INDENT>processed[mibname] = statusMissing<EOL><DEDENT><DEDENT><DEDENT>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % (len(parsedMibs), len(failedMibs)))<EOL>for mibname in tuple(parsedMibs):<EOL><INDENT>fileInfo, mibInfo, mibTree = parsedMibs[mibname]<EOL>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % mibname)<EOL>for searcher in self._searchers:<EOL><INDENT>try:<EOL><INDENT>searcher.fileExists(mibname, fileInfo.mtime, rebuild=options.get('<STR_LIT>'))<EOL><DEDENT>except error.PySmiFileNotFoundError:<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % (mibname, searcher))<EOL>continue<EOL><DEDENT>except error.PySmiFileNotModifiedError:<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % (mibname, searcher))<EOL>del parsedMibs[mibname]<EOL>processed[mibname] = statusUntouched<EOL>break<EOL><DEDENT>except error.PySmiError:<EOL><INDENT>exc_class, exc, tb = sys.exc_info()<EOL>exc.searcher = searcher<EOL>exc.mibname = mibname<EOL>exc.msg += '<STR_LIT>' % mibname<EOL>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % (searcher, exc))<EOL>continue<EOL><DEDENT><DEDENT>else:<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % mibname)<EOL>if options.get('<STR_LIT>') and mibname not in canonicalMibNames:<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % mibname)<EOL>del parsedMibs[mibname]<EOL>processed[mibname] = statusUntouched<EOL>continue<EOL><DEDENT><DEDENT><DEDENT>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % (len(parsedMibs), len(failedMibs)))<EOL>for mibname in parsedMibs.copy():<EOL><INDENT>fileInfo, mibInfo, mibTree = parsedMibs[mibname]<EOL>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % (mibname, fileInfo.path))<EOL>platform_info, user_info = self._get_system_info()<EOL>comments = [<EOL>'<STR_LIT>' % fileInfo.path,<EOL>'<STR_LIT>' % (packageName, packageVersion, time.asctime()),<EOL>'<STR_LIT>' % (platform_info[<NUM_LIT:1>], platform_info[<NUM_LIT:0>],<EOL>platform_info[<NUM_LIT:2>], user_info[<NUM_LIT:0>]),<EOL>'<STR_LIT>' % sys.version.split('<STR_LIT:\n>')[<NUM_LIT:0>]<EOL>]<EOL>try:<EOL><INDENT>mibInfo, mibData = self._codegen.genCode(<EOL>mibTree,<EOL>symbolTableMap,<EOL>comments=comments,<EOL>dstTemplate=options.get('<STR_LIT>'),<EOL>genTexts=options.get('<STR_LIT>'),<EOL>textFilter=options.get('<STR_LIT>')<EOL>)<EOL>builtMibs[mibname] = fileInfo, mibInfo, mibData<EOL>del parsedMibs[mibname]<EOL>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % (mibname, fileInfo.path, self._writer))<EOL><DEDENT>except error.PySmiError:<EOL><INDENT>exc_class, exc, tb = sys.exc_info()<EOL>exc.handler = self._codegen<EOL>exc.mibname = mibname<EOL>exc.msg += '<STR_LIT>' % mibname<EOL>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % (self._codegen, exc))<EOL>processed[mibname] = statusFailed.setOptions(error=exc)<EOL>failedMibs[mibname] = exc<EOL>del parsedMibs[mibname]<EOL><DEDENT><DEDENT>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % (len(parsedMibs), len(failedMibs)))<EOL>for mibname in failedMibs.copy():<EOL><INDENT>if options.get('<STR_LIT>') and mibname not in canonicalMibNames:<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % mibname)<EOL>continue<EOL><DEDENT>for borrower in self._borrowers:<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % (mibname, borrower))<EOL>try:<EOL><INDENT>fileInfo, fileData = borrower.getData(<EOL>mibname,<EOL>genTexts=options.get('<STR_LIT>')<EOL>)<EOL>borrowedMibs[mibname] = fileInfo, MibInfo(name=mibname, imported=[]), fileData<EOL>del failedMibs[mibname]<EOL>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % (mibname, borrower))<EOL>break<EOL><DEDENT>except error.PySmiError:<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % (borrower, sys.exc_info()[<NUM_LIT:1>]))<EOL><DEDENT><DEDENT><DEDENT>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % (len(borrowedMibs), len(failedMibs)))<EOL>for mibname in borrowedMibs.copy():<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % mibname)<EOL>fileInfo, mibInfo, mibData = borrowedMibs[mibname]<EOL>for searcher in self._searchers:<EOL><INDENT>try:<EOL><INDENT>searcher.fileExists(mibname, fileInfo.mtime, rebuild=options.get('<STR_LIT>'))<EOL><DEDENT>except error.PySmiFileNotFoundError:<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % (mibname, searcher))<EOL>continue<EOL><DEDENT>except error.PySmiFileNotModifiedError:<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % (mibname, searcher))<EOL>del borrowedMibs[mibname]<EOL>processed[mibname] = statusUntouched<EOL>break<EOL><DEDENT>except error.PySmiError:<EOL><INDENT>exc_class, exc, tb = sys.exc_info()<EOL>exc.searcher = searcher<EOL>exc.mibname = mibname<EOL>exc.msg += '<STR_LIT>' % mibname<EOL>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % (searcher, exc))<EOL>continue<EOL><DEDENT><DEDENT>else:<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % mibname)<EOL>if options.get('<STR_LIT>') and mibname not in canonicalMibNames:<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % mibname)<EOL>processed[mibname] = statusUntouched<EOL><DEDENT>else:<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % mibname)<EOL>builtMibs[mibname] = borrowedMibs[mibname]<EOL>processed[mibname] = statusBorrowed.setOptions(<EOL>path=fileInfo.path, file=fileInfo.file,<EOL>alias=fileInfo.name<EOL>)<EOL><DEDENT>del borrowedMibs[mibname]<EOL><DEDENT><DEDENT>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % (len(builtMibs), len(failedMibs)))<EOL>if failedMibs and not options.get('<STR_LIT>'):<EOL><INDENT>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % '<STR_LIT:U+002CU+0020>'.join(failedMibs))<EOL>for mibname in builtMibs:<EOL><INDENT>processed[mibname] = statusUnprocessed<EOL><DEDENT>return processed<EOL><DEDENT>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % ('<STR_LIT:U+002CU+0020>'.join(builtMibs), '<STR_LIT:U+002CU+0020>'.join(failedMibs)))<EOL>for mibname in builtMibs.copy():<EOL><INDENT>fileInfo, mibInfo, mibData = builtMibs[mibname]<EOL>try:<EOL><INDENT>if options.get('<STR_LIT>', True):<EOL><INDENT>self._writer.putData(<EOL>mibname, mibData, dryRun=options.get('<STR_LIT>')<EOL>)<EOL><DEDENT>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % (mibname, self._writer))<EOL>del builtMibs[mibname]<EOL>if mibname not in processed:<EOL><INDENT>processed[mibname] = statusCompiled.setOptions(<EOL>path=fileInfo.path,<EOL>file=fileInfo.file,<EOL>alias=fileInfo.name,<EOL>oid=mibInfo.oid,<EOL>oids=mibInfo.oids,<EOL>identity=mibInfo.identity,<EOL>revision=mibInfo.revision,<EOL>enterprise=mibInfo.enterprise,<EOL>compliance=mibInfo.compliance,<EOL>)<EOL><DEDENT><DEDENT>except error.PySmiError:<EOL><INDENT>exc_class, exc, tb = sys.exc_info()<EOL>exc.handler = self._codegen<EOL>exc.mibname = mibname<EOL>exc.msg += '<STR_LIT>' % mibname<EOL>debug.logger & debug.flagCompiler and debug.logger('<STR_LIT>' % (exc, self._writer))<EOL>processed[mibname] = statusFailed.setOptions(error=exc)<EOL>failedMibs[mibname] = exc<EOL>del builtMibs[mibname]<EOL><DEDENT><DEDENT>debug.logger & debug.flagCompiler and debug.logger(<EOL>'<STR_LIT>' % '<STR_LIT:U+002CU+0020>'.join([x for x in processed if processed[x] in ('<STR_LIT>', '<STR_LIT>')]))<EOL>return processed<EOL>
Transform requested and possibly referred MIBs.

        The *compile* method should be invoked when *MibCompiler* object
        is operational meaning at least *sources* are specified.

        Once called with a MIB module name, *compile* will:

        * fetch ASN.1 MIB module with given name by calling *sources*
        * make sure no such transformed MIB already exists (with *searchers*)
        * parse ASN.1 MIB text with *parser*
        * perform actual MIB transformation into target format with *code generator*
        * may attempt to borrow pre-transformed MIB through *borrowers*
        * write transformed MIB through *writer*

        The above sequence will be performed for each MIB name given in
        *mibnames* and may be performed for all MIBs referred to from
        MIBs being processed.

        Args:
            mibnames: list of ASN.1 MIBs names
            options: options that affect the way PySMI components work

        Returns:
            A dictionary of MIB module names processed (keys) and *MibStatus*
            class instances (values)