text:
/**
 * An object for executing Python code and passing the results along to interested components.
 *
 * @constructor
 * @this {BlockPyEditor}
 * @param {Object} main - The main BlockPy instance
 * @param {HTMLElement} tag - The HTML object this is attached to.
 */

document.write("");

var PyEngine = function(programStatus, mixpyProject) {
    this.loadEngine();
	this.programStatus = programStatus;
	this.mixpyProject = mixpyProject;
}

/**
 * Definable function to be run when execution has fully ended,
 * whether it succeeds or fails.
 *
 */
PyEngine.prototype.onExecutionEnd = null;

/**
 * Helper function that will attempt to call the defined onExecutionEnd,
 * but will do nothing if there is no function defined.
 */
PyEngine.prototype.executionEnd_ = function() {
    if (this.onExecutionEnd !== null) {
        this.onExecutionEnd();
    }
};

/**
 * Initializes the Python Execution engine and the Printer (console).
 */
PyEngine.prototype.loadEngine = function() {
    var engine = this;
    // No connected services
    Sk.connectedServices = {}
	// No time limit
	//Sk.execLimit = null;

    // Ensure version 3, so we get proper print handling
    Sk.python3 = true;

    Sk.TurtleGraphics = {'target': 'output_img',
		                  'width': $('#output_img').width() - 50,
						'height': $('#output_img').height() - 50};//turtle

	Sk.canvas = 'output_img';
	// TODO
    //Sk.console = printer.getConfiguration();
    // Definitely use a prompt
    Sk.inputfunTakesPrompt = true;

    // Keeps track of the tracing while the program is executing; destroyed afterwards.
    this.executionBuffer = {};
}

/**
 * Used to access Skulpt built-ins. This is pretty generic, taken
 * almost directly from the Skulpt docs.
 *
 * @param {String} filename - The python filename (e.g., "os" or "pprint") that will be loaded.
 * @returns {String} The JavaScript source code of the file (weird, right?)
 * @throws Will throw an error if the file isn't found.
 */
PyEngine.prototype.readFile = function(filename) {
	var newFilename = filename.substring(2); //eg:./mymodule.py --> mymodule.py
	if(this.mixpyProject.exist(newFilename)){
		return this.mixpyProject.getFileContent(newFilename);
	}
    if (Sk.builtinFiles === undefined ||
        Sk.builtinFiles["files"][filename] === undefined) {
        throw "File not found: '" + filename + "'";
    }
    return Sk.builtinFiles["files"][filename];
}

PyEngine.prototype.fileread = function(filename, mode) {
	if(this.mixpyProject.exist(filename)){
    	return this.mixpyProject.getFileContent(filename);
	}else{
		if(mode.indexOf('w') !== -1){
			this.mixpyProject.add(filename, '', 1);
			return '';
		}else
			return null;
	}
}

PyEngine.prototype.filewrite = function(fileItem, str) {
	var filename = fileItem.name;
	this.mixpyProject.modify(filename, str);
	this.mixpyProject.select(filename);
}

PyEngine.prototype.skInput = function(prompt) {

	return new Promise((resolve, reject) => {
		var currText =  $("#side_code").text();
		var $textareaE= $('<textarea/>').addClass("inputMsg").val(currText + prompt);
		$textareaE.height($("#side_code").height());
		$("#side_code").text("");
		$("#side_code").append($textareaE);
		//$textareaE.focus();
		$textareaE.putCursorAtEnd();
		$textareaE.on('change keyup', function(){
			var allText = $textareaE.val();
			if(allText[allText.length - 1] === "\n"){
				resolve(allText.substring(currText.length + prompt.length, allText.length - 1));
			}
		});
	});
}

/**
 * Resets the state of the execution engine, including reinitailizing
 * the execution buffer (trace, step, etc.), reseting the printer, and
 * hiding the trace button.
 *
 */
PyEngine.prototype.reset = function() {
	Sk.execLimit = Number.POSITIVE_INFINITY;
	$("#side_code").text('');
	var $output_img = $("#output_img");
	$output_img.text('');
	document.getElementById('output_img').style.width = $output_img.width() + "px";
}

PyEngine.prototype.kill = function() {
	Sk.execLimit = 0;
    $("#loading").css('display', "none");
}

/**
 * "Steps" the execution of the code, meant to be used as a callback to the Skulpt
 * environment.
 *
 * @param {Object} variables - Hash that maps the names of variables (Strings) to their Skulpt representation.
 * @param {Number} lineNumber - The corresponding line number in the source code that is being executed.
 * @param {Number} columnNumber - The corresponding column number in the source code that is being executed. Think of it as the "X" position to the lineNumber's "Y" position.
 * @param {String} filename - The name of the python file being executed (e.g., "__main__.py").
 * @param {String} astType - Unused? TODO: What is this?
 * @param {String} ast - String-encoded JSON representation of the AST node associated with this element.
 */
PyEngine.prototype.step = function(variables, lineNumber,
                                       columnNumber, filename, astType, ast) {
    if (filename == '<stdin>.py') {
        var currentStep = this.executionBuffer.step;
        var globals = this.parseGlobals(variables);
        this.executionBuffer.trace.push(
            {'step': currentStep,
             'filename': filename,
             //'block': highlightMap[lineNumber-1],
             'line': lineNumber,
             'column': columnNumber,
             'properties': globals.properties,
             'modules': globals.modules});
        this.executionBuffer.step = currentStep+1;
        this.executionBuffer.last_step = currentStep+1;
        this.executionBuffer.line_number = lineNumber;
    }
}

/**
 * Runs the AbstractInterpreter to get some static information about the code,
 * in particular the variables' types. This is needed for type checking.
 *
 * @returns {Object<String, AIType>} Maps variable names (as Strings) to types as constructed by the AbstractIntepreter.
 */
PyEngine.prototype.analyzeVariables = function() {
    // Get the code
    var code = this.main.model.programs['__main__']();
    if (code.trim() == "") {
        return {};
    }

    var analyzer = new AbstractInterpreter(code);
    report = analyzer.report;
    return analyzer.variableTypes;
}

/**
 * Runs the AbstractInterpreter to get some static information about the code,
 * including potential semantic errors. It then parses that information to give
 * feedback.
 *
 * @returns {Boolean} Whether the code was successfully analyzed.
 */
PyEngine.prototype.analyze = function() {
    this.main.model.execution.status("analyzing");

    var feedback = this.main.components.feedback;

    // Get the code
    var code = this.main.model.programs['__main__']();
    if (code.trim() == "") {
        this.main.components.feedback.emptyProgram("You haven't written any code yet!");
        //this.main.model.feedback.status("semantic");
        return false;
    }

    var analyzer = new AbstractInterpreter(code);
    this.main.model.execution.ast = analyzer.ast;

    report = analyzer.report;
    // Syntax error
    if (report.error !== false) {
        console.log(report.error.args.v)
        var codeLine = '.';
        if (report.error.args.v.length > 3) {
            codeLine = ', where it says:
'+report.error.args.v[3][2]+'';
        }
        this.main.reportError('editor', report.error, "While attempting to process your Python code, I found a syntax error. In other words, your Python code has a mistake in it (e.g., mispelled a keyword, bad indentation, unnecessary symbol). You should check to make sure that you have written all of your code correctly. To me, it looks like the problem is on line "+ report.error.args.v[2]+codeLine, report.error.args.v[2]);
        return false;
    }

    if (report["Unconnected blocks"].length >= 1) {
        var variable = report['Unconnected blocks'][0];
        feedback.semanticError("Unconnected blocks", "It looks like you have unconnected blocks on line "+variable.position.line+". Before you run your program, you must make sure that all of your blocks are connected and that there are no unfilled holes.", variable.position.line)
        return false;
    } else if (report['Iteration variable is iteration list'].length >= 1) {
        var variable = report['Iteration variable is iteration list'][0];
        feedback.semanticError("Iteration Problem", "The property "+variable.name+" was iterated on line "+variable.position.line+", but you used the same variable as the iteration variable. You should choose a different variable name for the iteration variable. Usually, the iteration variable is the singular form of the iteration list (e.g., for dog in dogs:).", variable.position.line)
        return false;
    } else if (report["Undefined variables"].length >= 1) {
        var variable = report["Undefined variables"][0];
        feedback.semanticError("Initialization Problem", "The property "+variable.name+" was read on line "+variable.position.line+", but it was not given a value on a previous line. You cannot use a property until it has been initialized.", variable.position.line)
        return false;
    } else if (report["Possibly undefined variables"].length >= 1) {
        var variable = report["Possibly undefined variables"][0];
        feedback.semanticError("Initialization Problem", "The property "+variable.name+" was read on line "+variable.position.line+", but it was possibly not given a value on a previous line. You cannot use a property until it has been initialized. Check to make sure that this variable was declared in all of the branches of your decision.", variable.position.line);
        return false;
    } else if (report["Unread variables"].length >= 1) {
        var variable = report["Unread variables"][0];
        feedback.semanticError("Unused Property", "The property "+variable.name+" was set, but was never used after that.", null)
        return false;
    } else if (report["Overwritten variables"].length >= 1) {
        var variable = report["Overwritten variables"][0];
        feedback.semanticError("Overwritten Property", "The property "+variable.name+" was set, but before it could be read it was changed on line "+variable.position.line+". It is unnecessary to change an existing variable's value without reading it first.", variable.position.line)
        return false;
    } else if (report["Empty iterations"].length >= 1) {
        var variable = report["Empty iterations"][0];
        feedback.semanticError("Iterating over empty list", "The property "+variable.name+" was set as an empty list, and then you attempted to iterate over it on "+variable.position.line+". You should only iterate over non-empty lists.", variable.position.line)
        return false;
    } else if (report["Non-list iterations"].length >= 1) {
        var variable = report["Non-list iterations"][0];
        feedback.semanticError("Iterating over non-list", "The property "+variable.name+" is not a list, but you attempted to iterate over it on "+variable.position.line+". You should only iterate over non-empty lists.", variable.position.line)
        return false;
    } else if (report["Incompatible types"].length >= 1) {
        var variable = report["Incompatible types"][0];
        feedback.semanticError("Incompatible types", "You attempted to "+variable.operation+" a "+variable.left.type+" and a "+variable.right.type+" on line "+variable.position.line+". But you can't do that with that operator. Make sure both sides of the operator are the right type.", variable.position.line)
        return false;
    }

    return true;
}

var GLOBAL_VALUE;

/**
 * Runs the given python code, resetting the console and Trace Table.
 */
