OWASP O2 Platform Blog

PoC of IronPython REPL Scripting Environment

Based on http://www.ironpython.net/2.7 , here is an O2 script that creates a simple Python REPL scripting environment

Gui Created

Source Code

var topPanel = "PoC - IronPython REPL - Simple".popupWindow(800,400);
topPanel.insert_LogViewer();
//var topPanel = panel.clear().add_Panel();

var code = "print 2+2;";

Action<string> executeScript = null;
new API_ConsoleOut().show_ConsoleOut(topPanel.title("Console Out"));
var codeEditor = topPanel.insert_Left("Python Code").add_SourceCodeViewer().set_Text(code,".cs");

var cmdLine = new PythonCommandLine();
var engine = Python.CreateEngine();
var runtime = engine.Runtime;
executeScript = (script) =>	{
								try
								{
									"Execucuring code".info();
									var source = engine.CreateScriptSourceFromString(script, SourceCodeKind.AutoDetect);
									var mod = engine.CreateScope();
									source.Execute(mod);
								}
								catch(Exception ex)
								{
									ex.log();
								}
							};

codeEditor.onTextChange((text)=> code = text);
codeEditor.parent().insert_Above(20).add_Link("Execute Pyhton code" , ()=> executeScript(code)).click();

//using Microsoft.Scripting
//using IronPython
//using IronPython.Hosting
//O2Ref:IronPython.dll
//O2Ref:Microsoft.Dynamic.dll
//O2Ref:Microsoft.Scripting.dll
//O2File:API_ConsoleOut.cs

April 23, 2012 - Posted by | Python

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: