I mentioned my affinity for Python on my first Weblog entry, at the end of last year. I had intended to tell you about the Iron Python for ASP.NET CTP in my second entry, but it mysteriously stopped working for me before I could write about it. It turns out that disabling Iron Python for ASP.NET was an unintended side effect of the Visual Studio SP1 installation, which also caused other mayhem on my Visual Studio 2005 instance. By the time I had fixed all that and reinstalled Iron Python for ASP.NET I was distracted by the AJAX subversion exploit.
I recently went back and looked at the Iron Python for ASP.NET CTP, and was impressed with what has actually been accomplished with that project. It's not just that you can code server-side ASP.NET Web logic very simply in Python, as in this Global.py from the Iron Python Personal Web site starter site:
from System import * from System.Web import * from System.Web.Security import * def Application_Start(): SiteMap.SiteMapResolve += AppendQueryString if not Roles.RoleExists('Administrators'): Roles.CreateRole('Administrators') if not Roles.RoleExists('Friends'): Roles.CreateRole('Friends') def AppendQueryString(sender, e): node = SiteMap.CurrentNode if node is not None: node = node.Clone(True) qs = e.Context.Request.QUERY_STRING if len(qs) > 0: node.Url += '?' + qs if node.ParentNode is not None: node.ParentNode.Url += '?' + qs return node
It's also not just that you can write code behind standard-looking ASP.NET pages in Python, and that much of what you already know about Python and ASP.NET just carries over.
No, it's even more impressive than that. What this team has done is to extend the ASP.NET model from static compiled languages to dynamic languages, as explained in David Ebbo's white paper on the subject. They basically scrapped the CodeDOM model used for static compiled languages, and extended the idea of no-compile pages. It sounds like a paradox, but they've created no-compile pages that support scripting languages with a change to the
PageParserFilter API, which gives external code a hook into the parser. They have also added a custom HTTP module, and a custom base class for scripting pages.
One thing they haven't done is to support Web services. That turned out to be hard, and it's not clear when or even whether they'll come up with a solution. Another thing that they haven't done in the CTP, but which I hope to see in a future drop, is to write full Visual Studio IntelliSense support for Python. Stay tuned.