PyEngine.prototype.run = function() {
    document.getElementById("matplot_img").src=""
    document.getElementById("output_img").style.height='100%'
    document.getElementById("mat_div").style.height='0%'
    $("#loading").css('display', "inline-block");

	if(sidecodeDisplay === false){
		sidecodeClick();
	}
    // Reset everything
    this.reset();
	this.loadEngine();
	// Major Skulpt configurations
    Sk.configure({
        // Function to handle the text outputted by Skulpt
        output: function(lineText){
			if($('.inputMsg').length > 0)
				$('#side_code').text($('#side_code').text() + $('.inputMsg').val() + lineText);
			else
				$('#side_code').text($('#side_code').text()  + lineText);
		},
        // Function to handle loading in new files
        read: this.readFile.bind(this),
		inputfun:this.skInput.bind(this),
		inputfunTakesPrompt: true,
		execLimit:Number.POSITIVE_INFINITY,
        fileread:this.fileread.bind(this),
        filewrite:this.filewrite.bind(this)
    });

    Sk.builtins.value = new Sk.builtin.func(function() {
        return Sk.ffi.remapToPy(GLOBAL_VALUE === undefined ? 5 : GLOBAL_VALUE);
    });
    Sk.builtins.set_value = new Sk.builtin.func(function(v) {
        GLOBAL_VALUE = v.v;
    });

    // Get the code
    var code = "";
    if(document.getElementById('tab_arduino').className == 'tabon'){
        //code = document.getElementById('content_arduino').value;

        code = editor.getValue();
    }else{
        code = Blockly.Python.workspaceToCode(Blockly.mainWorkspace) || '';//code
    }

    var pack_num = 0;
    var pack_list = ["numpy","pandas","scikit-learn","matplotlib","sklearn"];
    var code_pack_list = [];
    for (var i = 0; i < pack_list.length; i++) {
        if ((code.indexOf("import "+pack_list[i])!=-1)||(code.indexOf("from "+pack_list[i]+" import")!=-1)){
            pack_num++;
            code_pack_list.push(pack_list[i])
        }
    }
    if (pack_num==0){//代码处理
    var engine = this;
    if(code === "") {
        engine.programStatus['running'] = false;
        $("#loading").css('display', "none");
        return;
    }
    // Actually run the python code
    var executionPromise = Sk.misceval.asyncToPromise(function() {
        return Sk.importMainWithBody("<stdin>", false, code, true);
    });

    executionPromise.then(
        function (module) {
			engine.programStatus['running'] = false;
            $("#loading").css('display', "none");
            // Run the afterSingleExecution one extra time for final state
            /*Sk.afterSingleExecution(module.$d, -1, 0, "<stdin>.py");
            engine.check(code, execution.trace(), execution.output(), execution.ast, module.$d);
            engine.executionEnd_();
			*/
        },
        function(error) {
			engine.programStatus['running'] = false;
			$("#loading").css('display', "none");
    		var original = prettyPrintError(error);
			//hack for kill program with time limiterror
			if(original.indexOf("TimeLimitError") !== -1)
				return;
			if($('.inputMsg').length > 0)
				$('#side_code').text($('#side_code').text() + $('.inputMsg').val())

			var $errorE = $('').addClass('errorMsg').html(original);
			$("#side_code").append($errorE)
			var matchRet = /on line (\d+)/.exec(original);
			var lineNumber = -1;
			if(matchRet !== null && matchRet.length == 2){
				lineNumber = parseInt(matchRet[1]) - 1;
				editor.session.addMarker(new EditorRange(lineNumber, 0, lineNumber, 1), "errorMarker", "fullLine");
				editor.hasMarker = true;
			}

        }
    );
    }
    else{
        var reg1=/print\(.+\)\n/g
        if (code.search(reg1)!=-1){
        var print_code=code.match(reg1).toString()
        print_code=print_code.slice(6,-2)+'\n'
        code=code.replace(reg1,print_code)
        }
        languagePluginLoader.then(() => {
        pyodide.loadPackage(code_pack_list).then(() => {
        if (code.indexOf("matplotlib.pyplot.show()") != -1){
        code+=`\nimport io, base64\nbuf = io.BytesIO()\nmatplotlib.pyplot.savefig(buf, format='png')\nmatplotlib.pyplot.clf()\nbuf.seek(0)\nimg_str = 'data:image/png;base64,' + base64.b64encode(buf.read()).decode('UTF-8')\n`

        var code_result = pyodide.runPython(code);
        document.getElementById("mat_div").style.height='100%'
        document.getElementById("output_img").style.height='0%'
        document.getElementById("matplot_img").src = pyodide.globals.img_str;

    }else{
        var code_result = pyodide.runPython(code);
    }
        if(code_result!=undefined){
        document.getElementById("side_code").innerText = code_result;
        }
        $("#loading").css('display', "none");

      });});
    }
}

/**
 * Indents the given string by 4 spaces. This correctly handles multi-line strings.
 *
 * @param {String} str - The string to be manipulated.
 * @returns {String} The string with four spaces added at the start of every new line.
 */
function indent(str) {
  return str.replace(/^(?=.)/gm, '    ');
}

function prettyPrintError (error) {
    if (typeof error === "string") {
        return error;
    } else {
        // A weird skulpt thing?
        if (error.tp$str !== undefined) {
            return error.tp$str().v;
        } else {
            return ""+error.name + ": " + error.message;
        }
    }
}

/**
 * Skulpt Module for holding the Instructor API.
 *
 * This module is a little hackish. We need to sit down and reevaluate the best way to
 * organize it and whether this particular structure is ideal. I suspect it should be
 * it's own proper JS file.
 *
 * @param {String} name - The name of the module (should always be 'instructor')
 *
 */
var instructor_module = function(name) {
    // Main module object that gets returned at the end.
    var mod = {};

    /**
     * Skulpt Exception that represents a Feedback object, to be rendered to the user
     * when the feedback system finds a problem.
     *
     * @param {Array} args - A list of optional arguments to pass to the Exception.
     *                       Usually this will include a message for the user.
     */
    Sk.builtin.Feedback = function (args) {
        var o;
        if (!(this instanceof Sk.builtin.Feedback)) {
            o = Object.create(Sk.builtin.Feedback.prototype);
            o.constructor.apply(o, arguments);
            return o;
        }
        Sk.builtin.Exception.apply(this, arguments);
    };
    Sk.abstr.setUpInheritance("Feedback", Sk.builtin.Feedback, Sk.builtin.Exception);

    /**
     * Skulpt Exception that represents a Success object, to be thrown when the user
     * completes their program successfully.
     *
     ** @param {Array} args - A list of optional arguments to pass to the Exception.
     *                       Usually this will be empty.
     */
    Sk.builtin.Success = function (args) {
        var o;
        if (!(this instanceof Sk.builtin.Success)) {
            o = Object.create(Sk.builtin.Success.prototype);
            o.constructor.apply(o, arguments);
            return o;
        }
        Sk.builtin.Exception.apply(this, arguments);
    };
    Sk.abstr.setUpInheritance("Success", Sk.builtin.Success, Sk.builtin.Exception);

    /**
     * Skulpt Exception that represents a Finished object, to be thrown when the user
     * completes their program successfully, but isn't in a problem with a "solution".
     * This is useful for open-ended canvases where we still want to capture the students'
     * code in Canvas.
     *
     ** @param {Array} args - A list of optional arguments to pass to the Exception.
     *                       Usually this will be empty.
     */
    Sk.builtin.Finished = function (args) {
        var o;
        if (!(this instanceof Sk.builtin.Finished)) {
            o = Object.create(Sk.builtin.Finished.prototype);
            o.constructor.apply(o, arguments);
            return o;
        }
        Sk.builtin.Exception.apply(this, arguments);
    };
    Sk.abstr.setUpInheritance("Finished", Sk.builtin.Finished, Sk.builtin.Exception);

    /**
     * A Skulpt function that throws a Feedback exception, allowing us to give feedback
     * to the user through the Feedback panel. This function call is done for aesthetic
     * reasons, so that we are calling a function instead of raising an error. Still,
     * exceptions allow us to break out of the control flow immediately, like a
     * return, so they are a good mechanism to use under the hood.
     *
     * @param {String} message - The message to display to the user.
     */
    mod.set_feedback = new Sk.builtin.func(function(message) {
        Sk.builtin.pyCheckArgs("set_feedback", arguments, 1, 1);
        Sk.builtin.pyCheckType("message", "string", Sk.builtin.checkString(message));
        throw new Sk.builtin.Feedback(message.v);
    });

    /**
     * A Skulpt function that throws a Success exception. This will terminate the
     * feedback analysis, but reports that the students' code was successful.
     * This function call is done for aesthetic reasons, so that we are calling a
     * function instead of raising an error. Still, exceptions allow us to break
     * out of the control flow immediately, like a return would, so they are a
     * good mechanism to use under the hood.
     */
    mod.set_success = new Sk.builtin.func(function() {
        Sk.builtin.pyCheckArgs("set_success", arguments, 0, 0);
        throw new Sk.builtin.Success();
    });

    /**
     * A Skulpt function that throws a Finished exception. This will terminate the
     * feedback analysis, but reports that the students' code was successful.
     * This function call is done for aesthetic reasons, so that we are calling a
     * function instead of raising an error. Still, exceptions allow us to break
     * out of the control flow immediately, like a return would, so they are a
     * good mechanism to use under the hood.
     */
    mod.set_finished = new Sk.builtin.func(function() {
        Sk.builtin.pyCheckArgs("set_finished", arguments, 0, 0);
        throw new Sk.builtin.Finished();
    });

    // Memoization of previous parses - some mild redundancy to save time
    // TODO: There's no evidence this is good, and could be a memory hog on big
    // programs. Someone should investigate this. The assumption is that multiple
    // helper functions might be using parses. But shouldn't we trim old parses?
    // Perhaps a timed cache would work better.
    var parses = {};

    /**
     * Given source code as a string, return a flat list of all of the AST elements
     * in the parsed source code.
     *
     * TODO: There's redundancy here, since the source code was previously parsed
     * to run the file and to execute it. We should probably be able to do this just
     * once and shave off time.
     *
     * @param {String} source - Python source code.
     * @returns {Array.<Object>}
     */
    function getParseList(source) {
        if (!(source in parses)) {
            var parse = Sk.parse("__main__", source);
            parses[source] = Sk.astFromParse(parse.cst, "__main__", parse.flags);
        }
        var ast = parses[source];
        return (new NodeVisitor()).recursive_walk(ast);
    }

    /**
     * Given source code as a string, return a list of all of the AST elements
     * that are Num (aka numeric literals) but that are not inside List elements.
     *
     * @param {String} source - Python source code.
     * @returns {Array.number} The list of JavaScript numeric literals that were found.
     */
    function getNonListNums(source) {
        if (!(source in parses)) {
            var parse = Sk.parse("__main__", source);
            parses[source] = Sk.astFromParse(parse.cst, "__main__", parse.flags);
        }
        var ast = parses[source];
        var visitor = new NodeVisitor();
        var insideList = false;
        var nums = [];
        visitor.visit_List = function(node) {
            insideList = true;
            this.generic_visit(node);
            insideList = false;
        }
        visitor.visit_Num = function(node) {
            if (!insideList) {
                nums.push(node.n);
            }
            this.generic_visit(node);
        }
        visitor.visit(ast);
        return nums;
    }

    /**
     * Given source code as a string, return a list of all of the AST elements
     * that are being printed (using the print function) but are not variables.
     *
     * @param {String} source - Python source code.
     * @returns {Array.<Object>} The list of AST elements that were found.
     */
    function getPrintedNonProperties(source) {
        if (!(source in parses)) {
            var parse = Sk.parse("__main__", source);
            parses[source] = Sk.astFromParse(parse.cst, "__main__", parse.flags);
        }
        var ast = parses[source];
        var visitor = new NodeVisitor();
        var nonVariables = [];
        visitor.visit_Call = function(node) {
            var func = node.func;
            var args = node.args;
            if (func._astname == 'Name' && func.id.v == 'print') {
                for (var i =0; i < args.length; i+= 1) {
                    if (args[i]._astname != "Name") {
                        nonVariables.push(args[i]);
                    }
                }
            }
            this.generic_visit(node);
        }
        visitor.visit(ast);
        return nonVariables;
    }

    /**
     * Skulpt function to iterate through the final state of
     * all the variables in the program, and check to see if they have
     * a given value.
     */
    mod.get_value_by_name = new Sk.builtin.func(function(name) {
        Sk.builtin.pyCheckArgs("get_value_by_name", arguments, 1, 1);
        Sk.builtin.pyCheckType("name", "string", Sk.builtin.checkString(name));
        name = name.v;
        var final_values = Sk.builtins._final_values;
        if (name in final_values) {
            return final_values[name];
        } else {
            return Sk.builtin.none.none$;
        }
    });
    mod.get_value_by_type = new Sk.builtin.func(function(type) {
        Sk.builtin.pyCheckArgs("get_value_by_type", arguments, 1, 1);

        var final_values = Sk.builtins._final_values;
        var result = [];
        for (var property in final_values) {
            if (final_values[property].tp$name == type.tp$name) {
                result.push(final_values[property]);
            }
        }
        return Sk.builtin.list(result);
    });

    mod.parse_json = new Sk.builtin.func(function(blob) {
        Sk.builtin.pyCheckArgs("parse_json", arguments, 1, 1);
        Sk.builtin.pyCheckType("blob", "string", Sk.builtin.checkString(blob));
        blob = blob.v;
        return Sk.ffi.remapToPy(JSON.parse(blob));
    });
    mod.get_property = new Sk.builtin.func(function(name) {
        Sk.builtin.pyCheckArgs("get_property", arguments, 1, 1);
        Sk.builtin.pyCheckType("name", "string", Sk.builtin.checkString(name));
        name = name.v;
        var trace = Sk.builtins._trace;
        if (trace.length <= 0) {
            return Sk.builtin.none.none$;
        }
        var properties = trace[trace.length-1]["properties"];
        for (var i = 0, len = properties.length; i < len; i += 1) {
            if (properties[i]['name'] == name) {
                return Sk.ffi.remapToPy(properties[i])
            }
        }
        return Sk.builtin.none.none$;
    });

    mod.calls_function = new Sk.builtin.func(function(source, name) {
        Sk.builtin.pyCheckArgs("calls_function", arguments, 2, 2);
        Sk.builtin.pyCheckType("source", "string", Sk.builtin.checkString(source));
        Sk.builtin.pyCheckType("name", "string", Sk.builtin.checkString(name));

        source = source.v;
        name = name.v;

        var ast_list = getParseList(source);

        var count = 0;
        for (var i = 0, len = ast_list.length; i < len; i = i+1) {
            if (ast_list[i]._astname == 'Call') {
                if (ast_list[i].func._astname == 'Attribute') {
                    count += Sk.ffi.remapToJs(ast_list[i].func.attr) == name | 0;
                } else if (ast_list[i].func._astname == 'Name') {
                    count += Sk.ffi.remapToJs(ast_list[i].func.id) == name | 0;
                }
            }
        }

        return Sk.ffi.remapToPy(count > 0);
    });

    mod.count_components = new Sk.builtin.func(function(source, component) {
        Sk.builtin.pyCheckArgs("count_components", arguments, 2, 2);
        Sk.builtin.pyCheckType("source", "string", Sk.builtin.checkString(source));
        Sk.builtin.pyCheckType("component", "string", Sk.builtin.checkString(component));

        source = source.v;
        component = component.v;

        var ast_list = getParseList(source);

        var count = 0;
        for (var i = 0, len = ast_list.length; i < len; i = i+1) {
            if (ast_list[i]._astname == component) {
                count = count+1;
            }
        }

        return Sk.ffi.remapToPy(count);
    });

    mod.no_nonlist_nums = new Sk.builtin.func(function(source) {
        Sk.builtin.pyCheckArgs("no_nonlist_nums", arguments, 1, 1);
        Sk.builtin.pyCheckType("source", "string", Sk.builtin.checkString(source));

        source = source.v;

        var num_list = getNonListNums(source);

        var count = 0;
        for (var i = 0, len = num_list.length; i < len; i = i+1) {
            if (num_list[i].v != 0 && num_list[i].v != 1) {
                return Sk.ffi.remapToPy(true);
            }
        }
        return Sk.ffi.remapToPy(false);
    });
    mod.only_printing_properties = new Sk.builtin.func(function(source) {
        Sk.builtin.pyCheckArgs("only_printing_properties", arguments, 1, 1);
        Sk.builtin.pyCheckType("source", "string", Sk.builtin.checkString(source));

        source = source.v;

        var non_var_list = getPrintedNonProperties(source);
        return Sk.ffi.remapToPy(non_var_list.length == 0);
    });

    return mod;
}

