<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>A song for the lovers</title>
	
	<link>http://www.oluyede.org/blog</link>
	<description>Everything considered harmful</description>
	<lastBuildDate>Sat, 09 May 2009 12:35:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/ASongForTheLovers" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Erlang talk</title>
		<link>http://feedproxy.google.com/~r/ASongForTheLovers/~3/SCWrO9x7p-0/</link>
		<comments>http://www.oluyede.org/blog/2009/05/09/erlang-talk/#comments</comments>
		<pubDate>Sat, 09 May 2009 12:35:36 +0000</pubDate>
		<dc:creator>Lawrence</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[erlang python pycon slides]]></category>

		<guid isPermaLink="false">http://www.oluyede.org/blog/?p=424</guid>
		<description><![CDATA[This morning I gave my talk about Erlang to a room full of Pythonistas (even people standing!) and it went pretty well considering the fact that was my first talk ever. I already posted the slides online on SlideShare.

http://www.slideshare.net/rhymes/erlang-and-python
]]></description>
			<content:encoded><![CDATA[<p>This morning I gave my talk about Erlang to a room full of Pythonistas (even people standing!) and it went pretty well considering the fact that was my first talk ever. I already posted the <a href="http://www.slideshare.net/rhymes/erlang-and-python">slides</a> online on SlideShare.</p>

<p><a href="http://www.slideshare.net/rhymes/erlang-and-python">http://www.slideshare.net/rhymes/erlang-and-python</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ASongForTheLovers?a=SCWrO9x7p-0:FJTo_7ut6yo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/ASongForTheLovers?i=SCWrO9x7p-0:FJTo_7ut6yo:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ASongForTheLovers?a=SCWrO9x7p-0:FJTo_7ut6yo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/ASongForTheLovers?i=SCWrO9x7p-0:FJTo_7ut6yo:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ASongForTheLovers/~4/SCWrO9x7p-0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.oluyede.org/blog/2009/05/09/erlang-talk/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.oluyede.org/blog/2009/05/09/erlang-talk/</feedburner:origLink></item>
		<item>
		<title>Offline</title>
		<link>http://feedproxy.google.com/~r/ASongForTheLovers/~3/9kS_dPuQCSM/</link>
		<comments>http://www.oluyede.org/blog/2009/04/30/offline/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 09:10:06 +0000</pubDate>
		<dc:creator>Lawrence</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python erlang pycon london]]></category>

		<guid isPermaLink="false">http://www.oluyede.org/blog/?p=421</guid>
		<description><![CDATA[Tomorrow evening I&#8217;m leaving for a trip to London (yes, again!). Just vacation by the way.

I&#8217;ll be back on the 6th of May.

PyCon Tre is coming, in fact I&#8217;ll be in Florence from the 7th of May to the 10th to attend it. This year I&#8217;m going to speak for the first time. I submitted [...]]]></description>
			<content:encoded><![CDATA[<p>Tomorrow evening I&#8217;m leaving for a trip to London (yes, again!). Just vacation by the way.</p>

<p>I&#8217;ll be back on the 6th of May.</p>

<p>PyCon Tre is coming, in fact I&#8217;ll be in Florence from the 7th of May to the 10th to attend it. This year I&#8217;m going to speak for the first time. I submitted a talk about Erlang and Python but then I pretty soon realized that it should have been about Erlang and the outside world because there&#8217;s no direct connection between the two <img src='http://www.oluyede.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<p>Anyway, I know that few people of the non-italian community will be there (Guido, Fredrik, Raymond, Anna, and many more) so I&#8217;ll see you all in Florence on the 8th!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ASongForTheLovers?a=9kS_dPuQCSM:J2ZQeHkzg0A:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/ASongForTheLovers?i=9kS_dPuQCSM:J2ZQeHkzg0A:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ASongForTheLovers?a=9kS_dPuQCSM:J2ZQeHkzg0A:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/ASongForTheLovers?i=9kS_dPuQCSM:J2ZQeHkzg0A:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ASongForTheLovers/~4/9kS_dPuQCSM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.oluyede.org/blog/2009/04/30/offline/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.oluyede.org/blog/2009/04/30/offline/</feedburner:origLink></item>
		<item>
		<title>PyCon Italy Tre is ready to rock.</title>
		<link>http://feedproxy.google.com/~r/ASongForTheLovers/~3/ncFkU4hig9o/</link>
		<comments>http://www.oluyede.org/blog/2009/04/03/pycon-italy-tre-is-ready-to-rock/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 18:24:16 +0000</pubDate>
		<dc:creator>Lawrence</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python pycon italy]]></category>

		<guid isPermaLink="false">http://www.oluyede.org/blog/?p=419</guid>
		<description><![CDATA[The third edition of the PyCon Italy is ready, we&#8217;ve finally published the schedule!

It will be held in Florence as last year, on the 8th, 9th and 10th of May!

We&#8217;ve received several talk proposal, we let the community vote to create a chart and we created the schedule including regular talks, sponsored ones and talks [...]]]></description>
			<content:encoded><![CDATA[<p>The third edition of the PyCon Italy is ready, we&#8217;ve finally published the <a href="http://www.pycon.it/pycon3/schedule/">schedule</a>!</p>

<p>It will be held in Florence as last year, on the 8th, 9th and 10th of May!</p>

<p>We&#8217;ve received several talk proposal, we let the community vote to create a chart and we created the schedule including regular talks, sponsored ones and talks by invited guests. Talking about the invited guests: this year we have the pleasure to be joined by <strong>Guido Van Rossum</strong> (with two keynotes and a QA session), Alex Martelli (talking about software abstractions), Raymond Hettinger (AI with Python and descriptors), Fredrik Lundh (<strong>with the first talk ever about <a href="http://code.google.com/p/unladen-swallow/wiki/ProjectPlan">Unladen Swallow</a>!</strong>)  and Antonio Cangiano (talking about how to get rich with Python <img src='http://www.oluyede.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  !</p>

<p>Remember that as last year all the talks will have simultaneous translation between english and italian and viceversa so you&#8217;ll be able to attend the conference and understand everything.</p>

<p>If you are interested in <a href="http://www.pycon.it/pycon3/sponsorship/">sponsoring</a>, donating or any kind of help for the conference please contact me or write to the board of organizers at info at pycon.it</p>

<p>Hope to see you there!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ASongForTheLovers?a=ncFkU4hig9o:neUaZpIQwXE:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/ASongForTheLovers?i=ncFkU4hig9o:neUaZpIQwXE:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ASongForTheLovers?a=ncFkU4hig9o:neUaZpIQwXE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/ASongForTheLovers?i=ncFkU4hig9o:neUaZpIQwXE:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ASongForTheLovers/~4/ncFkU4hig9o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.oluyede.org/blog/2009/04/03/pycon-italy-tre-is-ready-to-rock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.oluyede.org/blog/2009/04/03/pycon-italy-tre-is-ready-to-rock/</feedburner:origLink></item>
		<item>
		<title>The first Django book “made in Italy” is out</title>
		<link>http://feedproxy.google.com/~r/ASongForTheLovers/~3/ACFqlEY41x8/</link>
		<comments>http://www.oluyede.org/blog/2009/01/30/the-first-django-book-made-in-italy-is-out/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 22:29:03 +0000</pubDate>
		<dc:creator>Lawrence</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.oluyede.org/blog/?p=416</guid>
		<description><![CDATA[Marco Beri, one of the organizers of PyCon Italy, published the first book in Italian about Django 1.0. It has been reviewed, among others, by Antonio Cangiano! This is great news for the chances of widespread adoption of Django in Italy!
]]></description>
			<content:encoded><![CDATA[<p><a href="http://beri.it/">Marco Beri</a>, one of the organizers of <a href="http://www.pycon.it/">PyCon Italy</a>, published <a href="http://www.apogeonline.com/libri/9788850328178/scheda">the first book in Italian about Django 1.0</a>. It has been reviewed, among others, by <a href="http://antoniocangiano.com/">Antonio Cangiano</a>! This is great news for the chances of widespread adoption of Django in Italy!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/ASongForTheLovers?a=3jXwutoJ"><img src="http://feeds.feedburner.com/~f/ASongForTheLovers?i=3jXwutoJ" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/ASongForTheLovers?a=9SFdciJV"><img src="http://feeds.feedburner.com/~f/ASongForTheLovers?i=9SFdciJV" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ASongForTheLovers/~4/ACFqlEY41x8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.oluyede.org/blog/2009/01/30/the-first-django-book-made-in-italy-is-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.oluyede.org/blog/2009/01/30/the-first-django-book-made-in-italy-is-out/</feedburner:origLink></item>
		<item>
		<title>Blog feed changed</title>
		<link>http://feedproxy.google.com/~r/ASongForTheLovers/~3/eTu1N5ZNi-0/</link>
		<comments>http://www.oluyede.org/blog/2009/01/23/blog-feed-changed/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 10:40:56 +0000</pubDate>
		<dc:creator>Lawrence</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://www.oluyede.org/blog/?p=410</guid>
		<description><![CDATA[FeedBurner has changed, so has my feed, please update: http://feeds2.feedburner.com/ASongForTheLovers
]]></description>
			<content:encoded><![CDATA[<p>FeedBurner has changed, so has my feed, please update: <a href="http://feeds2.feedburner.com/ASongForTheLovers">http://feeds2.feedburner.com/ASongForTheLovers</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/ASongForTheLovers?a=XCtfJZoG"><img src="http://feeds.feedburner.com/~f/ASongForTheLovers?i=XCtfJZoG" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/ASongForTheLovers?a=vjS21d7V"><img src="http://feeds.feedburner.com/~f/ASongForTheLovers?i=vjS21d7V" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ASongForTheLovers/~4/eTu1N5ZNi-0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.oluyede.org/blog/2009/01/23/blog-feed-changed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.oluyede.org/blog/2009/01/23/blog-feed-changed/</feedburner:origLink></item>
		<item>
		<title>PyCon Italia Tre is ready to go</title>
		<link>http://feedproxy.google.com/~r/ASongForTheLovers/~3/vl5VzT_yahQ/</link>
		<comments>http://www.oluyede.org/blog/2009/01/23/pycon-italia-tre-is-ready-to-go/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 10:07:49 +0000</pubDate>
		<dc:creator>Lawrence</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[pycon]]></category>
		<category><![CDATA[PyConIt]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.oluyede.org/blog/?p=404</guid>
		<description><![CDATA[The website of the Italian Python Conference, PyCon.it, has been launched. Apart from the schedule and new stuff (that I&#8217;ll talk about in another detailed post) the big, big news is that this year Guido van Rossum himself will be there to host a keynote.

I&#8217;m thrilled about this because it also means that PyCon Italy [...]]]></description>
			<content:encoded><![CDATA[<p>The website of the <a href="http://www.pycon.it/">Italian Python Conference</a>, <a href="http://www.pycon.it/">PyCon.it</a>, has been launched. Apart from the schedule and new stuff (that I&#8217;ll talk about in another detailed post) the <strong>big</strong>, <strong>big</strong> news is that this year Guido van Rossum himself will be there to host a keynote.</p>

<p>I&#8217;m thrilled about this because it also means that PyCon Italy is really growing. Last year we had around 300 people and Alex Martelli, Brad Fitzpatrick and Raymond Hettinger among others. This year Guido agreed to come so I hope I&#8217;ll see at least all the Italian Python community there!</p>

<p>See you on the 8th, 9th and 10th of May, 2009.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/ASongForTheLovers?a=DXCj90Ni"><img src="http://feeds.feedburner.com/~f/ASongForTheLovers?i=DXCj90Ni" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/ASongForTheLovers?a=9bAllGzw"><img src="http://feeds.feedburner.com/~f/ASongForTheLovers?i=9bAllGzw" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ASongForTheLovers/~4/vl5VzT_yahQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.oluyede.org/blog/2009/01/23/pycon-italia-tre-is-ready-to-go/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.oluyede.org/blog/2009/01/23/pycon-italia-tre-is-ready-to-go/</feedburner:origLink></item>
		<item>
		<title>IronPython in Action, book review</title>
		<link>http://feedproxy.google.com/~r/ASongForTheLovers/~3/y1SyTyOGbO8/</link>
		<comments>http://www.oluyede.org/blog/2009/01/19/ironpython-in-action-book-review/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 15:29:26 +0000</pubDate>
		<dc:creator>Lawrence</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[DotNET]]></category>
		<category><![CDATA[Opensource]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.oluyede.org/blog/?p=388</guid>
		<description><![CDATA[I&#8217;ve been actively developing with .NET in 2003-2004 but for some reasons I left the whole bandwagon.

Recently I&#8217;ve had the opportunity to read Michael Foord&#8217;s upcoming book: IronPython in Action and let me say that I found it extremely interesting, and I suggest it to everybody needing (or wanting) to work with .NET from a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been actively developing with .NET in 2003-2004 but for <a href="http://www.oluyede.org/blog/2007/04/07/about-me-and-net-atomnet-and-stuff-like-that/">some reasons</a> I left the whole <em>bandwagon</em>.</p>

<p>Recently I&#8217;ve had the opportunity to read <a href="http://www.voidspace.org.uk/python/weblog/index.shtml">Michael Foord</a>&#8217;s upcoming book: <a href="http://www.ironpythoninaction.com/">IronPython in Action</a> and let me say that I found it extremely interesting, and I suggest it to everybody needing (or wanting) to work with .NET from a <em>dynamic</em> perspective or to .NET developers interested in the <em>world out there</em>.</p>

<p>The book covers a lot of ground, sometimes deeply, sometimes just in the surface but it seems to talk about everything there&#8217;s to know to make that ground solid enough to build something lasting.</p>

<p>From the Python introduction to IronPython extension, from IronPython embedding to XML, Visual Studio, testing, metaprogramming, Windows Presentation Foundation (the .NET new UI), system administration, ASP.NET, databases, Silverlight and much more.</p>

<p>Let&#8217;s go through the chapters themselves.</p>

<h2>Chapter 1: A New Language for .NET</h2>

<p>This chapter is an introduction to IronPython, .NET and our <em>beloved</em> interactive interpreter.
One of the things I enjoyed discovering throughout the book is the extent of the language support in the .NET framework. Who knew Microsoft could have promoted it as a full citizen!</p>

<p>You can use IronPython in Visual Studio, ASP.NET, Silverlight, <a href="http://en.wikipedia.org/wiki/Microsoft_XNA">XNA</a> (Microsoft&#8217;s new gaming platform), the Robotics Kit and many more places. Since .NET libraries are all written with the same bytecode (called <acronym title="Intermediate Language">IL</acronym>) pretty much every door is open.</p>

<p><a href="http://en.wikipedia.org/wiki/Common_Public_License">IP&#8217;s license</a> is opensource and approved by the OSI, the development is done in public so there&#8217;s no need to worry about the future of the language.</p>

<p>There are two versions of IP: 1 and 2. I&#8217;d stick with version 2 because support Python 2.5 features. Recently there&#8217;s been <a href="http://ironpython-urls.blogspot.com/2009/01/ironpython-and-python-26.html">some new development</a> about the next version and support for Python 2.6. The second version also ships the Dynamic Language Runtime (<em>DLR</em>), a specific runtime dedicated to dynamic languages. It seems Jim Hugunin was definitely right after all.</p>

<p>IP 2 should work in Mono too (by default requires .NET 2) but I didn&#8217;t succeed to do so and soon gave up anyway because I planned to use my Windows virtual machine on Mac OS X.</p>

<p>The book as a nice series of reasons why a Python developer should try IP:</p>

<ul>
<li>IronPython has no GIL for multithreaded applications</li>
<li>Extending IP through C# is easier than extending Python through C</li>
<li>Applications can be sandboxed</li>
<li>You can leverage two Window&#8217;s GUI toolkits for desktop apps: Windows Forms and WPF</li>
<li>.NET has a huge number of libraries available</li>
<li>Silverlight allows the developer to code inside the browser in IP</li>
</ul>

<p>IP is a full citizen of the platform, and the interactive interpreter can be used to explore at runtime the whole framework while developing. That&#8217;s a huge advantage over C# developers <img src='http://www.oluyede.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<h2>Chapter 2: Introduction to Python</h2>

<p>The second chapter is an overview of Python. I posted a <a href="http://blogs.ugidotnet.org/lawrence/archive/2008/12/28/ironpython-in-action-introduzione-a-python.aspx">detailed summary in Italian</a> on my old .NET blog just to help .NET developers (at least those who read the blogs of the <a href="http://www.ugidotnet.org/">Italian .NET user group</a>) to understand what&#8217;s Python all about.</p>

<h2>Chapter 3: .NET Objects &amp; IronPython</h2>

<p>How to use .NET from IP? That&#8217;s what this chapter is all about. After the intro there&#8217;s a whole Windows Forms example showing the important parts. Notice that creating a desktop application take something like this:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">    <span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">import</span> clr
    <span style="color: #66cc66;">&gt;&gt;&gt;</span> clr.<span style="color: black;">AddReference</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'System.Windows.Forms'</span><span style="color: black;">&#41;</span>
    <span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">from</span> System.<span style="color: black;">Windows</span>.<span style="color: black;">Forms</span> <span style="color: #ff7700;font-weight:bold;">import</span> Application, Form
    <span style="color: #66cc66;">&gt;&gt;&gt;</span> form = Form<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #66cc66;">&gt;&gt;&gt;</span> form.<span style="color: black;">Text</span> = <span style="color: #483d8b;">'Hello World'</span> <span style="color: #808080; font-style: italic;"># set the title</span>
    <span style="color: #66cc66;">&gt;&gt;&gt;</span> Application.<span style="color: black;">Run</span><span style="color: black;">&#40;</span>form<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># main loop</span></pre></div></div>


<p>You can either choose to write the interface manually or use Visual Studio to design it and load it from the application.</p>

<p>Note that .NET objects are inheritable from IP, so that&#8217;s a go!</p>

<p>I remember the old days of C# where I had to declare each and every type up front and it feels nice to be able to use the same libraries and classes without all the verbosity.</p>

<h2>Chapter 4: Writing An Application and Design Patterns with IronPython</h2>

<p>Finally with the fourth chapter I can get my hands dirty and start delving into the process of writing a real application in IP.</p>

<p>The application is a Windows Forms based multiple document editor, <em>MultiDoc</em>. You can find all the book <a href="http://www.ironpythoninaction.com/download.html">source code online</a>.</p>

<p>The chapter starts talking about Python protocols, duck typing, magic methods to help understand what&#8217;s going on underneath and how to leverage Python features for the application at hand.</p>

<p>The choice is perfect because in a few line of code Michael Foord can throw in <em>a lot</em> of features, functionalities and patterns (like MVC, command, observer and others).</p>

<p>It&#8217;s shown that there&#8217;s some overlap sometimes between Python features and .NET&#8217;s and Michael Foord wisely suggests to choose considering needs, portability and pure taste.</p>

<p>I personally found amusing the fact that you can add event handlers for GUI applications like this:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">  button.<span style="color: black;">Click</span> += <span style="color: #ff7700;font-weight:bold;">lambda</span> sender, event: command.<span style="color: black;">execute</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>


<h2>Chapter 5: First Class Functions in Action with XML</h2>

<p><em>MultiDoc</em> in this chapter gains XML supports. There&#8217;s an introduction to first class functions, higher order functions and decorator. Functions are used as event handlers.</p>

<p>The command pattern is used to implement some functionalities for the application.</p>

<h2>Chapter 6: Properties, Dialogs and Visual Studio</h2>

<p>The chapter starts with an introduction to Python properties used to augment a partial implementation of the observer pattern to synchronize parts of the application. Cool.</p>

<p>After that Visual Studio is fired up to design a dialog to embed in the application.</p>

<h2>Chapter 7: Agile Testing &#8211; Where Dynamic Typing Shines</h2>

<p>This chapter is all about testing. We all know how testing is fundamental. Michael Foord uses the standard <em>unittest</em> module and his <a href="http://pypi.python.org/pypi/mock/0.4.0">Mock</a> library.</p>

<p>I really liked the monkey patching explanation combined to the method lookup rules in Python. It refreshed my memory and I guess it&#8217;s useful for newcomers.</p>

<p>The author also shows functional testing and <em>user stories</em> applied to the same GUI application.</p>

<p>I once developed a wxPython app in TDD (with Twisted in place too) and that thought me a lot of stuff about mocking and GUI testing.</p>

<h2>Chapter 8: Getting deeper in IronPython: Metaprogramming, Protocols and More</h2>

<p>I think this chapter is mandatory for a non-Python developer, or a beginner anyway.</p>

<p>It&#8217;s all about protocols in common Python code and in the standard library: basic procotols, generators, descriptors and so on.</p>

<p>I honestly didn&#8217;t know there was some kind of duck typing in C# too (see <code>IEnumerable</code> and <code>foreach</code>)</p>

<p>A good book on Python cannot ignore metaprogramming through metaclasses and I think Michael Foord does a good job explaning the how, what and why without giving an headache to the reader about the gory details. There&#8217;s plenty of documentation about the dark side of Python out there already.</p>

<p>The &#8220;more&#8221; part of the chapter&#8217;s title is: profiling through metaclasses, differences between .NET types and Python&#8217;s and more.</p>

<h2>Chapter 9: WPF and IronPython</h2>

<p>From now on the book goes in details about the .NET world seen from IronPython side. From chapter 1 to chapter 8 you build the solid ground, now it&#8217;s time to make it flourish.</p>

<p>One of the big parts of .NET is his UI support and Windows Presentation Foundation (<em>WPF</em>) is the king in the castle.</p>

<p>Michael Foord develops an example showing <strong>lots</strong> of stuff. It&#8217;s good to know that you can still leverage the tools to design the UI like mainstream .NET developers do.</p>

<h2>Chapter 10: Windows System Administration with IronPython</h2>

<p>We all know how versatile Python is. It can scale up and down easily.
The activity of system administration can be very simplified with a dynamic language. Yes I&#8217;m talking to you Windows developers!</p>

<p>Please stop writing scripts with the DOS batch language, (Iron)Python is there to help you.</p>

<p>It really makes system administration on Windows shiny. The book teaches how to interface with <a href="http://en.wikipedia.org/wiki/Windows_Management_Instrumentation">WMI</a> and <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx">PowerShell</a>. Who new you could call IronPython from another shell language!</p>

<h2>Chapter 11: IronPython and ASP.NET</h2>

<p>ASP.NET is the web framework of .NET. IronPython can be used but there are some extensions to install to make it so.</p>

<p>I still find <strong>extremely odd</strong> the concept of <em>viewstate</em>: an encrypted serialization of the state of all the <em>controls</em> of an ASP.NET page that gets embedded in a hidden HTML element and passed back and forth each time. What!? <img src='http://www.oluyede.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<p>The book shows a way to serialize Python objects inside there (beware, it can potentially make the HTML pages bigger and bigger).</p>

<p>Anyway I still find a lot of ASP.NET stuff very <em>odd</em>, like the limit of one web form per page.</p>

<p>I stated my opinion about ASP.NET (which I find one of the worst parts of .NET) a lot of time ago. Nice to see that almost nothing has changed <img src='http://www.oluyede.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<p>Looking forward to see how <a href="http://www.asp.net/mvc/">ASP.NET MVC</a> will be.</p>

<h2>Chapter 12: Databases and Web Services</h2>

<p>This chapter starts with the .NET data model and its interface to database systems. <del datetime="2009-01-19T16:25:14+00:00">Michael Foord</del> Christian Muirhead (the co-author) uses PostgreSQL to support the examples.</p>

<p>The second part is about the SOAP and REST capabilities of the framework. Consuming a SOAP webservice in .NET it&#8217;s really easy, altough the example parses a web service written in .NET itself.</p>

<p>I wonder if it&#8217;s all easy with a SOAP service exposed by other stacks.</p>

<h2>Chapter 13: Silverlight: IronPython in the Browser</h2>

<p>Microsoft some time ago released a plugin <em>almost</em> cross platform and <em>almost</em> cross browser called Silverlight.</p>

<p>Silverlight is useful if you want to develop applications inside the browser in a sandboxed environment.</p>

<p>Silverlight features: a slimmed version of WPF, full access to the DOM, access to JavaScript, cross domain requests, threading, asynchronous programming, client side storage and even media streaming with video brushing.</p>

<p>The chapter develops a Twitter client to show these features.</p>

<p>I&#8217;m still not really up to the idea that the future of web development should be inside these plugins, but it&#8217;s there if you want to use it.</p>

<h2>Chapter 14: Extending IronPython with C# / VB.NET</h2>

<p>This and the next chapter explain how to reach out the usual domain of IronPython and either extend it or embed it.</p>

<p>IronPython is theoretically extensible with any language of the .NET platform but for obvious reasons the book treats particularities of C# and VB.NET.</p>

<p>It deals with Python idioms and how to implement them, it deals with how to create mutable classes, how to implement keyword arguments and so on.</p>

<p>The really interesting part is the last one where it&#8217;s shown an example of a function to generate and compile at runtime a .NET assembly using code generation techniques.</p>

<p>Very funky!</p>

<h2>Chapter 15: Embedding the IronPython Engine</h2>

<p>With this last, advanced, chapter Michael Foord explains how to embed IronPython and so augment a .NET application. It can be used as a scripting engine, for plugins or to mix and integrate other languages (you can even interact with snippets of codes written in different languages!).</p>

<h2>Conclusions</h2>

<p>I personally found the book very enlightening and there&#8217;s much of interesting stuff in there for both Python and .NET developers. I guess it&#8217;s the first book on IronPython and anyway it&#8217;s a must have for everyone who needs to work on .NET.</p>

<p>It shows there are some unpolished parts with the integration and some differences between CPython and IronPython behavior but it can only become better in the future.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/ASongForTheLovers?a=hybUCp3D"><img src="http://feeds.feedburner.com/~f/ASongForTheLovers?i=hybUCp3D" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/ASongForTheLovers?a=2fPUvtzD"><img src="http://feeds.feedburner.com/~f/ASongForTheLovers?i=2fPUvtzD" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ASongForTheLovers/~4/y1SyTyOGbO8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.oluyede.org/blog/2009/01/19/ironpython-in-action-book-review/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.oluyede.org/blog/2009/01/19/ironpython-in-action-book-review/</feedburner:origLink></item>
		<item>
		<title>Twitter account</title>
		<link>http://feedproxy.google.com/~r/ASongForTheLovers/~3/CF2E33k1_JQ/</link>
		<comments>http://www.oluyede.org/blog/2009/01/11/twitter-account/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 13:12:17 +0000</pubDate>
		<dc:creator>Lawrence</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.oluyede.org/blog/?p=383</guid>
		<description><![CDATA[I opened a new twitter account in english. I use twitter a lot but only for my personal ramblings and to follow the italian blogosphere. From time to time I found myself wanting to twit in English either to reply to developers, designers and the great minds of the IT world or post about my [...]]]></description>
			<content:encoded><![CDATA[<p>I opened a new twitter account in english. I use twitter a lot but only for my personal ramblings and to follow the italian blogosphere. From time to time I found myself wanting to <em>twit </em>in English either to reply to developers, designers and the great minds of the IT world or post about my work stuff.</p>

<p>So I decided to divide my twitter account into two. <a href="http://twitter.com/rhymes">@rhymes</a> will still be my personal rambling page in Italian, <a href="http://twitter.com/lawrenceoluyede">@lawrenceoluyede</a> is going to be my window to the rest of the twitter world.</p>

<p>This way my english speaking followers don&#8217;t have to understand italian too <img src='http://www.oluyede.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/ASongForTheLovers?a=uyJE2BBb"><img src="http://feeds.feedburner.com/~f/ASongForTheLovers?i=uyJE2BBb" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/ASongForTheLovers?a=IhKokQc0"><img src="http://feeds.feedburner.com/~f/ASongForTheLovers?i=IhKokQc0" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ASongForTheLovers/~4/CF2E33k1_JQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.oluyede.org/blog/2009/01/11/twitter-account/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.oluyede.org/blog/2009/01/11/twitter-account/</feedburner:origLink></item>
		<item>
		<title>Django has the quid</title>
		<link>http://feedproxy.google.com/~r/ASongForTheLovers/~3/ngttqNkgRoo/</link>
		<comments>http://www.oluyede.org/blog/2008/11/23/django-has-the-quid/#comments</comments>
		<pubDate>Sun, 23 Nov 2008 14:26:51 +0000</pubDate>
		<dc:creator>Lawrence</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[pylons]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.oluyede.org/blog/?p=372</guid>
		<description><![CDATA[I started developing web applications in Python relatively a long time ago.

I tried almost them all in various degrees of depth: Python + CGI, Zope 2, Webware for Python, Subway (who does remember it?), Twisted Web, Nevow, Python + WSGI, Paste, Django, Pylons and maybe something else I can&#8217;t remember right now.

Nowadays most of my [...]]]></description>
			<content:encoded><![CDATA[<p>I started developing web applications in Python relatively a long time ago.</p>

<p>I tried almost them all in various degrees of depth: Python + CGI, Zope 2, Webware for Python, Subway (who does remember it?), Twisted Web, Nevow, Python + WSGI, Paste, Django, Pylons and maybe something else I can&#8217;t remember right now.</p>

<p>Nowadays most of my attention is caught by Pylons and Django. The latter has recently come to its 1.0 milestone and altough some books about it out there need update there&#8217;s a ton of documentation to start on the right track. Pylons has a different approach (but not that different in my opinion, because Django is not tight coupled as some people think it is) on how to develop applications but I&#8217;m not here to judge which one does things in the best way although I have to admit that for personal preference I&#8217;d vote for Django.</p>

<p>I&#8217;ve been using Pylons at work (the web part of one of our flagship product is going to be Pylons in and out) for a year and I used Django for personal and professional applications and both of them have pro and cons.</p>

<p>What really concerns me is the different <em>feeling </em>the everyday use of both give me. When I&#8217;m focused on Django I feel part of an increasing and participating community with tons of blog posts,  job offerings, and niceties such as the amazing <a href="http://pinaxproject.com/">Pinax project</a>, <a href="http://djangopeople.net/">django people</a> and so on. It does also feel like I&#8217;m using something rock solid despite its limitations (every piece of software has them).</p>

<p>Pylons, <em>au contraire</em>, is just a nice piece of software with which you can develop your applications but I don&#8217;t have around me the same community, the same <em>vibe</em>.</p>

<p>I hope the <a href="http://pylonsbook.com/">upcoming Pylons book</a> is going to change that. Don&#8217;t underestimate the power of communities, there&#8217;s not only Facebook out there <img src='http://www.oluyede.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/ASongForTheLovers?a=T9xoeCV2"><img src="http://feeds.feedburner.com/~f/ASongForTheLovers?i=T9xoeCV2" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/ASongForTheLovers?a=3hWSvjZs"><img src="http://feeds.feedburner.com/~f/ASongForTheLovers?i=3hWSvjZs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ASongForTheLovers/~4/ngttqNkgRoo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.oluyede.org/blog/2008/11/23/django-has-the-quid/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.oluyede.org/blog/2008/11/23/django-has-the-quid/</feedburner:origLink></item>
		<item>
		<title>Twisted interactive console</title>
		<link>http://feedproxy.google.com/~r/ASongForTheLovers/~3/AahTGnljkv4/</link>
		<comments>http://www.oluyede.org/blog/2008/08/31/twisted-interactive-console/#comments</comments>
		<pubDate>Sun, 31 Aug 2008 17:39:05 +0000</pubDate>
		<dc:creator>Lawrence</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python twisted repl]]></category>

		<guid isPermaLink="false">http://www.oluyede.org/blog/2008/08/31/twisted-interactive-console/</guid>
		<description><![CDATA[As you all already know TwistedMatrix is great to write asynchronous event-driven network oriented programs: define how your protocol responds in case of events, attach some callbacks if you need them, wrap it in a factory and activate the reactor.

The reactor runs a giant loop in which events are processed in a non-blocking fashion. Sometimes, [...]]]></description>
			<content:encoded><![CDATA[<p>As you all already know <a href="http://twistedmatrix.com/">TwistedMatrix</a> is great to write asynchronous event-driven network oriented programs: define how your protocol responds in case of events, attach some callbacks if you need them, wrap it in a factory and activate the reactor.</p>

<p>The reactor runs a giant loop in which events are processed in a non-blocking fashion. Sometimes, though, everything a man needs it&#8217;s just to make it stop. At least for a while, at least for the sake of getting data from the user.</p>

<p>The most prominent example of a command line client program that needs to stop and wait is a REPL. The following kind of <a href="http://en.wikipedia.org/wiki/REPL">REPL</a> is a bit unorthodox, you&#8217;ll see.</p>

<p>The secret sauce (at least the one I found) to write such kind of interactive program in Twisted is <a href="http://twistedmatrix.com/documents/current/api/twisted.internet.stdio.html">twisted.internet.stdio.StandardIO</a>. It connects your <a href="http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IProtocol.html">protocol</a> to standard input and output:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> Repl<span style="color: black;">&#40;</span>basic.<span style="color: black;">LineReceiver</span><span style="color: black;">&#41;</span>:
    delimiter = <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span>
    prompt_string = <span style="color: #483d8b;">'cmd&gt; '</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> prompt<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">transport</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">prompt_string</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> connectionMade<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">sendLine</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Welcome to Console'</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">prompt</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> lineReceived<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, line<span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># blank line</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> line:
            <span style="color: #008000;">self</span>.<span style="color: black;">prompt</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">return</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">issueCommand</span><span style="color: black;">&#40;</span>line<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> issueCommand<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, command<span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># send the command to the server</span>
        d = sendCmd<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%s%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>command, <span style="color: #008000;">self</span>.<span style="color: black;">delimiter</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        d.<span style="color: black;">addCallback</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._checkResponse<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> _checkResponse<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, args<span style="color: black;">&#41;</span>:
        success, num_lines, data = args
        <span style="color: #ff7700;font-weight:bold;">if</span> num_lines <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">20</span>:
            <span style="color: #808080; font-style: italic;"># use less to display the response</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">lessify</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #008000;">self</span>.<span style="color: black;">sendLine</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">prompt</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> lessify<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, data<span style="color: black;">&#41;</span>:
        p = <span style="color: #dc143c;">subprocess</span>.<span style="color: black;">Popen</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;less&quot;</span><span style="color: black;">&#93;</span>, stdin=<span style="color: #dc143c;">subprocess</span>.<span style="color: black;">PIPE</span><span style="color: black;">&#41;</span>
        p.<span style="color: black;">communicate</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> connectionLost<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, reason<span style="color: black;">&#41;</span>:
        reactor.<span style="color: black;">stop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>


<p>When the protocol it is connected to the standard output with</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">stdio.<span style="color: black;">StandardIO</span><span style="color: black;">&#40;</span>TaskConsole<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
reactor.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>


<p>the program displays the prompt, hence when a line is received from the standard input it is sent to the other protocol attached on the network and a callback is registered for the response. I also decided to use <em>less</em> to display the response if it&#8217;s more than some lines but that&#8217;s a detail.</p>

<p>The <em>sendCmd</em> function instantiate the networked protocol and its factory:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> sendCmd<span style="color: black;">&#40;</span><span style="color: #dc143c;">cmd</span><span style="color: black;">&#41;</span>:
    factory = CFactory<span style="color: black;">&#40;</span><span style="color: #dc143c;">cmd</span><span style="color: black;">&#41;</span>
    reactor.<span style="color: black;">connectTCP</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'127.0.0.1'</span>, <span style="color: #ff4500;">1234</span>, factory<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> factory.<span style="color: black;">deferred</span></pre></div></div>


<p>Then, when the server replies with some content we check to see if everything went ok and the reconstruct the whole response sending it back the REPL:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> Client<span style="color: black;">&#40;</span>basic.<span style="color: black;">LineReceiver</span><span style="color: black;">&#41;</span>:
    delimiter = <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> connectionMade<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># send the command received by the cmdline to the server</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">sendLine</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">factory</span>.<span style="color: #dc143c;">cmd</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">buffer</span> = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">cmd_success</span> = <span style="color: #008000;">True</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> lineReceived<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, line<span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># basic check error/success</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> line.<span style="color: black;">startswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'OK'</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> line.<span style="color: black;">startswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'ERR'</span><span style="color: black;">&#41;</span>:
            <span style="color: #008000;">self</span>.<span style="color: black;">cmd_success</span> = <span style="color: #008000;">False</span>
            <span style="color: #ff7700;font-weight:bold;">return</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">if</span> line == <span style="color: #483d8b;">'END'</span>:
            <span style="color: #808080; font-style: italic;"># join the response at the end of it</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">responseFinished</span><span style="color: black;">&#40;</span>
                <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">buffer</span><span style="color: black;">&#41;</span>, <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">buffer</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">buffer</span> = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #008000;">self</span>.<span style="color: black;">buffer</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>line<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> responseFinished<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, num_lines, data<span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># disconnect</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">sendLine</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'quit'</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">transport</span>.<span style="color: black;">loseConnection</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># send back the response to the REPL</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">factory</span>.<span style="color: black;">deferred</span>.<span style="color: black;">callback</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">cmd_success</span>, num_lines, data<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> CFactory<span style="color: black;">&#40;</span>protocol.<span style="color: black;">ClientFactory</span><span style="color: black;">&#41;</span>:
    protocol = Client
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #dc143c;">cmd</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: #dc143c;">cmd</span> = <span style="color: #dc143c;">cmd</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">deferred</span> = defer.<span style="color: black;">Deferred</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>


<p>How cool is that? Not really to be honest. It has a big gigantic fault: every time you input a line a connection to the server is opened and closed. That&#8217;s bad, really bad.</p>

<p>It didn&#8217;t take too long to create a version that use just one connection:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> connectionMade<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
    <span style="color: #008000;">self</span>.<span style="color: black;">sendLine</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Welcome to Console'</span><span style="color: black;">&#41;</span>
    <span style="color: #008000;">self</span>.<span style="color: black;">factory</span> = CFactory<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #008000;">self</span>.<span style="color: black;">connector</span> = reactor.<span style="color: black;">connectTCP</span><span style="color: black;">&#40;</span>
        <span style="color: #483d8b;">'127.0.0.1'</span>, <span style="color: #ff4500;">1234</span>, <span style="color: #008000;">self</span>.<span style="color: black;">factory</span><span style="color: black;">&#41;</span>
    <span style="color: #008000;">self</span>.<span style="color: black;">prompt</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>


<p>We store the connector and the factory. <em>issueCommand</em> does not open a connection anymore, just:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> issueCommand<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, command<span style="color: black;">&#41;</span>:
    <span style="color: #008000;">self</span>.<span style="color: black;">connector</span>.<span style="color: black;">transport</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%s%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>command, <span style="color: #008000;">self</span>.<span style="color: black;">delimiter</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: #008000;">self</span>.<span style="color: black;">factory</span>.<span style="color: black;">deferred</span>.<span style="color: black;">addCallback</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._checkResponse<span style="color: black;">&#41;</span></pre></div></div>


<p>We write directly to the transport of the connector (and not the one connected to the stdout) and register the callback on the factory&#8217;s deferred.</p>

<p>That&#8217;s better in my opinion and a nice start. I know that within <a href="http://twistedmatrix.com/documents/current/api/twisted.conch.stdio.html">twisted.conch.stdio</a> there&#8217;s something more evolved. I&#8217;ll try to look into it when I have more time.</p>

<p>You can find the <a href="http://share11.appspot.com/1022">first version</a> (bad) and the <a href="http://share11.appspot.com/1421">second version</a> (better) online.</p>

<p>What do you think about this try?</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/ASongForTheLovers?a=Crihg74U"><img src="http://feeds.feedburner.com/~f/ASongForTheLovers?i=Crihg74U" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/ASongForTheLovers?a=nb4FvOoR"><img src="http://feeds.feedburner.com/~f/ASongForTheLovers?i=nb4FvOoR" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ASongForTheLovers/~4/AahTGnljkv4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.oluyede.org/blog/2008/08/31/twisted-interactive-console/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.oluyede.org/blog/2008/08/31/twisted-interactive-console/</feedburner:origLink></item>
	</channel>
</rss>