PyEngine.prototype.setupEnvironment = function(student_code, traceTable, output, ast, final_values) {
    var model = this.main.model;
    this._backup_execution = Sk.afterSingleExecution;
    Sk.afterSingleExecution = undefined;
    Sk.builtins.get_output = new Sk.builtin.func(function() {
        Sk.builtin.pyCheckArgs("get_output", arguments, 0, 0);
        return Sk.ffi.remapToPy(model.execution.output());
    });
    Sk.builtins.reset_output = new Sk.builtin.func(function() {
        Sk.builtin.pyCheckArgs("reset_output", arguments, 0, 0);
        model.execution.output.removeAll();
    });
    Sk.builtins.log = new Sk.builtin.func(function(data) {
        Sk.builtin.pyCheckArgs("log", arguments, 1, 1);
        console.log(data)
    });
    //Sk.builtins.trace = Sk.ffi.remapToPy(traceTable);
    Sk.builtins._trace = traceTable;
    Sk.builtins._final_values = final_values;
    Sk.builtins.code = Sk.ffi.remapToPy(student_code);
    Sk.builtins.set_success = this.instructor_module.set_success;
    Sk.builtins.set_feedback = this.instructor_module.set_feedback;
    Sk.builtins.set_finished = this.instructor_module.set_finished;
    Sk.builtins.count_components = this.instructor_module.count_components;
    Sk.builtins.no_nonlist_nums = this.instructor_module.no_nonlist_nums;
    Sk.builtins.only_printing_properties = this.instructor_module.only_printing_properties;
    Sk.builtins.calls_function = this.instructor_module.calls_function;
    Sk.builtins.get_property = this.instructor_module.get_property;
    Sk.builtins.get_value_by_name = this.instructor_module.get_value_by_name;
    Sk.builtins.get_value_by_type = this.instructor_module.get_value_by_type;
    Sk.builtins.parse_json = this.instructor_module.parse_json;
    Sk.skip_drawing = true;
    model.settings.mute_printer(true);
}

PyEngine.prototype.disposeEnvironment = function() {
    Sk.afterSingleExecution = this._backup_execution;
    Sk.builtins.get_output = undefined;
    Sk.builtins.reset_output = undefined;
    Sk.builtins.log = undefined;
    Sk.builtins._trace = undefined;
    Sk.builtins.trace = undefined;
    Sk.builtins.code = undefined;
    Sk.builtins.set_success = undefined;
    Sk.builtins.set_feedback = undefined;
    Sk.builtins.set_finished = undefined;
    Sk.builtins.count_components = undefined;
    Sk.builtins.calls_function = undefined;
    Sk.builtins.get_property = undefined;
    Sk.builtins.get_value_by_name = undefined;
    Sk.builtins.get_value_by_type = undefined;
    Sk.builtins.no_nonlist_nums = undefined;
    Sk.builtins.only_printing_properties = undefined;
    Sk.builtins.parse_json = undefined;
    Sk.skip_drawing = false;
    GLOBAL_VALUE = undefined;
    this.main.model.settings.mute_printer(false);
}

PyEngine.prototype.check = function(student_code, traceTable, output, ast, final_values) {
    var engine = this;
    var model = this.main.model;
    var on_run = model.programs['give_feedback']();
    if (on_run !== undefined && on_run.trim() !== "") {
        on_run = 'def run_code():\n'+indent(student_code)+'\n'+on_run;
        this.setupEnvironment(student_code, traceTable, output, ast, final_values);

        var executionPromise = Sk.misceval.asyncToPromise(function() {
            return Sk.importMainWithBody("<stdin>", false, on_run, true);
        });
        executionPromise.then(
            function (module) {
                engine.main.components.feedback.noErrors();
                engine.disposeEnvironment();
            }, function (error) {
                engine.disposeEnvironment();
                console.log(error.tp$name, error.tp$name == "Success");
                if (error.tp$name == "Success") {
                    server.markSuccess(1.0);
                    engine.main.components.feedback.complete();
                } else if (error.tp$name == "Feedback") {
                    server.markSuccess(0.0);
                    engine.main.components.feedback.instructorFeedback("Incorrect Answer", error.args.v[0].v);
                } else if (error.tp$name == "Finished") {
                    server.markSuccess(1.0);
                    engine.main.components.feedback.finished();
                } else {
                    console.error(error);
                    engine.main.components.feedback.internalError(error, "Feedback Error", "Error in instructor's feedback. Please show the above message to an instructor!");
                    server.logEvent('blockly_instructor_error', ''+error);
                }
            });
    }
}

PyEngine.prototype.parseGlobals = function(variables) {
    var result = Array();
    var modules = Array();
    for (var property in variables) {
        var value = variables[property];
        if (property !== "__name__" && property !== "__doc__") {
            property = property.replace('_$rw$', '')
                               .replace('_$rn$', '');
            var parsed = this.parseValue(property, value);
            if (parsed !== null) {
                result.push(parsed);
            } else if (value.constructor == Sk.builtin.module) {
                modules.push(value.$d.__name__.v);
            }
        }
    }
    return {"properties": result, "modules": modules};
}

PyEngine.prototype.parseValue = function(property, value) {
    if (value == undefined) {
        return {'name': property,
                'type': 'Unknown',
                "value": 'Undefined'
                };
    }
    switch (value.constructor) {
        case Sk.builtin.func:
            return {'name': property,
                    'type': "Function",
                    "value":
                        (value.func_code.co_varnames !== undefined ?
                         " Arguments: "+value.func_code.co_varnames.join(", ") :
                         ' No arguments')
                    };
        case Sk.builtin.module: return null;
        case Sk.builtin.str:
            return {'name': property,
                'type': "String",
                "value": value.$r().v
            };
        case Sk.builtin.none:
            return {'name': property,
                'type': "None",
                "value": "None"
            };
        case Sk.builtin.bool:
            return {'name': property,
                'type': "Boolean",
                "value": value.$r().v
            };
        case Sk.builtin.nmber:
            return {'name': property,
                'type': "int" == value.skType ? "Integer": "Float",
                "value": value.$r().v
            };
        case Sk.builtin.int_:
            return {'name': property,
                'type': "Integer",
                "value": value.$r().v
            };
        case Sk.builtin.float_:
            return {'name': property,
                'type': "Float",
                "value": value.$r().v
            };
        case Sk.builtin.tuple:
            return {'name': property,
                'type': "Tuple",
                "value": value.$r().v
            };
        case Sk.builtin.list:
            if (value.v.length <= 20) {
                return {'name': property,
                    'type': "List",
                    "value": value.$r().v,
                    'exact_value': value
                };
            } else {
                return {'name': property,
                    'type': "List",
                    "value": "[... "+value.v.length+" elements ...]",
                    "exact_value": value
                };
            }
        case Sk.builtin.dict:
            return {'name': property,
                'type': "Dictionary",
                "value": value.$r().v
            };
        case Number:
            return {'name': property,
                'type': value % 1 === 0 ? "Integer" : "Float",
                "value": value
            };
        case String:
            return {'name': property,
                'type': "String",
                "value": value
            };
        case Boolean:
                return {'name': property,
                    'type': "Boolean",
                    "value": (value ? "True": "False")
                };
        default:
            return {'name': property,
                    'type': value.tp$name == undefined ? value : value.tp$name,
                    "value": value.$r == undefined ? value : value.$r().v
                    };
    }
}

/**
 * The main bootstrap script for loading pyodide.
 */

var languagePluginLoader = new Promise((resolve, reject) => {
  // This is filled in by the Makefile to be either a local file or the
  // deployed location. TODO: This should be done in a less hacky
  // way.
  var baseURL = self.languagePluginUrl || 'https://pyodide-cdn2.iodide.io/v0.15.0/full/';
  baseURL = baseURL.substr(0, baseURL.lastIndexOf('/')) + '/';

  ////////////////////////////////////////////////////////////
  // Package loading
  let loadedPackages = {};
  var loadPackagePromise = new Promise((resolve) => resolve());
  // Regexp for validating package name and URI
  var package_name_regexp = '[a-z0-9_][a-z0-9_\-]*'
  var package_uri_regexp =
      new RegExp('^https?://.*?(' + package_name_regexp + ').js$', 'i');
  var package_name_regexp = new RegExp('^' + package_name_regexp + '$', 'i');

  let _uri_to_package_name = (package_uri) => {
    // Generate a unique package name from URI

    if (package_name_regexp.test(package_uri)) {
      return package_uri;
    } else if (package_uri_regexp.test(package_uri)) {
      let match = package_uri_regexp.exec(package_uri);
      // Get the regexp group corresponding to the package name
      return match[1];
    } else {
      return null;
    }
  };

  // clang-format off
  let preloadWasm = () => {
    // On Chrome, we have to instantiate wasm asynchronously. Since that
    // can't be done synchronously within the call to dlopen, we instantiate
    // every .so that comes our way up front, caching it in the
    // `preloadedWasm` dictionary.

    let promise = new Promise((resolve) => resolve());
    let FS = pyodide._module.FS;

    function recurseDir(rootpath) {
      let dirs;
      try {
        dirs = FS.readdir(rootpath);
      } catch {
        return;
      }
      for (let entry of dirs) {
        if (entry.startsWith('.')) {
          continue;
        }
        const path = rootpath + entry;
        if (entry.endsWith('.so')) {
          if (Module['preloadedWasm'][path] === undefined) {
            promise = promise
              .then(() => Module['loadWebAssemblyModule'](
                FS.readFile(path), {loadAsync: true}))
              .then((module) => {
                Module['preloadedWasm'][path] = module;
              });
          }
        } else if (FS.isDir(FS.lookupPath(path).node.mode)) {
          recurseDir(path + '/');
        }
      }
    }

    recurseDir('/');

    return promise;
  }
  // clang-format on

  function loadScript(url, onload, onerror) {
    if (self.document) { // browser
      const script = self.document.createElement('script');
      script.src = url;
      script.onload = (e) => { onload(); };
      script.onerror = (e) => { onerror(); };
      self.document.head.appendChild(script);
    } else if (self.importScripts) { // webworker
      try {
        self.importScripts(url);
        onload();
      } catch {
        onerror();
      }
    }
  }

  let _loadPackage = (names, messageCallback, errorCallback) => {
    if (messageCallback == undefined) {
      messageCallback = () => {};
    }
    if (errorCallback == undefined) {
      errorCallback = () => {};
    }
    let _messageCallback = (msg) => {
      console.log(msg);
      messageCallback(msg);
    };
    let _errorCallback = (errMsg) => {
      console.error(errMsg);
      errorCallback(errMsg);
    };

    // DFS to find all dependencies of the requested packages
    let packages = self.pyodide._module.packages.dependencies;
    let loadedPackages = self.pyodide.loadedPackages;
    let queue = [].concat(names || []);
    let toLoad = {};
    while (queue.length) {
      let package_uri = queue.pop();

      const pkg = _uri_to_package_name(package_uri);

      if (pkg == null) {
        _errorCallback(`Invalid package name or URI '${package_uri}'`);
        return;
      } else if (pkg == package_uri) {
        package_uri = 'default channel';
      }

      if (pkg in loadedPackages) {
        if (package_uri != loadedPackages[pkg]) {
          _errorCallback(`URI mismatch, attempting to load package ` +
                         `${pkg} from ${package_uri} while it is already ` +
                         `loaded from ${loadedPackages[pkg]}!`);
          return;
        } else {
          _messageCallback(`${pkg} already loaded from ${loadedPackages[pkg]}`)
        }
      } else if (pkg in toLoad) {
        if (package_uri != toLoad[pkg]) {
          _errorCallback(`URI mismatch, attempting to load package ` +
                         `${pkg} from ${package_uri} while it is already ` +
                         `being loaded from ${toLoad[pkg]}!`);
          return;
        }
      } else {
        console.log(
            `${pkg} to be loaded from ${package_uri}`); // debug level info.

        toLoad[pkg] = package_uri;
        if (packages.hasOwnProperty(pkg)) {
          packages[pkg].forEach((subpackage) => {
            if (!(subpackage in loadedPackages) && !(subpackage in toLoad)) {
              queue.push(subpackage);
            }
          });
        } else {
          _errorCallback(`Unknown package '${pkg}'`);
        }
      }
    }

    self.pyodide._module.locateFile = (path) => {
      // handle packages loaded from custom URLs
      let pkg = path.replace(/\.data$/, "");
      if (pkg in toLoad) {
        let package_uri = toLoad[pkg];
        if (package_uri != 'default channel') {
          return package_uri.replace(/\.js$/, ".data");
        };
      };
      return baseURL + path;
    };

    let promise = new Promise((resolve, reject) => {
      if (Object.keys(toLoad).length === 0) {
        resolve('No new packages to load');
        return;
      }

      let packageList = Array.from(Object.keys(toLoad));
      _messageCallback(`Loading ${packageList.join(', ')}`)

      // monitorRunDependencies is called at the beginning and the end of each
      // package being loaded. We know we are done when it has been called
      // exactly "toLoad * 2" times.
      var packageCounter = Object.keys(toLoad).length * 2;

      self.pyodide._module.monitorRunDependencies = () => {
        packageCounter--;
        if (packageCounter === 0) {
          for (let pkg in toLoad) {
            self.pyodide.loadedPackages[pkg] = toLoad[pkg];
          }
          delete self.pyodide._module.monitorRunDependencies;
          self.removeEventListener('error', windowErrorHandler);

          let resolveMsg = `Loaded `;
          if (packageList.length > 0) {
            resolveMsg += packageList.join(', ');
          } else {
            resolveMsg += 'no packages'
          }

          if (!isFirefox) {
            preloadWasm().then(() => {
              console.log(resolveMsg);
              resolve(resolveMsg);
            });
          } else {
            console.log(resolveMsg);
            resolve(resolveMsg);
          }
        }
      };

      // Add a handler for any exceptions that are thrown in the process of
      // loading a package
      var windowErrorHandler = (err) => {
        delete self.pyodide._module.monitorRunDependencies;
        self.removeEventListener('error', windowErrorHandler);
        // Set up a new Promise chain, since this one failed
        loadPackagePromise = new Promise((resolve) => resolve());
        reject(err.message);
      };
      self.addEventListener('error', windowErrorHandler);

      for (let pkg in toLoad) {
        let scriptSrc;
        let package_uri = toLoad[pkg];
        if (package_uri == 'default channel') {
          scriptSrc = `${baseURL}${pkg}.js`;
        } else {
          scriptSrc = `${package_uri}`;
        }
        _messageCallback(`Loading ${pkg} from ${scriptSrc}`)
        loadScript(scriptSrc, () => {}, () => {
          // If the package_uri fails to load, call monitorRunDependencies twice
          // (so packageCounter will still hit 0 and finish loading), and remove
          // the package from toLoad so we don't mark it as loaded, and remove
          // the package from packageList so we don't say that it was loaded.
          _errorCallback(`Couldn't load package from URL ${scriptSrc}`);
          delete toLoad[pkg];
          let packageListIndex = packageList.indexOf(pkg);
          if (packageListIndex !== -1) {
            packageList.splice(packageListIndex, 1);
          }
          for (let i = 0; i < 2; i++) {
            self.pyodide._module.monitorRunDependencies();
          }
        });
      }

      // We have to invalidate Python's import caches, or it won't
      // see the new files. This is done here so it happens in parallel
      // with the fetching over the network.
      self.pyodide.runPython('import importlib as _importlib\n' +
                             '_importlib.invalidate_caches()\n');
    });

    return promise;
  };

  let loadPackage = (names, messageCallback, errorCallback) => {
    /* We want to make sure that only one loadPackage invocation runs at any
     * given time, so this creates a "chain" of promises. */
    loadPackagePromise = loadPackagePromise.then(
        () => _loadPackage(names, messageCallback, errorCallback));
    return loadPackagePromise;
  };

  ////////////////////////////////////////////////////////////
  // Fix Python recursion limit
  function fixRecursionLimit(pyodide) {
    // The Javascript/Wasm call stack may be too small to handle the default
    // Python call stack limit of 1000 frames. This is generally the case on
    // Chrom(ium), but not on Firefox. Here, we determine the Javascript call
    // stack depth available, and then divide by 50 (determined heuristically)
    // to set the maximum Python call stack depth.

    let depth = 0;
    function recurse() {
      depth += 1;
      recurse();
    }
    try {
      recurse();
    } catch (err) {
      ;
    }

    let recursionLimit = depth / 50;
    if (recursionLimit > 1000) {
      recursionLimit = 1000;
    }
    pyodide.runPython(
        `import sys; sys.setrecursionlimit(int(${recursionLimit}))`);
  };

  ////////////////////////////////////////////////////////////
  // Rearrange namespace for public API
  let PUBLIC_API = [
    'globals',
    'loadPackage',
    'loadedPackages',
    'pyimport',
    'repr',
    'runPython',
    'runPythonAsync',
    'checkABI',
    'version',
    'autocomplete',
  ];

  function makePublicAPI(module, public_api) {
    var namespace = {_module : module};
    for (let name of public_api) {
      namespace[name] = module[name];
    }
    return namespace;
  }

  ////////////////////////////////////////////////////////////
  // Loading Pyodide
  let wasmURL = `${baseURL}pyodide.asm.wasm`;
  let Module = {};
  self.Module = Module;

  Module.noImageDecoding = true;
  Module.noAudioDecoding = true;
  Module.noWasmDecoding = true;
  Module.preloadedWasm = {};
  let isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;

  let wasm_promise, wasm_fetch = fetch(wasmURL);
  const compileBuffer = () =>
      wasm_fetch.then(response => response.arrayBuffer())
          .then(bytes => WebAssembly.compile(bytes));
  if (WebAssembly.compileStreaming === undefined) {
    wasm_promise = compileBuffer();
  } else {
    wasm_promise = WebAssembly.compileStreaming(wasm_fetch);
    wasm_promise = wasm_promise.catch(e => {
      if (e instanceof TypeError) {
        console.error("pyodide streaming compilation failed:", e,
                      "- falling back to buffered compilation");
        return compileBuffer()
      }
      throw e;
    });
  }

  Module.instantiateWasm = (info, receiveInstance) => {
    wasm_promise.then(module => WebAssembly.instantiate(module, info))
        .then(instance => receiveInstance(instance));
    return {};
  };

  Module.checkABI = function(ABI_number) {
    if (ABI_number !== parseInt('1')) {
      var ABI_mismatch_exception =
          `ABI numbers differ. Expected 1, got ${ABI_number}`;
      console.error(ABI_mismatch_exception);
      throw ABI_mismatch_exception;
    }
    return true;
  };

  Module.autocomplete =
      function(path) {
    var pyodide_module = Module.pyimport("pyodide");
    return pyodide_module.get_completions(path);
  }

      Module.locateFile = (path) => baseURL + path;
  var postRunPromise = new Promise((resolve, reject) => {
    Module.postRun = () => {
      delete self.Module;
      fetch(`${baseURL}packages.json`)
          .then((response) => response.json())
          .then((json) => {
            fixRecursionLimit(self.pyodide);
            self.pyodide.globals =
                self.pyodide.runPython('import sys\nsys.modules["__main__"]');
            self.pyodide = makePublicAPI(self.pyodide, PUBLIC_API);
            self.pyodide._module.packages = json;
            if (self.iodide !== undefined) {
              // Perform some completions immediately so there isn't a delay on
              // the first call to autocomplete
              self.pyodide.runPython('import pyodide');
              self.pyodide.runPython('pyodide.get_completions("")');
            }
            resolve();
          });
    };
  });

  var dataLoadPromise = new Promise((resolve, reject) => {
    Module.monitorRunDependencies =
        (n) => {
          if (n === 0) {
            delete Module.monitorRunDependencies;
            resolve();
          }
        }
  });

  Promise.all([ postRunPromise, dataLoadPromise ]).then(() => resolve());

  const data_script_src = `${baseURL}pyodide.asm.data.js`;
  loadScript(data_script_src, () => {
    const scriptSrc = `${baseURL}pyodide.asm.js`;
    loadScript(scriptSrc, () => {
      // The emscripten module needs to be at this location for the core
      // filesystem to install itself. Once that's complete, it will be replaced
      // by the call to `makePublicAPI` with a more limited public API.
      self.pyodide = pyodide(Module);
      self.pyodide.loadedPackages = {};
      self.pyodide.loadPackage = loadPackage;
    }, () => {});
  }, () => {});

  ////////////////////////////////////////////////////////////
  // Iodide-specific functionality, that doesn't make sense
  // if not using with Iodide.
  if (self.iodide !== undefined) {
    // Load the custom CSS for Pyodide
    let link = document.createElement('link');
    link.rel = 'stylesheet';
    link.type = 'text/css';
    link.href = `${baseURL}renderedhtml.css`;
    document.getElementsByTagName('head')[0].appendChild(link);

    // Add a custom output handler for Python objects
    self.iodide.addOutputRenderer({
      shouldRender : (val) => {
        return (typeof val === 'function' &&
                pyodide._module.PyProxy.isPyProxy(val));
      },

      render : (val) => {
        let div = document.createElement('div');
        div.className = 'rendered_html';
        var element;
        if (val._repr_html_ !== undefined) {
          let result = val._repr_html_();
          if (typeof result === 'string') {
            div.appendChild(new DOMParser()
                                .parseFromString(result, 'text/html')
                                .body.firstChild);
            element = div;
          } else {
            element = result;
          }
        } else {
          let pre = document.createElement('pre');
          pre.textContent = val.toString();
          div.appendChild(pre);
          element = div;
        }
        return element.outerHTML;
      }
    });
  }
});
languagePluginLoader


text:
#ifndef V_WRITERCACHE_H
#define V_WRITERCACHE_H

#include "v_kernel.h"
#include "v_cache.h"

#define v_writerCache(o) (C_CAST((o),v_writerCache))
#define v_writerCacheItem(o) (C_CAST((o),v_writerCacheItem))

v_cache
v_writerCacheNew (
    v_kernel kernel,
    v_cacheKind kind);

#define v_writerCacheInsert(_this,item) \
        v_cacheInsert(v_cache(_this),v_cacheNode(item))

#define v_writerCacheWalk(_this,action,arg) \
        v_cacheWalk(v_cache(_this),action,arg)

#define v_writerCacheDeinit(_this) \
        v_cacheDeinit(v_cache(_this))

#define v_writerCacheRemove(_this,item) \
        v_cacheRemove(v_cache(_this),v_cacheNode(item))

/* Inner class: v_writerCacheItem */

v_writerCacheItem
v_writerCacheItemNew (
    v_cache cache,
    v_groupInstance instance);

#define v_writerCacheItemInstance(_this) \
        c_keep(v_writerCacheItem(_this)-instance)

#define v_writerCacheItemRemove(_this,kind) \
        v_cacheNodeRemove(v_cacheNode(_this),kind)

#endif

redpajama_set_name: RedPajamaGithub


text:
using Alldigit.IG.TradingFacade.Contracts.Messages;
using Alldigit.IG.TradingFacade.Logic.Messages.Interfaces;
using Newtonsoft.Json;
using System;

namespace Alldigit.IG.TradingFacade.Logic.Messages
{
    public class UserCredentials : IUserCredentials, IMessage<IUserCredentials, UserCredentials>
    {
        [JsonProperty("identifier")]
        public string Username { get; set; }

        [JsonProperty("password")]
        public string Password { get; set; }

        [JsonProperty("encryptedPassword")]
        public bool EncryptedPassword { get; set; }

        UserCredentials IMessage<IUserCredentials, UserCredentials>.CopyFrom(IUserCredentials source)
        {
            if (source == null) throw new ArgumentNullException("source");

            Username = source.Username;
            Password = source.Password;
            EncryptedPassword = source.EncryptedPassword;

            return this;
        }
    }
}


text:
/*
 * This file provided by Facebook is for non-commercial testing and evaluation
 * purposes only.  Facebook reserves all rights not expressly granted.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package com.facebook.samples.round;

import android.app.Application;

import com.facebook.common.logging.FLog;
import com.facebook.drawee.backends.pipeline.Fresco;

/**
 * Round Application implementation where we set up Fresco
 */
public class RoundApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        FLog.setMinimumLoggingLevel(FLog.VERBOSE);
        Fresco.initialize(this);
    }
}


text:
'use strict';

var fs = require('fs');
var path = require('path');

var Dispatcher = require('./dispatcher');
var Cache = require('./cache');
var Syncher = require('./syncher');

var extend = require('./extend');

function sizeof(pair) {
	return pair[0].length;
}

function remove(event) {
	this.watcher.remove(event.name).close();
}

function Loader(params) {
	params = params || {};
	extend(this, {
		pathname: params.pathname || '.',
		extname: params.extname ? '.' + params.extname : '',
		converter: params.converter,
		options: extend({encoding: 'utf-8'}, params.options),
		cache: new Cache({maxSize: params.maxSize, sizeof: sizeof}),
		watcher: new Cache(),
		queue: new Cache()
	});
	this.cache.on('remove', remove.bind(this));
}

Loader.prototype = extend(Object.create(Dispatcher.prototype), {
	constructor: Loader,
	_distrib: function (name, err, data, stat) {
		err || this._watch(name, data, stat);
		this.queue.remove(name).forEach(function (fn) {
			typeof fn == 'function' && fn(err, data, stat);
		});
	},
	_watch: function (name, data, stat) {
		this.cache.set(name, [data, stat]);
		this.watcher.has(name) || fs.watch(this._path(name), this.watcher.set(name, function (type, filename) {
			// cache removed internally
			// while remove-event not yet triggered
			if (!this.cache.has(name)) return ;
			switch (type) {
			case 'rename':
				if (!filename) break;
				var oldName = name;
				name = path.basename(filename, this.extname);
				this.watcher.set(name, this.watcher.remove(oldName));
				this.cache.set(name, this.cache.remove(oldName));
				this.dispatch({type: type, name: name, oldName: oldName});
				break;
			case 'change':
				this.cache.remove(name);
				this.load(name);
				this.dispatch({type: type, name: name});
				break;
			default:
				throw new Error('unrecognized file modification type: ' + type);
			}
		}.bind(this)));
	},
	_path: function (name) {
		return path.join(this.pathname, name + this.extname);
	},
	_push: function (name, fn) {
		if (this.queue.has(name)) return this.queue.get(name).push(fn) && false;
		return this.queue.set(name, [fn]) && true;
	},
	load: function (name, callback) {
		if (this.cache.has(name)) {
			if (typeof callback == 'function') {
				var args = this.cache.get(name);
				callback(null, args[0], args[1]);
			}
		}
		else if (this._push(name, callback)) {
			new Syncher().add(function (fn) {
				fs.readFile(this._path(name), this.options, fn);
			}.bind(this), function (fn) {
				fs.stat(this._path(name), fn);
			}.bind(this)).run(function (dataArgs, statArgs) {
				var err = dataArgs[0] || statArgs[0];
				var data = dataArgs[1];
				var stat = statArgs[1];
				if (err || typeof this.converter != 'function') return this._distrib(name, err, data, stat);
				this.converter({
					data: data,
					pathname: this._path(name)
				}, function (cvtErr, data) {
					this._distrib(name, err || cvtErr, data, stat);
				}.bind(this));
			}.bind(this));
		}
		return this;
	}
});

module.exports = Loader;


text:
#include <stdio.h>
#include <string>

#include "VideoManager.h"

extern "C"
    {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"

#include "EOSLuaRuntime.h"

    // -----------------------------------------------------------------------------
    // -----------------------------------------------------------------------------
    //
    // Module manifest structure. Developer must edit just the #define values below.
    //
#define _MODULE_NAME            "video"
#define _MODULE_VERSION         "0.1"
#define _MODULE_DATE            "November 16, 2012"
#define _MODULE_DESC_SHORT      "FFmpeg based video decoding module for EOS Scripting Environment"
#define _MODULE_DESC_LONG       "based on FFmpeg library. See http://ffmpeg.org/ for more details."
#define _MODULE_AUTHOR_NAME     "EOS Scripting Team"
#define _MODULE_AUTHOR_WEBSITE  "http://sourceforge.net/projects/eos-scripting/"
    //
    // -----------------------------------------------------------------------------
    // -----------------------------------------------------------------------------

    // -----------------------------------------------------------------------------

    // utility functions -----------------------------------------------------
    // end utility functions -------------------------------------------------

    // ====================== COMMON REQUIRED FUNCTIONS ============================
    // -----------------------------------------------------------------------------

    /*- @function eos.kinect.module.cleanup
     *  @brief automatically called from eos kernel on module unloading
     */
    static int moduleCleanup(lua_State* luaRuntime)
        {
        VideoManager::getInstance()->shutdown();
        //
        return 0;
        }

    // ====================== CUSTOM MODULE FUNCTIONS ==============================
    // -----------------------------------------------------------------------------

    static int initialize(lua_State* luaRuntime)
        {
        bool done = VideoManager::getInstance()->powerOn();
        //
        lua_pushboolean(luaRuntime, done);
        return 1;
        }

    // -----------------------------------------------------------------------------

    static int openStream(lua_State* luaRuntime)
        {
        bool done = false;
        //
        if(EOSLuaRuntime::checkLuaParameters("eos."_MODULE_NAME, "eos."_MODULE_NAME".stream.open", 1))
            {
            done = (VideoManager::getInstance()->openStream(luaL_checkstring(luaRuntime, 1)) == 0) ;
            }
        //
        lua_pushboolean(luaRuntime, done);
        return 1;
        }

    // -----------------------------------------------------------------------------

    /*- @function eos.kinect.update
     *  @brief updates module and active render targets
     *  @return updated (boolean) true or false
     */
    static int update(lua_State* luaRuntime)
        {
        VideoManager::getInstance()->update();
        //
        return 0;
        }

    // -----------------------------------------------------------------------------

    /*-
     * @name function eos.kinect.renderTarget.create()
     * @brief create a new render target for output
     * @param renderTargetName name of the render target
     * @param width width in pixels
     * @param height height in pixels
     * @returns session object
     */
    static int getOutputRGB(lua_State* luaRuntime)
        {
        void* userdata = NULL;
        userdata = VideoManager::getInstance()->getRGBFramebufferObject();
        //
        lua_pushlightuserdata(luaRuntime, userdata);
        return 1;
        }

    // -----------------------------------------------------------------------------
    // ========================== END LIBRARY FUNCTIONS ============================
    // -----------------------------------------------------------------------------

    /*class KeyValue
        {
    public:

        KeyValue(const char* key, int value)
            {
            this->key = strdup(key);
            this->value = value;
            }

        ~KeyValue()
            {
            free(this->key);
            }
        char* key;
        int value;
            };

    std::vector<KeyValue*> keysymbols;

    void loadModuleSymbols()
        {
        keysymbols.push_back(new KeyValue("EVT_NEWUSER", EVT_NEWUSER));
        keysymbols.push_back(new KeyValue("EVT_LOSTUSER", EVT_LOSTUSER));
        keysymbols.push_back(new KeyValue("EVT_POSEDETECTED", EVT_POSEDETECTED));
        keysymbols.push_back(new KeyValue("EVT_CALIBRATIONSTART", EVT_CALIBRATIONSTART));
        keysymbols.push_back(new KeyValue("EVT_CALIBRATIONEND", EVT_CALIBRATIONEND));
        keysymbols.push_back(new KeyValue("EVT_CALIBRATIONFAIL", EVT_CALIBRATIONFAIL));
        //
        char tmpstr[120];
        int totalsymbols = keysymbols.size();
        for (int i = 0; i < totalsymbols; i++)
            {
            sprintf(tmpstr, "eos.%s.%s = %d", _MODULE_NAME, keysymbols[i]->key, keysymbols[i]->value);
            EOSLuaRuntime::getInstance()->executeLuaChunk(tmpstr);
            delete keysymbols[i];
            }
        keysymbols.clear();
        }
     */

    // -----------------------------------------------------------------------------
    // ======================== LUA FUNCTIONS REGISTRATION =========================
    // -----------------------------------------------------------------------------

    // ==== Here we declare an array with all functions and their respective names.
    // ==== This array has elements of type luaL_reg, which is a structure with
    // ==== two fields: a string and a function pointer.

    const struct luaL_reg fn_table_module [] = {
        {"cleanup", moduleCleanup},
        {NULL, NULL} // <-- end-of-table sentinel
        };

    const struct luaL_reg  fn_table_stream[] = {
        {"open", openStream},
        {NULL, NULL} // <-- end-of-table sentinel
        };

    const struct luaL_reg fn_table_main [] = {
        {"initialize", initialize},
        {"getOutputRGB", getOutputRGB},
        {"update", update},
                                              //{"shutdown",                     shutdown},
        {NULL, NULL} // <-- end-of-table sentinel
        };

    /*const struct luaL_reg fn_table_image [] = {
            {NULL, NULL}  // <-- end-of-table sentinel
            };*/

    // ==== Finally, we declare a main (initialization) function, using luaL_openlib:

    int _INIT_(lua_State* luaRuntime)
        {
        EOSLuaRuntime::getInstance()->setRuntime(luaRuntime);
        //
        // let's fill the module manifest structure. Pay attention: it's in lua language!
        EOSLuaRuntime::getInstance()->executeLuaChunk(
                                                      "eos."_MODULE_NAME" = {}\
				 eos.module._new = eos."_MODULE_NAME"\
				 eos.module._new.module                        = {}\
				 eos.module._new.module.info                   = {}\
				 eos.module._new.module.info.name              = '"_MODULE_NAME".eosmodule'\
				 eos.module._new.module.info.tableName         = 'eos."_MODULE_NAME"'\
				 eos.module._new.module.info.version           = '"_MODULE_VERSION"'\
				 eos.module._new.module.info.date              = '"_MODULE_DATE"'\
				 eos.module._new.module.info.description       = {}\
				 eos.module._new.module.info.description.short = '"_MODULE_DESC_SHORT"'\
				 eos.module._new.module.info.description.long  = '"_MODULE_DESC_LONG"'\
				 eos.module._new.module.info.author            = {}\
				 eos.module._new.module.info.author.name       = '"_MODULE_AUTHOR_NAME"'\
				 eos.module._new.module.info.author.website    = '"_MODULE_AUTHOR_WEBSITE"'\
				 eos.module._new.module.reservedFunctions         = {}\
				 eos.module._new.module.reservedFunctions.init    = ''\
				 eos.module._new.module.reservedFunctions.cleanup = 'eos."_MODULE_NAME".module.cleanup'\
				");

        // registers "eos.*.module" functions
        luaL_register(luaRuntime, "eos."_MODULE_NAME".module", fn_table_module);

        // registers eos.* main functions
        luaL_register(luaRuntime, "eos."_MODULE_NAME, fn_table_main);

        // registers stream functions
        luaL_register(luaRuntime, "eos."_MODULE_NAME".stream", fn_table_stream);

        // loads module symbols
        //loadModuleSymbols();

        //
        return 1;
        }

    // -----------------------------------------------------------------------------

    } // extern "C" closure


text:
package icons;

import com.intellij.openapi.util.IconLoader;

import javax.swing.*;

/**
 * NOTE THIS FILE IS AUTO-GENERATED
 * DO NOT EDIT IT BY HAND, run build/scripts/icons.gant instead
 */
public class Git4ideaIcons {
  private static Icon load(String path) {
    return IconLoader.getIcon(path, Git4ideaIcons.class);
  }

  public static final Icon Ball0 = load("/icons/ball0.png"); // 8x8
  public static final Icon Ball1 = load("/icons/ball1.png"); // 8x8
  public static final Icon Ball2 = load("/icons/ball2.png"); // 8x8
  public static final Icon Ball3 = load("/icons/ball3.png"); // 8x8
  public static final Icon Ball4 = load("/icons/ball4.png"); // 8x8
  public static final Icon Ball5 = load("/icons/ball5.png"); // 8x8
  public static final Icon Ball6 = load("/icons/ball6.png"); // 8x8
  public static final Icon Ball7 = load("/icons/ball7.png"); // 8x8
  public static final Icon DeepCompare = load("/icons/DeepCompare.png"); // 16x16
  public static final Icon Greyball = load("/icons/greyball.png"); // 8x8
  public static final Icon Star = load("/icons/star.png"); // 13x13
}


text:
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.structuralsearch.impl.matcher;

import com.intellij.dupLocator.iterators.NodeIterator;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.XmlElementVisitor;
import com.intellij.psi.xml.*;
import com.intellij.structuralsearch.StructuralSearchUtil;
import com.intellij.structuralsearch.XmlMatchUtil;
import com.intellij.structuralsearch.impl.matcher.handlers.SubstitutionHandler;
import com.intellij.structuralsearch.impl.matcher.iterators.ListNodeIterator;
import com.intellij.structuralsearch.impl.matcher.iterators.SsrFilteringNodeIterator;
import com.intellij.xml.util.XmlUtil;
import org.jetbrains.annotations.NotNull;

/**
* @author Eugene.Kudelevsky
*/
public class XmlMatchingVisitor extends XmlElementVisitor {
  private final GlobalMatchingVisitor myMatchingVisitor;

  public XmlMatchingVisitor(@NotNull GlobalMatchingVisitor matchingVisitor) {
    myMatchingVisitor = matchingVisitor;
  }

  @Override public void visitXmlAttribute(XmlAttribute attribute) {
    final XmlAttribute another = (XmlAttribute)myMatchingVisitor.getElement();
    myMatchingVisitor.getMatchContext().pushResult();
    final XmlElement name = attribute.getNameElement();
    final boolean isTypedVar = myMatchingVisitor.getMatchContext().getPattern().isTypedVar(name);
    try {
      if (!myMatchingVisitor.setResult(isTypedVar || myMatchingVisitor.matchText(name, another.getNameElement()))) return;
      final XmlAttributeValue valueElement = attribute.getValueElement();
      myMatchingVisitor.setResult(valueElement == null || myMatchingVisitor.matchOptionally(valueElement, another.getValueElement()));
    } finally {
      myMatchingVisitor.scopeMatch(name, isTypedVar, another);
    }
  }

  @Override public void visitXmlAttributeValue(XmlAttributeValue value) {
    final XmlAttributeValue another = (XmlAttributeValue)myMatchingVisitor.getElement();
    final String text = value.getValue();

    if (myMatchingVisitor.getMatchContext().getPattern().isTypedVar(text)) {
      final SubstitutionHandler handler = (SubstitutionHandler)myMatchingVisitor.getMatchContext().getPattern().getHandler(text);
      final String text2 = another.getText();
      final int offset = StringUtil.isQuotedString(text2) ? 1 : 0;
      myMatchingVisitor.setResult(handler.handle(another, offset, text2.length() - offset, myMatchingVisitor.getMatchContext()));
    } else {
      myMatchingVisitor.setResult(myMatchingVisitor.matchText(text, another.getValue()));
    }
  }

  @Override public void visitXmlTag(XmlTag tag) {
    final XmlTag another = myMatchingVisitor.getElement(XmlTag.class);
    if (another == null) return;
    final CompiledPattern pattern = myMatchingVisitor.getMatchContext().getPattern();
    final XmlToken name = XmlUtil.getTokenOfType(tag, XmlTokenType.XML_NAME);
    final boolean isTypedVar = pattern.isTypedVar(name);

    if (!myMatchingVisitor.setResult((isTypedVar || myMatchingVisitor.matchText(tag.getName(), another.getName())) &&
                                     myMatchingVisitor.matchInAnyOrder(tag.getAttributes(), another.getAttributes()))) return;

    final XmlTagChild[] children1 = tag.getValue().getChildren();
    if (children1.length != 0) {
      if (children1.length == 1 && pattern.isTypedVar(children1[0])) {
        final NodeIterator patternNodes = SsrFilteringNodeIterator.create(tag.getValue().getChildren());
        if (patternNodes.current() != null) {
          final NodeIterator matchNodes = SsrFilteringNodeIterator.create(another.getValue().getChildren());
          if (!myMatchingVisitor.setResult(myMatchingVisitor.matchSequentially(patternNodes, matchNodes))) return;
        }
      }
      else if (children1.length != 1 || !XmlMatchUtil.isWhiteSpace(children1[0])) {
        final ListNodeIterator patternNodes = new ListNodeIterator(XmlMatchUtil.getElementsToMatch(children1));
        final XmlTagChild[] children2 = another.getValue().getChildren();
        final ListNodeIterator matchNodes = new ListNodeIterator(XmlMatchUtil.getElementsToMatch(children2));
        if (!myMatchingVisitor.setResult(myMatchingVisitor.matchSequentially(patternNodes, matchNodes))) return;
      }
    }
    if (isTypedVar) {
      final SubstitutionHandler handler = (SubstitutionHandler)pattern.getHandler(name);
      myMatchingVisitor.setResult(handler.handle(XmlUtil.getTokenOfType(another, XmlTokenType.XML_NAME),
                                                 myMatchingVisitor.getMatchContext()));
    }
  }

  @Override
  public void visitXmlText(XmlText text) {
    myMatchingVisitor.setResult(myMatchingVisitor.getMatchContext().getPattern().isTypedVar(text)
                                ? myMatchingVisitor.handleTypedElement(text, myMatchingVisitor.getElement())
                                : myMatchingVisitor.matchSequentially(text.getFirstChild(), myMatchingVisitor.getElement().getFirstChild()));
  }

  @Override public void visitXmlToken(XmlToken token) {
    if (token.getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) {
      final String text = token.getText();

      myMatchingVisitor.setResult(myMatchingVisitor.getMatchContext().getPattern().isTypedVar(text)
                                  ? myMatchingVisitor.handleTypedElement(token, myMatchingVisitor.getElement())
                                  : myMatchingVisitor.matchText(text, myMatchingVisitor.getElement().getText()));
    }
  }

  @Override
  public void visitXmlComment(XmlComment comment) {
    super.visitXmlComment(comment);
    final PsiElement element = myMatchingVisitor.getElement();
    if (!(element instanceof XmlComment)) return;
    final XmlComment other = (XmlComment)element;
    final XmlToken text = XmlUtil.getTokenOfType(comment, XmlTokenType.XML_COMMENT_CHARACTERS);
    assert text != null;
    final CompiledPattern pattern = myMatchingVisitor.getMatchContext().getPattern();
    final boolean typedVar = pattern.isTypedVar(text);
    if (typedVar) {
      final SubstitutionHandler handler = (SubstitutionHandler)pattern.getHandler(text);
      myMatchingVisitor.setResult(handler.handle(XmlUtil.getTokenOfType(other, XmlTokenType.XML_COMMENT_CHARACTERS),
                                                 myMatchingVisitor.getMatchContext()));
    }
    else {
      myMatchingVisitor.setResult(myMatchingVisitor.matchText(StructuralSearchUtil.normalize(text.getText()),
                                                              StructuralSearchUtil.normalize(other.getCommentText())));
    }
  }
}


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Aliyun.Api.LogService.Infrastructure.Protocol
{
    public class ErrorCode
    {
        #region Known error codes

        ///
        /// SDK 内部错误。
        ///
        internal static ErrorCode SdkInternalError { get; } = new ErrorCode(nameof(SdkInternalError));

        ///
        ///没有提供必须的 Content-Length 请求头。
        ///
        public static ErrorCode MissingContentLength { get; } = new ErrorCode(nameof(MissingContentLength));

        ///
        ///不支持 Content-Type 指定的类型。
        ///
        public static ErrorCode InvalidContentType { get; } = new ErrorCode(nameof(InvalidContentType));

        ///
        ///没有为 Body 不为空的 HTTP 请求指定 Content-Type 头。
        ///
        public static ErrorCode MissingContentType { get; } = new ErrorCode(nameof(MissingContentType));

        ///
        ///压缩场景下没有提供必须的 x-log-bodyrawsize 请求头。
        ///
        public static ErrorCode MissingBodyRawSize { get; } = new ErrorCode(nameof(MissingBodyRawSize));

        ///
        ///x-log-bodyrawsize 的值无效。
        ///
        public static ErrorCode InvalidBodyRawSize { get; } = new ErrorCode(nameof(InvalidBodyRawSize));

        ///
        ///x-log-compresstype 指定的压缩方式不支持。
        ///
        public static ErrorCode InvalidCompressType { get; } = new ErrorCode(nameof(InvalidCompressType));

        ///
        ///没有提供 HTTP 标准请求头 Host。
        ///
        public static ErrorCode MissingHost { get; } = new ErrorCode(nameof(MissingHost));

        ///
        ///没有提供 HTTP 标准请求头 Date。
        ///
        public static ErrorCode MissingDate { get; } = new ErrorCode(nameof(MissingDate));

        ///
        ///Date 请求头的值不符合 RFC822 标准。
        ///
        public static ErrorCode InvalidDateFormat { get; } = new ErrorCode(nameof(InvalidDateFormat));

        ///
        ///没有提供 HTTP 请求头 x-log-apiversion。
        ///
        public static ErrorCode MissingAPIVersion { get; } = new ErrorCode(nameof(MissingAPIVersion));

        ///
        ///HTTP 请求头 x-log-apiversion 的值不支持。
        ///
        public static ErrorCode InvalidAPIVersion { get; } = new ErrorCode(nameof(InvalidAPIVersion));

        ///
        ///没有在 Authorization 头部提供 AccessKeyId。
        ///
        public static ErrorCode MissAccessKeyId { get; } = new ErrorCode(nameof(MissAccessKeyId));

        ///
        ///提供的 AccessKeyId 值未授权。
        ///
        public static ErrorCode Unauthorized { get; } = new ErrorCode(nameof(Unauthorized));

        ///
        ///没有提供 HTTP 请求头 x-log-signaturemethod。
        ///
        public static ErrorCode MissingSignatureMethod { get; } = new ErrorCode(nameof(MissingSignatureMethod));

        ///
        ///x-log-signaturemethod 头部指定的签名方法不支持。
        ///
        public static ErrorCode InvalidSignatureMethod { get; } = new ErrorCode(nameof(InvalidSignatureMethod));

        ///
        ///请求的发送时间超过当前服务处理时间前后 15 分钟的范围。
        ///
        public static ErrorCode RequestTimeTooSkewed { get; } = new ErrorCode(nameof(RequestTimeTooSkewed));

        ///
        ///日志项目(Project)不存在。
        ///
        public static ErrorCode ProjectNotExist { get; } = new ErrorCode(nameof(ProjectNotExist));

        ///
        ///请求的数字签名不匹配。
        ///
        public static ErrorCode SignatureNotMatch { get; } = new ErrorCode(nameof(SignatureNotMatch));

        ///
        ///超过写入日志限额。
        ///
        public static ErrorCode WriteQuotaExceed { get; } = new ErrorCode(nameof(WriteQuotaExceed));

        ///
        ///超过读取日志限额。
        ///
        public static ErrorCode ReadQuotaExceed { get; } = new ErrorCode(nameof(ReadQuotaExceed));

        ///
        ///服务器内部错误。
        ///
        public static ErrorCode InternalServerError { get; } = new ErrorCode(nameof(InternalServerError));

        ///
        ///服务器正忙,请稍后再试。
        ///
        public static ErrorCode ServerBusy { get; } = new ErrorCode(nameof(ServerBusy));

        #endregion

        private static readonly IDictionary<String, ErrorCode> KnownErrorCodes;

        public String Code { get; }

        static ErrorCode()
        {
            KnownErrorCodes = new Dictionary<String, ErrorCode>(typeof(ErrorCode)
                .GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)
                .Where(x => x.PropertyType == typeof(ErrorCode))
                .Select(x => x.GetValue(null))
                .Cast<ErrorCode>()
                .ToDictionary(x => x.Code, x => x));
        }

        private ErrorCode(String code)
        {
            this.Code = code;
        }

        public static Boolean IsKnownErrorCode(String code)
        {
            return KnownErrorCodes.ContainsKey(code);
        }

        public Boolean IsKnownErrorCode()
        {
            return IsKnownErrorCode(this.Code);
        }

        public override Boolean Equals(Object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }

            if (ReferenceEquals(this, obj))
            {
                return true;
            }

            switch (obj)
            {
                case ErrorCode other:
                    return String.Equals(this.Code, other.Code);
                case String other:
                    return String.Equals(this.Code, other);
                default:
                    return false;
            }
        }

        public override Int32 GetHashCode()
            => this.Code?.GetHashCode() ?? 0;

        public override String ToString()
            => this.Code;

        public static implicit operator String(ErrorCode code)
            => code?.Code;

        public static implicit operator ErrorCode(String code)
            => code == null
                ? null
                : (KnownErrorCodes.TryGetValue(code, out var errorCode)
                    ? errorCode
                    : new ErrorCode(code));

        public static Boolean operator ==(ErrorCode lhs, ErrorCode rhs)
            => lhs?.Code == rhs?.Code;

        public static Boolean operator !=(ErrorCode lhs, ErrorCode rhs)
            => lhs?.Code != rhs?.Code;
    }
}


text:
.page.ng-enter {
    animation: fadeIn 1s;
}


text:
namespace llvm {
class StringRef;

class MSP430Subtarget : public MSP430GenSubtargetInfo {
  virtual void anchor();
  bool ExtendedInsts;
  const DataLayout DL; // Calculates type size & alignment
  MSP430FrameLowering FrameLowering;
  MSP430InstrInfo InstrInfo;
  MSP430TargetLowering TLInfo;
  MSP430SelectionDAGInfo TSInfo;

public:
  /// This constructor initializes the data members to match that
  /// of the specified triple.
  ///
  MSP430Subtarget(const std::string &TT, const std::string &CPU,
                  const std::string &FS, const TargetMachine &TM);

  MSP430Subtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);

  /// ParseSubtargetFeatures - Parses features string setting specified
  /// subtarget options.  Definition of function is auto generated by tblgen.
  void ParseSubtargetFeatures(StringRef CPU, StringRef FS);

  const TargetFrameLowering *getFrameLowering() const { return &FrameLowering; }
  const MSP430InstrInfo *getInstrInfo() const { return &InstrInfo; }
  const DataLayout *getDataLayout() const { return &DL; }
  const TargetRegisterInfo *getRegisterInfo() const {
    return &InstrInfo.getRegisterInfo();
  }
  const MSP430TargetLowering *getTargetLowering() const { return &TLInfo; }
  const MSP430SelectionDAGInfo *getSelectionDAGInfo() const { return &TSInfo; }
};
} // End llvm namespace

#endif  // LLVM_TARGET_MSP430_SUBTARGET_H


text:
package parser

import (
	"io"

	"github.com/jstesta/gomidi/cfg"
	"github.com/jstesta/gomidi/midi"
)

func ReadMidi(r io.Reader, c cfg.GomidiConfig) (m *midi.Midi, err error) {

	header, err := readHeader(r, c)
	if err != nil {
		return
	}

	var tracks []*midi.Track

	tracks = make([]*midi.Track, 0, header.NumberOfTracks())
	var i int
	for i = 0; i < header.NumberOfTracks(); i++ {
		track, err := readTrack(r, c)
		if err != nil {
			return nil, err
		}
		// track == nil if an alien chunk was found
		if track != nil {
			tracks = append(tracks, track)
		}
	}

	return midi.NewMidi(header, tracks), nil
}


text:
<?php

/**
 * Created by Khang Nguyen.
 * Email: khang.nguyen@banvien.com
 * Date: 9/12/2017
 * Time: 9:28 AM
 */
class News_controller extends CI_Controller
{
	function __construct() {
		parent::__construct();
		$this->load->model('Category_Model');
		$this->load->model('News_Model');
		$this->load->model('City_Model');
		$this->load->model('Brand_Model');
		$this->load->model('Product_Model');
		$this->load->model('SampleHouse_Model');
		$this->load->helper("seo_url");
		$this->load->helper("my_date");
		$this->load->helper("bootstrap_pagination");
		$this->load->library('pagination');
		$this->load->helper('form');
	}

	public function index($offset=0){
		// begin file cached
		$this->load->driver('cache');
		$categories = $this->cache->file->get('category');
		$footerMenus = $this->cache->file->get('footer');
		if(!$categories){
			$categories = $this->Category_Model->getCategories();
			$this->cache->file->save('category', $categories, 1440);
		}
		if(!$footerMenus) {
			$footerMenus = $this->City_Model->findByTopProductOfCategoryGroupByCity();
			$this->cache->file->save('footer', $footerMenus, 1440);
		}
		$data = $categories;
		$data['footerMenus'] = $footerMenus;
		// end file cached

		$cities = $this->cache->file->get('cities');
		if(!$cities){
			$cities = $this->City_Model->getAllActive();
			$this->cache->file->save('cities', $cities, 1440);
		}
		$data['cities'] = $cities;

		$search_data = $this->News_Model->searchByProperties($offset, MAX_PAGE_ITEM);
		$data = array_merge($data, $search_data);
		$config = pagination();
		$config['base_url'] = base_url('tin-tuc.html');
		$config['total_rows'] = $data['total'];
		$config['per_page'] = MAX_PAGE_ITEM;
		$data['sampleHouses'] = $this->SampleHouse_Model->findTopNewExceptCurrent(0, 5);
		$data['justUpdatedProducts'] = $this->Product_Model->findJustUpdate(0, 10);
		$data['topcityhasproduct'] = $this->City_Model->findTopCityHasProduct(20);
		$data['topbranchhasproduct'] = $this->Brand_Model->findTopBranchHasProduct(20);

		$this->pagination->initialize($config);
		$data['pagination'] = $this->pagination->create_links();

		$this->load->view('/news/News_view', $data);
	}

	public function detail($newsId){
		// begin file cached
		$this->load->driver('cache');
		$categories = $this->cache->file->get('category');
		$footerMenus = $this->cache->file->get('footer');
		if(!$categories){
			$categories = $this->Category_Model->getCategories();
			$this->cache->file->save('category', $categories, 1440);
		}
		if(!$footerMenus) {
			$footerMenus = $this->City_Model->findByTopProductOfCategoryGroupByCity();
			$this->cache->file->save('footer', $footerMenus, 1440);
		}
		$data = $categories;
		$data['footerMenus'] = $footerMenus;
		// end file cached

		$cities = $this->cache->file->get('cities');
		if(!$cities){
			$cities = $this->City_Model->getAllActive();
			$this->cache->file->save('cities', $cities, 1440);
		}
		$data['cities'] = $cities;

		$data['newsDetail'] = $this->News_Model->findById($newsId);
		$data['topNews'] = $this->News_Model->findTopNewExceptCurrent($newsId, 5);
		$data['sampleHouses'] = $this->SampleHouse_Model->findTopNewExceptCurrent(0, 5);
		$this->News_Model->updateViewForNewsId($newsId);

		$this->load->view('/news/News_detail', $data);
	}

}


text:
package com.appleframework.jms.rocketmq;

import com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer;

public class RocketMQPullConsumer extends DefaultMQPullConsumer {

	private String namesrvAddr;

	private String consumerGroup;

	public void setNamesrvAddr(String namesrvAddr) {
		this.namesrvAddr = namesrvAddr;
	}

	public void setConsumerGroup(String consumerGroup) {
		this.consumerGroup = consumerGroup;
	}

	public void close() {
		this.shutdown();
	}

	public void init() {
		super.setNamesrvAddr(namesrvAddr);
		super.setConsumerGroup(consumerGroup);
	}

}


text:
from Module import AbstractModule

class Module(AbstractModule):
    def __init__(self):
        AbstractModule.__init__(self)

    def run(
        self, network, antecedents, out_attributes, user_options, num_cores,
        outfile):
        from genomicode import filelib

        in_data = antecedents
        plot_hyb_bar(in_data.identifier, outfile)
        filelib.assert_exists_nz(outfile)

    def name_outfile(self, antecedents, user_options):
        return "hybridization.png"

def plot_hyb_bar(filename, outfile):
    from genomicode import mplgraph
    from genomicode import filelib
    import math
    import numpy

    high = ['ILMN_2038770', 'ILMN_2038769']
    med = ['ILMN_2038768', 'ILMN_2038771']
    low = ['ILMN_1343050', 'ILMN_1343052']
    high_data = []
    med_data = []
    low_data = []
    import arrayio
    M = arrayio.read(filename)
    header = M.row_names()
    for i in range(M.dim()[0]):
        if not M.row_names(header[1])[i] == 'cy3_hyb':
            continue
        if M.row_names(header[0])[i] in high:
            high_data.extend(M.slice()[i])
        if M.row_names(header[0])[i] in med:
            med_data.extend(M.slice()[i])
        if M.row_names(header[0])[i] in low:
            low_data.extend(M.slice()[i])

    mean = [numpy.mean(high_data), numpy.mean(med_data), numpy.mean(low_data)]
    flag = [math.isnan(i) for i in mean]
    assert True not in flag, 'input is not a control file'
    std = [numpy.std(high_data), numpy.std(med_data), numpy.std(low_data)]
    fig = mplgraph.barplot(
        mean, std, ylabel='Signal', box_label=['high', 'med', 'low'])
    fig.savefig(outfile)


text:
class BlogsController < ApplicationController

  before_filter :find_blog, :only => [:comment, :show, :authorize]
  before_filter :find_page, :except => [:captcha, :authorize]
  before_filter :load_blogs, :except => [:captcha, :authorize, :tag, :category, :author, :show]

  def index
    present(@page)

    respond_to do |format|
      format.html
      format.rss
    end
  end

  def tag
    @blogs = Blog.tagged_with(params[:tag], :on => :tags).published
    present(@page)
    render_or_404(@blogs)
  end

  def category
    @blogs = Blog.tagged_with(params[:category], :on => :categories).published
    present(@page)
    render_or_404(@blogs)
  end

  def author
    @blogs = Blog.tagged_with(params[:author], :on => :authors).published
    present(@page)
    render_or_404(@blogs)
  end

  def show
    if @blog.present? and @blog.published?
      @comment = @blog.comments.new
      present(@page)
    else
      error_404
    end
  end

  def comment
    @comment = @blog.comments.new(params[:comment])

    if Raptcha.valid?(params) || BlogSetting.enable_captcha == false
      @comment.approved = true unless BlogSetting.manual_moderation
      if @comment.save
        if BlogSetting.manual_moderation
          flash[:notice] = "Thank you for your comment. It will appear once it has been approved by our moderators."
        elsif BlogSetting.enable_approve_comment_by_email
          flash[:notice] = "Thank you for your comment. You have been emailed to approve this comment before it will appear."
        else
          flash[:notice] = @page[:successful_comment]
        end

        if BlogSetting.enable_email_notification
          begin
            BlogMailer.deliver_notification(@comment, request)
          rescue
            logger.warn "There was an error delivering a blog notification.\n#{$!}\n"
          end
        end
        if BlogSetting.enable_approve_comment_by_email && BlogSetting.manual_moderation
          begin
            BlogMailer.deliver_confirmation(@comment, request)
          rescue
            logger.warn "There was an error delivering a blog confirmation.\n#{$!}\n"
          end
        end
        @comment = @blog.comments.new
      end
    else
      @comment.valid?
      @comment.errors.add_to_base "Captcha is incorrect"
    end

    present(@page)
    render 'show'
  end

  def captcha
    Raptcha.render(controller=self, params)
  end

  def authorize
    if params[:token] && BlogSetting.enable_approve_comment_by_email && BlogSetting.manual_moderation
      @comment = Comment.find_by_token(params[:token])
      @comment.approved = true
      redirect_to blog_post_url(@comment.blog.permalink) if @comment.save
    else
      redirect_to blog_url
    end
  end

protected
  def load_blogs
    @blogs = Blog.published
  end

  def find_blog
    if (@blog = Blog.find_by_permalink(params[:permalink], :conditions => ["publishing_date < ? and draft != ?", Time.now, true]))
      if BlogSetting.enable_related_tags
        @related_tags_blogs = @blog.find_related_tags.reject {|blog| !blog.published? && !@blog }
      end

      if BlogSetting.enable_related_categories
        @related_categories_blogs = @blog.find_related_categories.reject {|blog| !blog.published? && !@blog }
      end

      if BlogSetting.enable_related_authors
        @related_authors_blogs = @blog.find_related_authors.reject {|blog| !blog.published? && !@blog }
      end
    end
  end

  def find_page
    @page = Page.find_by_link_url("/blog")
  end

  def render_or_404(blogs)
    if blogs.empty?
      error_404
    else
      render :action => 'index'
    end
  end
end


text:
/**
 * @constructor Stack
 * Stacks items on top of each other.
 * @param {ItemSet} itemset
 * @param {Object} [options]
 */
function Stack (itemset, options) {
  this.itemset = itemset;

  this.options = options || {};
  this.defaultOptions = {
    order: function (a, b) {
      //return (b.width - a.width) || (a.left - b.left);  // TODO: cleanup
      // Order: ranges over non-ranges, ranged ordered by width, and
      // lastly ordered by start.
      if (a instanceof ItemRange) {
        if (b instanceof ItemRange) {
          var aInt = (a.data.end - a.data.start);
          var bInt = (b.data.end - b.data.start);
          return (aInt - bInt) || (a.data.start - b.data.start);
        }
        else {
          return -1;
        }
      }
      else {
        if (b instanceof ItemRange) {
          return 1;
        }
        else {
          return (a.data.start - b.data.start);
        }
      }
    },
    margin: {
      item: 10
    }
  };

  this.ordered = [];  // ordered items
}

/**
 * Set options for the stack
 * @param {Object} options  Available options:
 *                          {ItemSet} itemset
 *                          {Number} margin
 *                          {function} order  Stacking order
 */
Stack.prototype.setOptions = function setOptions (options) {
  util.extend(this.options, options);

  // TODO: register on data changes at the connected itemset, and update the changed part only and immediately
};

/**
 * Stack the items such that they don't overlap. The items will have a minimal
 * distance equal to options.margin.item.
 */
Stack.prototype.update = function update() {
  this._order();
  this._stack();
};

/**
 * Order the items. If a custom order function has been provided via the options,
 * then this will be used.
 * @private
 */
Stack.prototype._order = function _order () {
  var items = this.itemset.items;
  if (!items) {
    throw new Error('Cannot stack items: ItemSet does not contain items');
  }

  // TODO: store the sorted items, to have less work later on
  var ordered = [];
  var index = 0;
  // items is a map (no array)
  util.forEach(items, function (item) {
    if (item.visible) {
      ordered[index] = item;
      index++;
    }
  });

  //if a customer stack order function exists, use it.
  var order = this.options.order || this.defaultOptions.order;
  if (!(typeof order === 'function')) {
    throw new Error('Option order must be a function');
  }

  ordered.sort(order);

  this.ordered = ordered;
};

/**
 * Adjust vertical positions of the events such that they don't overlap each
 * other.
 * @private
 */
Stack.prototype._stack = function _stack () {
  var i,
      iMax,
      ordered = this.ordered,
      options = this.options,
      orientation = options.orientation || this.defaultOptions.orientation,
      axisOnTop = (orientation == 'top'),
      margin;

  if (options.margin && options.margin.item !== undefined) {
    margin = options.margin.item;
  }
  else {
    margin = this.defaultOptions.margin.item
  }

  // calculate new, non-overlapping positions
  for (i = 0, iMax = ordered.length; i < iMax; i++) {
    var item = ordered[i];
    var collidingItem = null;
    do {
      // TODO: optimize checking for overlap. when there is a gap without items,
      //  you only need to check for items from the next item on, not from zero
      collidingItem = this.checkOverlap(ordered, i, 0, i - 1, margin);
      if (collidingItem != null) {
        // There is a collision. Reposition the event above the colliding element
        if (axisOnTop) {
          item.top = collidingItem.top + collidingItem.height + margin;
        }
        else {
          item.top = collidingItem.top - item.height - margin;
        }
      }
    } while (collidingItem);
  }
};

/**
 * Check if the destiny position of given item overlaps with any
 * of the other items from index itemStart to itemEnd.
 * @param {Array} items     Array with items
 * @param {int}  itemIndex  Number of the item to be checked for overlap
 * @param {int}  itemStart  First item to be checked.
 * @param {int}  itemEnd    Last item to be checked.
 * @return {Object | null}  colliding item, or undefined when no collisions
 * @param {Number} margin   A minimum required margin.
 *                          If margin is provided, the two items will be
 *                          marked colliding when they overlap or
 *                          when the margin between the two is smaller than
 *                          the requested margin.
 */
Stack.prototype.checkOverlap = function checkOverlap (items, itemIndex,
                                                      itemStart, itemEnd, margin) {
  var collision = this.collision;

  // we loop from end to start, as we suppose that the chance of a
  // collision is larger for items at the end, so check these first.
  var a = items[itemIndex];
  for (var i = itemEnd; i >= itemStart; i--) {
    var b = items[i];
    if (collision(a, b, margin)) {
      if (i != itemIndex) {
        return b;
      }
    }
  }

  return null;
};

/**
 * Test if the two provided items collide
 * The items must have parameters left, width, top, and height.
 * @param {Component} a     The first item
 * @param {Component} b     The second item
 * @param {Number} margin   A minimum required margin.
 *                          If margin is provided, the two items will be
 *                          marked colliding when they overlap or
 *                          when the margin between the two is smaller than
 *                          the requested margin.
 * @return {boolean}        true if a and b collide, else false
 */
Stack.prototype.collision = function collision (a, b, margin) {
  return ((a.left - margin) < (b.left + b.width) &&
      (a.left + a.width + margin) > b.left &&
      (a.top - margin) < (b.top + b.height) &&
      (a.top + a.height + margin) > b.top);
};