<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>Eli Bendersky's website</title>
	<atom:link href="http://eli.thegreenplace.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://eli.thegreenplace.net</link>
	<description>Eli Bendersky's personal website</description>
	<lastBuildDate>Wed, 25 Aug 2010 03:17:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Commenting out a block of code with Vim</title>
		<link>http://eli.thegreenplace.net/2010/08/25/commenting-out-a-block-of-code-with-vim/</link>
		<comments>http://eli.thegreenplace.net/2010/08/25/commenting-out-a-block-of-code-with-vim/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 03:17:56 +0000</pubDate>
		<dc:creator>eliben</dc:creator>
				<category><![CDATA[Software & Tools]]></category>

		<guid isPermaLink="false">http://eli.thegreenplace.net/?p=2273</guid>
		<description><![CDATA[After some looking-around I&#8217;ve found two interesting techniques to comment (or comment out) a block of code:
Substitution on a range of lines
Given a range of lines, a simple substitution command may add or remove comments. For example, for Python code s/^/#/ and s/^#// will add or remove a comment from the beginning of the line, [...]


Related posts:<ol><li><a href='http://eli.thegreenplace.net/2004/11/15/considerations-in-mixal-parsing/' rel='bookmark' title='Permanent Link: considerations in MIXAL parsing'>considerations in MIXAL parsing</a> <small>When Knuth designed the MIX assembly language (MIXAL), he didn&#8217;t...</small></li><li><a href='http://eli.thegreenplace.net/2008/10/14/parsing-c-more-on-line-directives/' rel='bookmark' title='Permanent Link: Parsing C: more on <code>#line</code> directives'>Parsing C: more on <code>#line</code> directives</a> <small>In a previous post I discussed a few issues that...</small></li><li><a href='http://eli.thegreenplace.net/2008/08/23/integrating-the-platform-sdk-into-ms-visual-c-express/' rel='bookmark' title='Permanent Link: Integrating the Platform SDK into MS Visual C++ Express'>Integrating the Platform SDK into MS Visual C++ Express</a> <small>As I wrote here, I&#8217;m using Microsoft&#8217;s free Visual C++...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>After some looking-around I&#8217;ve found two interesting techniques to comment (or comment out) a block of code:</p>
<p><strong>Substitution on a range of lines</strong></p>
<p>Given a range of lines, a simple substitution command may add or remove comments. For example, for Python code <tt class="docutils literal"><span class="pre">s/^/#/</span></tt> and <tt class="docutils literal"><span class="pre">s/^#//</span></tt> will add or remove a comment from the beginning of the line, respectively.</p>
<p>To make a range of lines for this operation you can use any Vim technique, like for example explicitly specifying the range:</p>
<div class="highlight">
<pre>:M,N s/^/#/
</pre>
</div>
<p>Will comment out lines in the inclusive range <tt class="docutils literal"><span class="pre">[M:N]</span></tt>.</p>
<p>A simpler way is to use the visual selection mode, by pressing <tt class="docutils literal"><span class="pre">V</span></tt> (capital <em>v</em> for line selection), selecting the needed lines and then executing the substitution command.</p>
<p><strong>Using block-mode visual selection</strong></p>
<ol class="arabic simple">
<li>Move to the first column in the first line you want to comment-out.</li>
<li>Press <tt class="docutils literal"><span class="pre">Ctrl-V</span></tt> to start block-mode selection.</li>
<li>Move down to select the first column of a block of lines.</li>
<li>Press <tt class="docutils literal"><span class="pre">I</span></tt> and then the desired comment starter (i.e. <tt class="docutils literal"><span class="pre">#</span></tt>)</li>
<li>Press <tt class="docutils literal"><span class="pre">ESC</span></tt> and the insertion will be applied to the whole block.</li>
</ol>
<p>To uncomment with this techniques follow the directions but instead of <tt class="docutils literal"><span class="pre">I</span></tt> use <tt class="docutils literal"><span class="pre">x</span></tt> to delete the first char.</p>
<p><strong>Others&#8230;</strong></p>
<p>If you have other techniques to suggest, please let me know. Also if you&#8217;re familiar with a good plugin that makes this really easy and also knows which types of source code require which comment chars, I&#8217;d like to hear about it.</p>
<img src="http://eli.thegreenplace.net/?ak_action=api_record_view&id=2273&type=feed" alt="" />

<p>Related posts:<ol><li><a href='http://eli.thegreenplace.net/2004/11/15/considerations-in-mixal-parsing/' rel='bookmark' title='Permanent Link: considerations in MIXAL parsing'>considerations in MIXAL parsing</a> <small>When Knuth designed the MIX assembly language (MIXAL), he didn&#8217;t...</small></li><li><a href='http://eli.thegreenplace.net/2008/10/14/parsing-c-more-on-line-directives/' rel='bookmark' title='Permanent Link: Parsing C: more on <code>#line</code> directives'>Parsing C: more on <code>#line</code> directives</a> <small>In a previous post I discussed a few issues that...</small></li><li><a href='http://eli.thegreenplace.net/2008/08/23/integrating-the-platform-sdk-into-ms-visual-c-express/' rel='bookmark' title='Permanent Link: Integrating the Platform SDK into MS Visual C++ Express'>Integrating the Platform SDK into MS Visual C++ Express</a> <small>As I wrote here, I&#8217;m using Microsoft&#8217;s free Visual C++...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://eli.thegreenplace.net/2010/08/25/commenting-out-a-block-of-code-with-vim/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Some problems installing Ubuntu 10.04 on VirtualBox</title>
		<link>http://eli.thegreenplace.net/2010/08/18/some-problems-installing-ubuntu-10-04-on-virtualbox/</link>
		<comments>http://eli.thegreenplace.net/2010/08/18/some-problems-installing-ubuntu-10-04-on-virtualbox/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 05:48:37 +0000</pubDate>
		<dc:creator>eliben</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://eli.thegreenplace.net/?p=2267</guid>
		<description><![CDATA[The HD space I allocated to my previous Ubuntu VM ran out, so instead of employing tricks to increase the HD, I decided to create a new VM and upgrade to 10.04 while I&#8217;m at it. All my data is quite easy to back-up and recover, and I&#8217;m still having the old VM around, just [...]


Related posts:<ol><li><a href='http://eli.thegreenplace.net/2010/03/27/running-several-oses-in-one-using-virtualbox/' rel='bookmark' title='Permanent Link: Running several OSes in one &#8211; using VirtualBox'>Running several OSes in one &#8211; using VirtualBox</a> <small>Being able to run a fully hosted OS in a...</small></li><li><a href='http://eli.thegreenplace.net/2007/08/11/hello-from-ubuntu-linux-704/' rel='bookmark' title='Permanent Link: Hello from Ubuntu Linux 7.04'>Hello from Ubuntu Linux 7.04</a> <small>I am writing this post from Ubuntu 7.04, running as...</small></li><li><a href='http://eli.thegreenplace.net/2008/10/20/installing-python-25-on-bluehost/' rel='bookmark' title='Permanent Link: Installing Python 2.5 on Bluehost'>Installing Python 2.5 on Bluehost</a> <small>Bluehost is my hosting provider for http://thegreenplace.net I&#8217;m generally quite...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>The HD space I allocated to my <a href="http://eli.thegreenplace.net/2010/03/27/running-several-oses-in-one-using-virtualbox/">previous Ubuntu VM</a> ran out, so instead of employing tricks to increase the HD, I decided to create a new VM and upgrade to 10.04 while I&#8217;m at it. All my data is quite easy to back-up and recover, and I&#8217;m still having the old VM around, just in case.</p>
<p>I downloaded a fresh 10.04 .iso from a torrent but it wouldn&#8217;t boot in VirtualBox. After selecting &#8220;Install Ubuntu&#8221; in the welcome screen it would just hang with an empty black screen.</p>
<p>What eventually solved the problem was installing a new version of VirtualBox (3.2.8, while previously I ran 3.0.12). Re-installing VirbualBox was a painful process since it decided it must disconnect me from the network and it took a reboot to cause my network to work again.</p>
<p>Once installed, however, VirtualBox 3.2.8 installed Ubuntu 10.04 smoothly, with network, shared folders and guest add-ons all working very well.</p>
<img src="http://eli.thegreenplace.net/?ak_action=api_record_view&id=2267&type=feed" alt="" />

<p>Related posts:<ol><li><a href='http://eli.thegreenplace.net/2010/03/27/running-several-oses-in-one-using-virtualbox/' rel='bookmark' title='Permanent Link: Running several OSes in one &#8211; using VirtualBox'>Running several OSes in one &#8211; using VirtualBox</a> <small>Being able to run a fully hosted OS in a...</small></li><li><a href='http://eli.thegreenplace.net/2007/08/11/hello-from-ubuntu-linux-704/' rel='bookmark' title='Permanent Link: Hello from Ubuntu Linux 7.04'>Hello from Ubuntu Linux 7.04</a> <small>I am writing this post from Ubuntu 7.04, running as...</small></li><li><a href='http://eli.thegreenplace.net/2008/10/20/installing-python-25-on-bluehost/' rel='bookmark' title='Permanent Link: Installing Python 2.5 on Bluehost'>Installing Python 2.5 on Bluehost</a> <small>Bluehost is my hosting provider for http://thegreenplace.net I&#8217;m generally quite...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://eli.thegreenplace.net/2010/08/18/some-problems-installing-ubuntu-10-04-on-virtualbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A new gaming addiction</title>
		<link>http://eli.thegreenplace.net/2010/08/14/a-new-gaming-addiction/</link>
		<comments>http://eli.thegreenplace.net/2010/08/14/a-new-gaming-addiction/#comments</comments>
		<pubDate>Sat, 14 Aug 2010 13:01:04 +0000</pubDate>
		<dc:creator>eliben</dc:creator>
				<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://eli.thegreenplace.net/?p=2259</guid>
		<description><![CDATA[And Blizzard is, once again, to blame for my complete lack of productivity lately.

Wow, what a game! Complete addiction (the kind when you have bunker deployment tactics in your dreams). And the worst part is that they&#8217;ve made it almost infinitely re-playable with a system of achievements. For example, today I&#8217;ve finished the main campaign:

But [...]


Related posts:<ol><li><a href='http://eli.thegreenplace.net/2004/12/30/gmails-to-give/' rel='bookmark' title='Permanent Link: gmails to give'>gmails to give</a> <small>If anyone is still without a Gmail account and in...</small></li><li><a href='http://eli.thegreenplace.net/2009/09/20/what-ive-been-up-to-recently/' rel='bookmark' title='Permanent Link: What I&#8217;ve been up to recently'>What I&#8217;ve been up to recently</a> <small>The blog hasn&#8217;t been abundant with content lately, as you&#8217;ve...</small></li><li><a href='http://eli.thegreenplace.net/2004/08/31/gmail-invitations/' rel='bookmark' title='Permanent Link: Gmail  invitations  ~!!'>Gmail  invitations  ~!!</a> <small>Hola amigos, I have 4 invitations left in Gmail, and...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>And Blizzard is, <a href="http://eli.thegreenplace.net/2009/09/20/what-ive-been-up-to-recently/">once again</a>, to blame for my complete lack of productivity lately.</p>
<p><img src="http://eli.thegreenplace.net/wp-content/uploads/2010/08/sc2_logo.png" alt="" title="sc2_logo" width="353" height="159" class="alignnone size-full wp-image-2261" /></p>
<p>Wow, what a game! Complete addiction (the kind when you have bunker deployment tactics in your dreams). And the worst part is that they&#8217;ve made it almost infinitely re-playable with a system of achievements. For example, today I&#8217;ve finished the main campaign:</p>
<p><img src="http://eli.thegreenplace.net/wp-content/uploads/2010/08/sc2_finish_achievement.png" alt="" title="sc2_finish_achievement" width="311" height="54" class="alignnone size-full wp-image-2260" /></p>
<p>But I can&#8217;t help thinking about going through the challenges, trying some missed-choice missions in the campaign, and even engaging in multi-player. By the way, my battle.net Real ID is my email: <code>eliben@gmail.com</code>. </p>
<p>P.S. Ron, I know you want to.</p>
<img src="http://eli.thegreenplace.net/?ak_action=api_record_view&id=2259&type=feed" alt="" />

<p>Related posts:<ol><li><a href='http://eli.thegreenplace.net/2004/12/30/gmails-to-give/' rel='bookmark' title='Permanent Link: gmails to give'>gmails to give</a> <small>If anyone is still without a Gmail account and in...</small></li><li><a href='http://eli.thegreenplace.net/2009/09/20/what-ive-been-up-to-recently/' rel='bookmark' title='Permanent Link: What I&#8217;ve been up to recently'>What I&#8217;ve been up to recently</a> <small>The blog hasn&#8217;t been abundant with content lately, as you&#8217;ve...</small></li><li><a href='http://eli.thegreenplace.net/2004/08/31/gmail-invitations/' rel='bookmark' title='Permanent Link: Gmail  invitations  ~!!'>Gmail  invitations  ~!!</a> <small>Hola amigos, I have 4 invitations left in Gmail, and...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://eli.thegreenplace.net/2010/08/14/a-new-gaming-addiction/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Contributing to Python</title>
		<link>http://eli.thegreenplace.net/2010/07/23/contributing-to-python/</link>
		<comments>http://eli.thegreenplace.net/2010/07/23/contributing-to-python/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 15:07:43 +0000</pubDate>
		<dc:creator>eliben</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://eli.thegreenplace.net/?p=2253</guid>
		<description><![CDATA[I&#8217;ve been involved in open-source projects almost since the first days of my &#34;serious&#34; programming (back in 1998), but these were always projects I started myself. I&#8217;ve long been thinking about joining one of the big and established open-source projects, both to make a contribution and to improve my own skills by working with some [...]


Related posts:<ol><li><a href='http://eli.thegreenplace.net/2009/03/13/python-documentation-annoyance/' rel='bookmark' title='Permanent Link: Python documentation annoyance'>Python documentation annoyance</a> <small>Edit: I&#8217;ve actually started working on fixing this annoyance in...</small></li><li><a href='http://eli.thegreenplace.net/2010/05/22/migrating-my-personal-projects-to-mercurial/' rel='bookmark' title='Permanent Link: Migrating my personal projects to Mercurial'>Migrating my personal projects to Mercurial</a> <small> Introduction My first acquaintance with version control was soon...</small></li><li><a href='http://eli.thegreenplace.net/2008/06/27/creating-python-extension-modules-in-c/' rel='bookmark' title='Permanent Link: Creating Python extension modules in C'>Creating Python extension modules in C</a> <small>I&#8217;ve successfully created a C extension for Python, basically following...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been involved in open-source projects almost since the first days of my &quot;serious&quot; programming (back in 1998), but these were always projects I started myself. I&#8217;ve long been thinking about joining one of the big and established open-source projects, both to make a contribution and to improve my own skills by working with some great people on interesting things.</p>
<p>Once I started tinkering with Python <a class="reference external" href="http://eli.thegreenplace.net/2008/05/14/python/">around two years ago</a>, it became the major candidate for my contribution &#8211; both because working on to Python can really make a difference for a huge amount of users, and because Python&#8217;s inner development circles include some of the brightest programmers I ever ran into. Joining this clique, even as a humble minor contributor, is very appealing.</p>
<p>So, a few weeks ago, inspired a <a class="reference external" href="http://jessenoller.com/2010/04/22/why-arent-you-contributing-to-python">couple</a> of <a class="reference external" href="http://tech.blog.aknin.name/2010/04/08/contributing-to-python/">articles</a>, I&#8217;ve finally made the plunge.</p>
<div align="center" class="align-center"><img alt="http://eli.thegreenplace.net/wp-content/uploads/2010/07/smilingpython.gif" class="align-center" src="http://eli.thegreenplace.net/wp-content/uploads/2010/07/smilingpython.gif" /></div>
<p>For now, my contributions are very minor: I&#8217;ve been involved in a few <a class="reference external" href="http://bugs.python.org/">issues</a>, and made several patches. A few were even committed into Python &#8211; one <a class="reference external" href="http://bugs.python.org/issue9132">documentation patch</a> and  <a class="reference external" href="http://bugs.python.org/issue9282">two</a> <a class="reference external" href="http://bugs.python.org/issue9323">patches</a> fixing bugs in the <tt class="docutils literal"><span class="pre">trace.py</span></tt> module in Python 3.x</p>
<p>I&#8217;m also &quot;in progress&quot; on several other issues, dealing with the <tt class="docutils literal"><span class="pre">trace.py</span></tt> module (improving its documentation, adding unit tests and debugging some issues with 3.x), documentation fixes for some standard library modules and a bug fix for <tt class="docutils literal"><span class="pre">difflib</span></tt>. Once you make the first step, finding more things to work on is quite easy. Python&#8217;s code and documentation are of relatively high quality, but like in any major software project, there&#8217;s place for improvement almost everywhere you look, even if the improvements are very minor (making the documentation more consistently formatted or clearer).</p>
<p>A few words on how I work on Python.</p>
<p>Although Python is well-supported on Windows and can be built on it without much trouble, Linux is the most convenient platform to use for development IMO. I&#8217;m using a <a class="reference external" href="http://eli.thegreenplace.net/2010/03/27/running-several-oses-in-one-using-virtualbox/">Ubuntu VM running on VirtualBox</a> on top of my Windows XP machine.</p>
<p>Python&#8217;s code is kept in a <a class="reference external" href="http://svn.python.org/view/">Subversion repository</a>, to which you can get a read-only access when you&#8217;re not a core committer. It means you can&#8217;t really interact with the repository, and if you want to save your temporary work, you&#8217;re on your own.</p>
<p>Luckily, Python is in the process of moving to Mercurial, and already has a <a class="reference external" href="http://code.python.org/hg">functional mirror</a> set up. Mercurial is a much better SCM tool for this purpose, because it allows you to work locally with your repository, only pulling changes from the official one when necessary.</p>
<p>Here&#8217;s my workflow with the Mercurial mirror of Python:</p>
<div align="center" class="align-center"><img alt="http://eli.thegreenplace.net/wp-content/uploads/2010/07/pythonrepos.png" class="align-center" src="http://eli.thegreenplace.net/wp-content/uploads/2010/07/pythonrepos.png" /></div>
<p>My local Mercurial repo is where I do all my hacking, occasionally backing-up to my personal clone at <tt class="docutils literal"><span class="pre">code.google.com</span></tt>. This lets me explore various ideas, create temporary fixes, all of this with full version control. From time to time, I&#8217;m pulling a fresh snapshot from Python&#8217;s official Mercurial mirror to get back on track, but I will always be able to get back to my own changes, because everything is safely stored in the history of my repo.</p>
<p>However, I still keep the SVN checkouts around, because:</p>
<ol class="arabic simple">
<li>I want to make sure my changes work on a clean check-out from Python&#8217;s official repository, which is still SVN.</li>
<li>I create patches against the SVN repo (with <tt class="docutils literal"><span class="pre">svn</span> <span class="pre">diff</span></tt>), because Mercurial creates slightly different diffs. Since committers actually commit into the SVN repo, this makes their lives easier.</li>
</ol>
<p>It&#8217;s easy to keep several versions of Python around. For example, I have the repositories for the 3.x development branch (both Mercurial for hacking and SVN for patches), plus the 2.7 and 2.6 maintenance branches. To get a new version/branch all one needs is:</p>
<ol class="arabic simple">
<li>Check it out from SVN or clone from Mercurial</li>
<li><tt class="docutils literal"><span class="pre">configure</span></tt> and then <tt class="docutils literal"><span class="pre">make</span></tt></li>
<li>Create a link somewhere on <tt class="docutils literal"><span class="pre">PATH</span></tt> to the relevant executable (for example I have in <tt class="docutils literal"><span class="pre">~/bin</span></tt> a link named <tt class="docutils literal"><span class="pre">py27</span></tt> for the 2.7 version, <tt class="docutils literal"><span class="pre">py3d</span></tt> for the debug build of the latest 3.x, and so on). The Python interpreter, once executed, knows where to find its own libraries, making it very simple to work with several versions of Python simultaneously.</li>
</ol>
<p>To conclude, now you know what&#8217;s been keeping me busy in the past month or so. Contributing to Python is something I&#8217;ve long wanted doing, and I&#8217;m happy that I finally started. It turned out to be much less difficult than I originally expected, and I now firmly believe that any competent developer with the desire to help and some free time on his hands can become a contributor.</p>
<p><strong>P.S.</strong> I had the privilege of receiving useful guidance from Terry Reedy, and I&#8217;d like to thank him for that. We still cooperate on several issues, and I hope we&#8217;ll continue working together. &quot;Pair-contribution&quot; seems like an interesting model the Python community may want to look into. I also want to thank Alexander Belopolsky for getting my fixes for <tt class="docutils literal"><span class="pre">trace.py</span></tt> quickly committed.</p>
<img src="http://eli.thegreenplace.net/?ak_action=api_record_view&id=2253&type=feed" alt="" />

<p>Related posts:<ol><li><a href='http://eli.thegreenplace.net/2009/03/13/python-documentation-annoyance/' rel='bookmark' title='Permanent Link: Python documentation annoyance'>Python documentation annoyance</a> <small>Edit: I&#8217;ve actually started working on fixing this annoyance in...</small></li><li><a href='http://eli.thegreenplace.net/2010/05/22/migrating-my-personal-projects-to-mercurial/' rel='bookmark' title='Permanent Link: Migrating my personal projects to Mercurial'>Migrating my personal projects to Mercurial</a> <small> Introduction My first acquaintance with version control was soon...</small></li><li><a href='http://eli.thegreenplace.net/2008/06/27/creating-python-extension-modules-in-c/' rel='bookmark' title='Permanent Link: Creating Python extension modules in C'>Creating Python extension modules in C</a> <small>I&#8217;ve successfully created a C extension for Python, basically following...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://eli.thegreenplace.net/2010/07/23/contributing-to-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enhorabuena a España</title>
		<link>http://eli.thegreenplace.net/2010/07/12/enhorabuena-a-espana/</link>
		<comments>http://eli.thegreenplace.net/2010/07/12/enhorabuena-a-espana/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 13:42:11 +0000</pubDate>
		<dc:creator>eliben</dc:creator>
				<category><![CDATA[Miscellanea]]></category>

		<guid isPermaLink="false">http://eli.thegreenplace.net/?p=2244</guid>
		<description><![CDATA[It was a tough game against Holland&#8217;s karate^H^H^H^H^H&#8230; err, football team, but Spain deserved to win. 
Earlier this year my brother and I went to Barcelona where we saw this in the window of some bank:

It says that it will provide a 3% yearly revenue on some kind of long-term deposit, and will increase the [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>It was a tough game against Holland&#8217;s karate^H^H^H^H^H&#8230; err, football team, but Spain deserved to win. </p>
<p>Earlier this year my brother and I went to Barcelona where we saw this in the window of some bank:</p>
<p><img src="http://eli.thegreenplace.net/wp-content/uploads/2010/07/espana_deposito_2010.jpg" alt="" title="espana_deposito_2010" width="440" height="582" class="alignnone size-full wp-image-2245" /></p>
<p>It says that it will provide a 3% yearly revenue on some kind of long-term deposit, and will increase the revenue to 4% if Spain gains the world cup. This is what sports fanaticism looks like!</p>
<img src="http://eli.thegreenplace.net/?ak_action=api_record_view&id=2244&type=feed" alt="" />

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://eli.thegreenplace.net/2010/07/12/enhorabuena-a-espana/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Summary of reading: May &#8211; June 2010</title>
		<link>http://eli.thegreenplace.net/2010/07/08/summary-of-reading-may-june-2010/</link>
		<comments>http://eli.thegreenplace.net/2010/07/08/summary-of-reading-may-june-2010/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 17:33:37 +0000</pubDate>
		<dc:creator>eliben</dc:creator>
				<category><![CDATA[Book reviews]]></category>

		<guid isPermaLink="false">http://eli.thegreenplace.net/?p=2237</guid>
		<description><![CDATA[Recently writing a full review for each and every book I read has become tiresome, so I&#8217;m changing the approach. Once in a few months I&#8217;m going to post the list of books I&#8217;ve read and re-read in that period, with very short reviews (up to a few sentences). Certain books may encourage me to [...]


Related posts:<ol><li><a href='http://eli.thegreenplace.net/2007/05/15/quality-reading-instead-of-quantity-reading/' rel='bookmark' title='Permanent Link: quality reading instead of quantity reading'>quality reading instead of quantity reading</a> <small>Lately I have a bad feeling about my reading patterns....</small></li><li><a href='http://eli.thegreenplace.net/2009/10/14/book-review-travels-with-charley-in-search-of-america-by-john-steinbeck/' rel='bookmark' title='Permanent Link: Book review: &#8220;Travels with Charley in search of America&#8221; by John Steinbeck'>Book review: &#8220;Travels with Charley in search of America&#8221; by John Steinbeck</a> <small>In 1960, John Steinbeck decided that he can&#8217;t keep writing...</small></li><li><a href='http://eli.thegreenplace.net/2006/03/17/book-review-reading-lolita-in-tehran-by-azar-nafisi/' rel='bookmark' title='Permanent Link: Book review: &#8220;Reading Lolita in Tehran&#8221; by Azar Nafisi'>Book review: &#8220;Reading Lolita in Tehran&#8221; by Azar Nafisi</a> <small>This book is a mixture of an auto-biography, history, literary...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Recently writing a full review for <a href="http://eli.thegreenplace.net/category/book-reviews/">each and every book</a> I read has become tiresome, so I&#8217;m changing the approach. Once in a few months I&#8217;m going to post the list of books I&#8217;ve read and re-read in that period, with very short reviews (up to a few sentences). Certain books may encourage me to write fuller reviews, which I&#8217;ll just do in the usual manner.</p>
<p>So, for May &#8211; June 2010 the list is:</p>
<ul class="simple">
<li>&quot;On Writing Well&quot; by William Zinsser &#8211; A good book on improving one&#8217;s writing skills.</li>
<li>&quot;Burning Bright&quot; by John Steinbeck &#8211; An unusual short story structured as a play. Quick and fun to read.</li>
<li>&quot;The Solitude of Prime Numbers&quot; by Paolo Giordano (read in Spanish) &#8211; a sad story, beautifully written. Though rough-edged in some places, this book was very enjoyable.</li>
<li>&quot;Sweet Thursday&quot; by John Steinbeck &#8211; Sequel to &quot;Cannery Row&quot;. Though somewhat less original, it&#8217;s still fun to read.</li>
</ul>
<p>Re-reads (books I&#8217;ve already read in the past, and have recently re-read):</p>
<ul class="simple">
<li>&#8220;Programming Pearls&#8221; by Jon Bentley</li>
<li>&#8220;The Moral Animal&#8221; by Robert Wright</li>
</ul>
<img src="http://eli.thegreenplace.net/?ak_action=api_record_view&id=2237&type=feed" alt="" />

<p>Related posts:<ol><li><a href='http://eli.thegreenplace.net/2007/05/15/quality-reading-instead-of-quantity-reading/' rel='bookmark' title='Permanent Link: quality reading instead of quantity reading'>quality reading instead of quantity reading</a> <small>Lately I have a bad feeling about my reading patterns....</small></li><li><a href='http://eli.thegreenplace.net/2009/10/14/book-review-travels-with-charley-in-search-of-america-by-john-steinbeck/' rel='bookmark' title='Permanent Link: Book review: &#8220;Travels with Charley in search of America&#8221; by John Steinbeck'>Book review: &#8220;Travels with Charley in search of America&#8221; by John Steinbeck</a> <small>In 1960, John Steinbeck decided that he can&#8217;t keep writing...</small></li><li><a href='http://eli.thegreenplace.net/2006/03/17/book-review-reading-lolita-in-tehran-by-azar-nafisi/' rel='bookmark' title='Permanent Link: Book review: &#8220;Reading Lolita in Tehran&#8221; by Azar Nafisi'>Book review: &#8220;Reading Lolita in Tehran&#8221; by Azar Nafisi</a> <small>This book is a mixture of an auto-biography, history, literary...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://eli.thegreenplace.net/2010/07/08/summary-of-reading-may-june-2010/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Python internals: adding a new statement to Python</title>
		<link>http://eli.thegreenplace.net/2010/06/30/python-internals-adding-a-new-statement-to-python/</link>
		<comments>http://eli.thegreenplace.net/2010/06/30/python-internals-adding-a-new-statement-to-python/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 17:18:35 +0000</pubDate>
		<dc:creator>eliben</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://eli.thegreenplace.net/?p=2231</guid>
		<description><![CDATA[This article is an attempt to better understand how the front-end of Python works. Just reading documentation and source code may be a bit boring, so I&#8217;m taking a hands-on approach here: I&#8217;m going to add an until statement to Python.
All the coding for this article was done against the cutting-edge Py3k branch in the [...]


Related posts:<ol><li><a href='http://eli.thegreenplace.net/2009/11/28/python-internals-working-with-python-asts/' rel='bookmark' title='Permanent Link: Python internals: Working with Python ASTs'>Python internals: Working with Python ASTs</a> <small> Starting with Python 2.5, the Python compiler (the part...</small></li><li><a href='http://eli.thegreenplace.net/2009/02/16/abstract-vs-concrete-syntax-trees/' rel='bookmark' title='Permanent Link: Abstract vs. Concrete Syntax Trees'>Abstract vs. Concrete Syntax Trees</a> <small>CSTs &#8211; Concrete Syntax Trees (a.k.a. Parse Trees) and ASTs...</small></li><li><a href='http://eli.thegreenplace.net/2008/07/11/asts-for-analyzing-c/' rel='bookmark' title='Permanent Link: ASTs for analyzing C'>ASTs for analyzing C</a> <small>As I wrote here, I&#8217;ve commonly found myself in the...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>This article is an attempt to better understand how the front-end of Python works. Just reading documentation and source code may be a bit boring, so I&#8217;m taking a hands-on approach here: I&#8217;m going to add an <tt class="docutils literal"><span class="pre">until</span></tt> statement to Python.</p>
<p>All the coding for this article was done against the cutting-edge Py3k branch in the <a class="reference external" href="http://code.python.org/hg/branches/py3k/">Python Mercurial repository mirror</a>.</p>
<div class="section" id="the-until-statement">
<h3>The <tt class="docutils literal"><span class="pre">until</span></tt> statement</h3>
<p>Some languages, like Ruby, have an <tt class="docutils literal"><span class="pre">until</span></tt> statement, which is the complement to <tt class="docutils literal"><span class="pre">while</span></tt> (<tt class="docutils literal"><span class="pre">until</span> <span class="pre">num</span> <span class="pre">==</span> <span class="pre">0</span></tt> is equivalent to <tt class="docutils literal"><span class="pre">while</span> <span class="pre">num</span> <span class="pre">!=</span> <span class="pre">0</span></tt>). In Ruby, I can write:</p>
<div class="highlight">
<pre>num = <span style="color: #007f7f">3</span>
<span style="color: #00007f; font-weight: bold">until</span> num == <span style="color: #007f7f">0</span> <span style="color: #00007f; font-weight: bold">do</span>
  <span style="color: #00007f">puts</span> num
  num -= <span style="color: #007f7f">1</span>
<span style="color: #00007f; font-weight: bold">end</span>
</pre>
</div>
<p>And it will print:</p>
<div class="highlight">
<pre>3
2
1
</pre>
</div>
<p>So, I want to add a similar capability to Python. That is, being able to write:</p>
<div class="highlight">
<pre>num = <span style="color: #007f7f">3</span>
until num == <span style="color: #007f7f">0</span>:
  <span style="color: #00007f; font-weight: bold">print</span>(num)
  num -= <span style="color: #007f7f">1</span>
</pre>
</div>
</div>
<div class="section" id="a-language-advocacy-digression">
<h3>A language-advocacy digression</h3>
<p>This article doesn&#8217;t attempt to suggest the addition of an <tt class="docutils literal"><span class="pre">until</span></tt> statement to Python. Although I think such a statement would make some code clearer, and this article displays how easy it is to add, I completely respect Python&#8217;s philosophy of minimalism. All I&#8217;m trying to do here, really, is gain some insight into the inner workings of Python.</p>
</div>
<div class="section" id="modifying-the-grammar">
<h3>Modifying the grammar</h3>
<p>Python uses a custom parser generator named <tt class="docutils literal"><span class="pre">pgen</span></tt>. This is a LL(1) parser that converts Python source code into a parse tree. The input to the parser generator is the file <tt class="docutils literal"><span class="pre">Grammar/Grammar</span></tt> <a class="footnote-reference" href="#id4" id="id1">[1]</a>. This is a simple text file that specifies the grammar of Python.</p>
<p>Two modifications have to be made to the grammar file. The first is to add a definition for the <tt class="docutils literal"><span class="pre">until</span></tt> statement. I found where the <tt class="docutils literal"><span class="pre">while</span></tt> statement was defined (<tt class="docutils literal"><span class="pre">while_stmt</span></tt>), and added <tt class="docutils literal"><span class="pre">until_stmt</span></tt> below <a class="footnote-reference" href="#id5" id="id2">[2]</a>:</p>
<div class="highlight">
<pre>compound_stmt: if_stmt | while_stmt | until_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated
if_stmt: &#39;if&#39; test &#39;:&#39; suite (&#39;elif&#39; test &#39;:&#39; suite)* [&#39;else&#39; &#39;:&#39; suite]
while_stmt: &#39;while&#39; test &#39;:&#39; suite [&#39;else&#39; &#39;:&#39; suite]
until_stmt: &#39;until&#39; test &#39;:&#39; suite
</pre>
</div>
<p>Note that I&#8217;ve decided to exclude the <tt class="docutils literal"><span class="pre">else</span></tt> clause from my definition of <tt class="docutils literal"><span class="pre">until</span></tt>, just to make it a little bit different (and because frankly I dislike the <tt class="docutils literal"><span class="pre">else</span></tt> clause of loops and don&#8217;t think it fits well with the Zen of Python).</p>
<p>The second change is to modify the rule for <tt class="docutils literal"><span class="pre">compound_stmt</span></tt> to include <tt class="docutils literal"><span class="pre">until_stmt</span></tt>, as you can see in the snippet above. It&#8217;s right after <tt class="docutils literal"><span class="pre">while_stmt</span></tt>, again.</p>
<p>When you run <tt class="docutils literal"><span class="pre">make</span></tt> after modifying <tt class="docutils literal"><span class="pre">Grammar/Grammar</span></tt>, notice that the <tt class="docutils literal"><span class="pre">pgen</span></tt> program is run to re-generate <tt class="docutils literal"><span class="pre">Include/graminit.h</span></tt> and <tt class="docutils literal"><span class="pre">Python/graminit.c</span></tt>, and then several files get re-compiled.</p>
</div>
<div class="section" id="modifying-the-ast-generation-code">
<h3>Modifying the AST generation code</h3>
<p>After the Python parser has created a parse tree, this tree is converted into an AST, since ASTs are <a class="reference external" href="http://eli.thegreenplace.net/2009/02/16/abstract-vs-concrete-syntax-trees/">much simpler to work with</a> in subsequent stages of the compilation process.</p>
<p>So, we&#8217;re going to visit <tt class="docutils literal"><span class="pre">Parser/Python.asdl</span></tt> which defines the structure of Python&#8217;s ASTs and add an AST node for our new <tt class="docutils literal"><span class="pre">until</span></tt> statement, again right below the <tt class="docutils literal"><span class="pre">while</span></tt>:</p>
<div class="highlight">
<pre>| While(expr test, stmt* body, stmt* orelse)
| Until(expr test, stmt* body)
</pre>
</div>
<p>If you now run <tt class="docutils literal"><span class="pre">make</span></tt>, notice that before compiling a bunch of files, <tt class="docutils literal"><span class="pre">Parser/asdl_c.py</span></tt> is run to generate C code from the AST definition file. This (like <tt class="docutils literal"><span class="pre">Grammar/Grammar</span></tt>) is another example of the Python source-code using a mini-language (in other words, a DSL) to simplify programming. Also note that since <tt class="docutils literal"><span class="pre">Parser/asdl_c.py</span></tt> is a Python script, this is a kind of <a class="reference external" href="http://en.wikipedia.org/wiki/Bootstrapping_%28compilers%29">bootstrapping</a> &#8211; to build Python from scratch, Python already has to be available.</p>
<p>While <tt class="docutils literal"><span class="pre">Parser/asdl_c.py</span></tt> generated the code to manage our newly defined AST node (into the files <tt class="docutils literal"><span class="pre">Include/Python-ast.h</span></tt> and <tt class="docutils literal"><span class="pre">Python/Python-ast.c</span></tt>), we still have to write the code that converts a relevant parse-tree node into it by hand. This is done in the file <tt class="docutils literal"><span class="pre">Python/ast.c</span></tt>. There, a function named <tt class="docutils literal"><span class="pre">ast_for_stmt</span></tt> converts parse tree nodes for statements into AST nodes. Again, guided by our old friend <tt class="docutils literal"><span class="pre">while</span></tt>, we jump right into the big <tt class="docutils literal"><span class="pre">switch</span></tt> for handling compound statements and add a clause for <tt class="docutils literal"><span class="pre">until_stmt</span></tt>:</p>
<div class="highlight">
<pre><span style="color: #00007f; font-weight: bold">case</span> while_stmt:
    <span style="color: #00007f; font-weight: bold">return</span> ast_for_while_stmt(c, ch);
<span style="color: #00007f; font-weight: bold">case</span> until_stmt:
    <span style="color: #00007f; font-weight: bold">return</span> ast_for_until_stmt(c, ch);
</pre>
</div>
<p>Now we should implement <tt class="docutils literal"><span class="pre">ast_for_until_stmt</span></tt>. Here it is:</p>
<div class="highlight">
<pre><span style="color: #00007f; font-weight: bold">static</span> stmt_ty
<span style="color: #00007f">ast_for_until_stmt</span>(<span style="color: #00007f; font-weight: bold">struct</span> compiling *c, <span style="color: #00007f; font-weight: bold">const</span> node *n)
{
    <span style="color: #007f00">/* until_stmt: &#39;until&#39; test &#39;:&#39; suite */</span>
    REQ(n, until_stmt);

    <span style="color: #00007f; font-weight: bold">if</span> (NCH(n) == <span style="color: #007f7f">4</span>) {
        expr_ty expression;
        asdl_seq *suite_seq;

        expression = ast_for_expr(c, CHILD(n, <span style="color: #007f7f">1</span>));
        <span style="color: #00007f; font-weight: bold">if</span> (!expression)
            <span style="color: #00007f; font-weight: bold">return</span> <span style="color: #00007f">NULL</span>;
        suite_seq = ast_for_suite(c, CHILD(n, <span style="color: #007f7f">3</span>));
        <span style="color: #00007f; font-weight: bold">if</span> (!suite_seq)
            <span style="color: #00007f; font-weight: bold">return</span> <span style="color: #00007f">NULL</span>;
        <span style="color: #00007f; font-weight: bold">return</span> Until(expression, suite_seq, LINENO(n), n-&gt;n_col_offset, c-&gt;c_arena);
    }

    PyErr_Format(PyExc_SystemError,
                 <span style="color: #7f007f">&quot;wrong number of tokens for &#39;until&#39; statement: %d&quot;</span>,
                 NCH(n));
    <span style="color: #00007f; font-weight: bold">return</span> <span style="color: #00007f">NULL</span>;
}
</pre>
</div>
<p>Again, this was coded while closely looking at the equivalent <tt class="docutils literal"><span class="pre">ast_for_while_stmt</span></tt>, with the difference that for <tt class="docutils literal"><span class="pre">until</span></tt> I&#8217;ve decided not to support the <tt class="docutils literal"><span class="pre">else</span></tt> clause. As expected, the AST is created recursively, using other AST creating functions like <tt class="docutils literal"><span class="pre">ast_for_expr</span></tt> for the condition expression and <tt class="docutils literal"><span class="pre">ast_for_suite</span></tt> for the body of the <tt class="docutils literal"><span class="pre">until</span></tt> statement. Finally, a new node named <tt class="docutils literal"><span class="pre">Until</span></tt> is returned.</p>
<p>Note that we access the parse-tree node <tt class="docutils literal"><span class="pre">n</span></tt> using some macros like <tt class="docutils literal"><span class="pre">NCH</span></tt> and <tt class="docutils literal"><span class="pre">CHILD</span></tt>. These are worth understanding &#8211; their code is in <tt class="docutils literal"><span class="pre">Include/node.h</span></tt>.</p>
</div>
<div class="section" id="digression-ast-composition">
<h3>Digression: AST composition</h3>
<p>I chose to create a new type of AST for the <tt class="docutils literal"><span class="pre">until</span></tt> statement, but actually this isn&#8217;t necessary. I could&#8217;ve saved some work and implemented the new functionality using composition of existing AST nodes, since:</p>
<div class="highlight">
<pre>until condition:
   <span style="color: #007f00"># do stuff</span>
</pre>
</div>
<p>Is functionally equivalent to:</p>
<div class="highlight">
<pre><span style="color: #00007f; font-weight: bold">while</span> <span style="color: #0000aa">not</span> condition:
  <span style="color: #007f00"># do stuff</span>
</pre>
</div>
<p>Instead of creating the <tt class="docutils literal"><span class="pre">Until</span></tt> node in <tt class="docutils literal"><span class="pre">ast_for_until_stmt</span></tt>, I could have created a <tt class="docutils literal"><span class="pre">Not</span></tt> node with an <tt class="docutils literal"><span class="pre">While</span></tt> node as a child. Since the AST compiler already knows how to handle these nodes, the next steps of the process could be skipped.</p>
</div>
<div class="section" id="compiling-asts-into-bytecode">
<h3>Compiling ASTs into bytecode</h3>
<p>The next step is compiling the AST into Python bytecode. The compilation has an intermediate result which is a CFG (Control Flow Graph), but since the same code handles it I will ignore this detail for now and leave it for another article.</p>
<p>The code we will look at next is <tt class="docutils literal"><span class="pre">Python/compile.c</span></tt>. Following the lead of <tt class="docutils literal"><span class="pre">while</span></tt>, we find the function <tt class="docutils literal"><span class="pre">compiler_visit_stmt</span></tt>, which is responsible for compiling statements into bytecode. We add a clause for <tt class="docutils literal"><span class="pre">Until</span></tt>:</p>
<div class="highlight">
<pre><span style="color: #00007f; font-weight: bold">case</span> While_kind:
    <span style="color: #00007f; font-weight: bold">return</span> compiler_while(c, s);
<span style="color: #00007f; font-weight: bold">case</span> Until_kind:
    <span style="color: #00007f; font-weight: bold">return</span> compiler_until(c, s);
</pre>
</div>
<p>If you wonder what <tt class="docutils literal"><span class="pre">Until_kind</span></tt> is, it&#8217;s a constant (actually a value of the <tt class="docutils literal"><span class="pre">_stmt_kind</span></tt> enumeration) automatically generated from the AST definition file into <tt class="docutils literal"><span class="pre">Include/Python-ast.h</span></tt>. Anyway, we call <tt class="docutils literal"><span class="pre">compiler_until</span></tt> which, of course, still doesn&#8217;t exist. I&#8217;ll get to it an a moment.</p>
<p>If you&#8217;re curious like me, you&#8217;ll notice that <tt class="docutils literal"><span class="pre">compiler_visit_stmt</span></tt> is peculiar. No amount of <tt class="docutils literal"><span class="pre">grep</span></tt>-ping the source tree reveals where it is called. When this is the case, only one option remains &#8211; C macro-fu. Indeed, a short investigation leads us to the <tt class="docutils literal"><span class="pre">VISIT</span></tt> macro defined in <tt class="docutils literal"><span class="pre">Python/compile.c</span></tt>:</p>
<div class="highlight">
<pre><span style="color: #007f00">#define VISIT(C, TYPE, V) {\</span>
<span style="color: #007f00">    if (!compiler_visit_ ## TYPE((C), (V))) \</span>
<span style="color: #007f00">        return 0; \</span>
</pre>
</div>
<p>It&#8217;s used to invoke <tt class="docutils literal"><span class="pre">compiler_visit_stmt</span></tt> in <tt class="docutils literal"><span class="pre">compiler_body</span></tt>. Back to our business, however&#8230;</p>
<p>As promised, here&#8217;s <tt class="docutils literal"><span class="pre">compiler_until</span></tt>:</p>
<div class="highlight">
<pre><span style="color: #00007f; font-weight: bold">static</span> <span style="color: #00007f; font-weight: bold">int</span>
<span style="color: #00007f">compiler_until</span>(<span style="color: #00007f; font-weight: bold">struct</span> compiler *c, stmt_ty s)
{
    basicblock *loop, *end, *anchor = <span style="color: #00007f">NULL</span>;
    <span style="color: #00007f; font-weight: bold">int</span> constant = expr_constant(s-&gt;v.Until.test);

    <span style="color: #00007f; font-weight: bold">if</span> (constant == <span style="color: #007f7f">1</span>) {
        <span style="color: #00007f; font-weight: bold">return</span> <span style="color: #007f7f">1</span>;
    }
    loop = compiler_new_block(c);
    end = compiler_new_block(c);
    <span style="color: #00007f; font-weight: bold">if</span> (constant == -<span style="color: #007f7f">1</span>) {
        anchor = compiler_new_block(c);
        <span style="color: #00007f; font-weight: bold">if</span> (anchor == <span style="color: #00007f">NULL</span>)
            <span style="color: #00007f; font-weight: bold">return</span> <span style="color: #007f7f">0</span>;
    }
    <span style="color: #00007f; font-weight: bold">if</span> (loop == <span style="color: #00007f">NULL</span> || end == <span style="color: #00007f">NULL</span>)
        <span style="color: #00007f; font-weight: bold">return</span> <span style="color: #007f7f">0</span>;

    ADDOP_JREL(c, SETUP_LOOP, end);
    compiler_use_next_block(c, loop);
    <span style="color: #00007f; font-weight: bold">if</span> (!compiler_push_fblock(c, LOOP, loop))
        <span style="color: #00007f; font-weight: bold">return</span> <span style="color: #007f7f">0</span>;
    <span style="color: #00007f; font-weight: bold">if</span> (constant == -<span style="color: #007f7f">1</span>) {
        VISIT(c, expr, s-&gt;v.Until.test);
        ADDOP_JABS(c, POP_JUMP_IF_TRUE, anchor);
    }
    VISIT_SEQ(c, stmt, s-&gt;v.Until.body);
    ADDOP_JABS(c, JUMP_ABSOLUTE, loop);

    <span style="color: #00007f; font-weight: bold">if</span> (constant == -<span style="color: #007f7f">1</span>) {
        compiler_use_next_block(c, anchor);
        ADDOP(c, POP_BLOCK);
    }
    compiler_pop_fblock(c, LOOP, loop);
    compiler_use_next_block(c, end);

    <span style="color: #00007f; font-weight: bold">return</span> <span style="color: #007f7f">1</span>;
}
</pre>
</div>
<p>I have a confession to make: this code wasn&#8217;t written based on a deep understanding of Python bytecode. Like the rest of the article, it was done in imitation of the kin <tt class="docutils literal"><span class="pre">compiler_while</span></tt> function. By reading it carefully, however, keeping in mind that the Python VM is stack-based, and glancing into the documentation of the <tt class="docutils literal"><span class="pre">dis</span></tt> module, which has <a class="reference external" href="http://docs.python.org/py3k/library/dis.html">a list of Python bytecodes</a> with descriptions, it&#8217;s possible to understand what&#8217;s going on.</p>
</div>
<div class="section" id="that-s-it-we-re-done-aren-t-we">
<h3>That&#8217;s it, we&#8217;re done&#8230; Aren&#8217;t we?</h3>
<p>After making all the changes and running <tt class="docutils literal"><span class="pre">make</span></tt>, we can run the newly compiled Python and try our new <tt class="docutils literal"><span class="pre">until</span></tt> statement:</p>
<div class="highlight">
<pre>&gt;&gt;&gt; until num == <span style="color: #007f7f">0</span>:
...   <span style="color: #00007f; font-weight: bold">print</span>(num)
...   num -= <span style="color: #007f7f">1</span>
...
<span style="color: #007f7f">3</span>
<span style="color: #007f7f">2</span>
<span style="color: #007f7f">1</span>
</pre>
</div>
<p>Voila, it works! Let&#8217;s see the bytecode created for the new statement by using the <tt class="docutils literal"><span class="pre">dis</span></tt> module as follows:</p>
<div class="highlight">
<pre><span style="color: #00007f; font-weight: bold">import</span> <span style="color: #00007f">dis</span>

<span style="color: #00007f; font-weight: bold">def</span> <span style="color: #00007f">myfoo</span>(num):
    until num == <span style="color: #007f7f">0</span>:
        <span style="color: #00007f; font-weight: bold">print</span>(num)
        num -= <span style="color: #007f7f">1</span>

dis.dis(myfoo)
</pre>
</div>
<p>Here&#8217;s the result:</p>
<div class="highlight">
<pre>4           0 SETUP_LOOP              36 (to 39)
      &gt;&gt;    3 LOAD_FAST                0 (num)
            6 LOAD_CONST               1 (0)
            9 COMPARE_OP               2 (==)
           12 POP_JUMP_IF_TRUE        38

5          15 LOAD_NAME                0 (print)
           18 LOAD_FAST                0 (num)
           21 CALL_FUNCTION            1
           24 POP_TOP

6          25 LOAD_FAST                0 (num)
           28 LOAD_CONST               2 (1)
           31 INPLACE_SUBTRACT
           32 STORE_FAST               0 (num)
           35 JUMP_ABSOLUTE            3
      &gt;&gt;   38 POP_BLOCK
      &gt;&gt;   39 LOAD_CONST               0 (None)
           42 RETURN_VALUE
</pre>
</div>
<p>The most interesting operation is number 12: if the condition is true, we jump to after the loop. This is correct semantics for <tt class="docutils literal"><span class="pre">until</span></tt>. If the jump isn&#8217;t executed, the loop body keeps running until it jumps back to the condition at operation 35.</p>
<p>Feeling good about my change, I then tried running the function (executing <tt class="docutils literal"><span class="pre">myfoo(3)</span></tt>) instead of showing its bytecode. The result was less than encouraging:</p>
<div class="highlight">
<pre>Traceback (most recent call last):
  File &quot;zy.py&quot;, line 9, in &lt;module&gt;
    myfoo(3)
  File &quot;zy.py&quot;, line 5, in myfoo
    print(num)
SystemError: no locals when loading &#39;print&#39;
</pre>
</div>
<p>Whoa&#8230; this can&#8217;t be good. So what went wrong?</p>
</div>
<div class="section" id="the-case-of-the-missing-symbol-table">
<h3>The case of the missing symbol table</h3>
<p>One of the steps the Python compiler performs when compiling the AST is create a symbol table for the code it compiles. The call to <tt class="docutils literal"><span class="pre">PySymtable_Build</span></tt> in <tt class="docutils literal"><span class="pre">PyAST_Compile</span></tt> calls into the symbol table module (<tt class="docutils literal"><span class="pre">Python/symtable.c</span></tt>), which walks the AST in a manner similar to the code generation functions. Having a symbol table for each scope helps the compiler figure out some key information, such as which variables are global and which are local to a scope.</p>
<p>To fix the problem, we have to modify the <tt class="docutils literal"><span class="pre">symtable_visit_stmt</span></tt> function in <tt class="docutils literal"><span class="pre">Python/symtable.c</span></tt>, adding code for handling <tt class="docutils literal"><span class="pre">until</span></tt> statements, after the similar code for <tt class="docutils literal"><span class="pre">while</span></tt> statements <a class="footnote-reference" href="#id6" id="id3">[3]</a>:</p>
<div class="highlight">
<pre><span style="color: #00007f; font-weight: bold">case</span> While_kind:
    VISIT(st, expr, s-&gt;v.While.test);
    VISIT_SEQ(st, stmt, s-&gt;v.While.body);
    <span style="color: #00007f; font-weight: bold">if</span> (s-&gt;v.While.orelse)
        VISIT_SEQ(st, stmt, s-&gt;v.While.orelse);
    <span style="color: #00007f; font-weight: bold">break</span>;
<span style="color: #00007f; font-weight: bold">case</span> Until_kind:
    VISIT(st, expr, s-&gt;v.Until.test);
    VISIT_SEQ(st, stmt, s-&gt;v.Until.body);
    <span style="color: #00007f; font-weight: bold">break</span>;
</pre>
</div>
<p>And now we really are done. Compiling the source after this change makes the execution of <tt class="docutils literal"><span class="pre">myfoo(3)</span></tt> work as expected.</p>
</div>
<div class="section" id="conclusion">
<h3>Conclusion</h3>
<p>In this article I&#8217;ve demonstrated how to add a new statement to Python. Albeit requiring quite a bit of tinkering in the code of the Python compiler, the change wasn&#8217;t difficult to implement, because I used a similar and existing statement as a guideline.</p>
<p>The Python compiler is a sophisticated chunk of software, and I don&#8217;t claim being an expert in it. However, I am really interested in the internals of Python, and particularly its front-end. Therefore, I found this exercise a very useful companion to theoretical study of the compiler&#8217;s principles and source code. It will serve as a base for future articles that will get deeper into the compiler.</p>
</div>
<div class="section" id="references">
<h3>References</h3>
<p>I used a few excellent references for the construction of this article. Here they are, in no particular order:</p>
<ul class="simple">
<li><a class="reference external" href="http://www.python.org/dev/peps/pep-0339/">PEP 339: Design of the CPython compiler</a> &#8211; probably the most important and comprehensive piece of <em>official</em> documentation for the Python compiler. Being very short, it painfully displays the scarcity of good documentation of the internals of Python.</li>
<li>&quot;Python Compiler Internals&quot; &#8211; an article by Thomas Lee</li>
<li>&quot;Python: Design and Implementation&quot; &#8211; a presentation by Guido van Rossum</li>
<li>Python (2.5) Virtual Machine, A guided tour &#8211; a presentation by Peter Tröger</li>
</ul>
<div align="center" class="align-center"><img alt="http://eli.thegreenplace.net/wp-content/uploads/hline.jpg" class="align-center" src="http://eli.thegreenplace.net/wp-content/uploads/hline.jpg" style="width: 320px; height: 5px;" /></div>
<table class="docutils footnote" frame="void" id="id4" rules="none">
<colgroup>
<col class="label" />
<col /></colgroup>
<tbody valign="top">
<tr>
<td class="label"><a class="fn-backref" href="#id1">[1]</a></td>
<td>From here on, references to files in the Python source are given relatively to the root of the source tree, which is the directory where you run <tt class="docutils literal"><span class="pre">configure</span></tt> and <tt class="docutils literal"><span class="pre">make</span></tt> to build Python.</td>
</tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id5" rules="none">
<colgroup>
<col class="label" />
<col /></colgroup>
<tbody valign="top">
<tr>
<td class="label"><a class="fn-backref" href="#id2">[2]</a></td>
<td>This demonstrates a common technique I use when modifying source code I&#8217;m not familiar with: <em>work by similarity</em>. This principle won&#8217;t solve all your problems, but it can definitely ease the process. Since everything that has to be done for <tt class="docutils literal"><span class="pre">while</span></tt> also has to be done for <tt class="docutils literal"><span class="pre">until</span></tt>, it serves as a pretty good guideline.</td>
</tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id6" rules="none">
<colgroup>
<col class="label" />
<col /></colgroup>
<tbody valign="top">
<tr>
<td class="label"><a class="fn-backref" href="#id3">[3]</a></td>
<td>By the way, without this code there&#8217;s a compiler warning for <tt class="docutils literal"><span class="pre">Python/symtable.c</span></tt>. The compiler notices that the <tt class="docutils literal"><span class="pre">Until_kind</span></tt> enumeration value isn&#8217;t handled in the switch statement of <tt class="docutils literal"><span class="pre">symtable_visit_stmt</span></tt> and complains. It&#8217;s always important to check for compiler warnings!</td>
</tr>
</tbody>
</table>
</div>
<img src="http://eli.thegreenplace.net/?ak_action=api_record_view&id=2231&type=feed" alt="" />

<p>Related posts:<ol><li><a href='http://eli.thegreenplace.net/2009/11/28/python-internals-working-with-python-asts/' rel='bookmark' title='Permanent Link: Python internals: Working with Python ASTs'>Python internals: Working with Python ASTs</a> <small> Starting with Python 2.5, the Python compiler (the part...</small></li><li><a href='http://eli.thegreenplace.net/2009/02/16/abstract-vs-concrete-syntax-trees/' rel='bookmark' title='Permanent Link: Abstract vs. Concrete Syntax Trees'>Abstract vs. Concrete Syntax Trees</a> <small>CSTs &#8211; Concrete Syntax Trees (a.k.a. Parse Trees) and ASTs...</small></li><li><a href='http://eli.thegreenplace.net/2008/07/11/asts-for-analyzing-c/' rel='bookmark' title='Permanent Link: ASTs for analyzing C'>ASTs for analyzing C</a> <small>As I wrote here, I&#8217;ve commonly found myself in the...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://eli.thegreenplace.net/2010/06/30/python-internals-adding-a-new-statement-to-python/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>AES encryption of files in Python with PyCrypto</title>
		<link>http://eli.thegreenplace.net/2010/06/25/aes-encryption-of-files-in-python-with-pycrypto/</link>
		<comments>http://eli.thegreenplace.net/2010/06/25/aes-encryption-of-files-in-python-with-pycrypto/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 16:26:49 +0000</pubDate>
		<dc:creator>eliben</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://eli.thegreenplace.net/?p=2227</guid>
		<description><![CDATA[The PyCrypto module seems to provide all one needs for employing strong cryptography in a program. It wraps a highly optimized C implementation of many popular encryption algorithms with a Python interface. PyCrypto can be built from source on Linux, and Windows binaries for various versions of Python 2.x were kindly made available by Michael [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>The <a class="reference external" href="http://www.pycrypto.org/">PyCrypto</a> module seems to provide all one needs for employing strong cryptography in a program. It wraps a highly optimized C implementation of many popular encryption algorithms with a Python interface. PyCrypto can be built from source on Linux, and Windows binaries for various versions of Python 2.x were kindly made available by Michael Foord on <a class="reference external" href="http://www.voidspace.org.uk/python/modules.shtml">this page</a>.</p>
<p>My only gripe with PyCrypto is its documentation. The auto-generated <a class="reference external" href="http://www.dlitz.net/software/pycrypto/apidoc/">API doc</a> is next to useless, and <a class="reference external" href="http://www.dlitz.net/software/pycrypto/doc/">this overview</a> is somewhat dated and didn&#8217;t address the questions I had about the module. It isn&#8217;t surprising that a few modules were created just to provide simpler and better documented wrappers around PyCrypto.</p>
<p>In this article I want to present how to use PyCrypto for simple symmetric encryption and decryption of files using the AES algorithm.</p>
<div class="section" id="simple-aes-encryption">
<h3>Simple AES encryption</h3>
<p>Here&#8217;s how one can encrypt a string with AES:</p>
<div class="highlight">
<pre><span style="color: #00007f; font-weight: bold">from</span> <span style="color: #00007f">Crypto.Cipher</span> <span style="color: #00007f; font-weight: bold">import</span> AES

key = <span style="color: #7f007f">&#39;0123456789abcdef&#39;</span>
mode = AES.MODE_CBC
encryptor = AES.new(key, mode)

text = <span style="color: #7f007f">&#39;j&#39;</span> * <span style="color: #007f7f">64</span> + <span style="color: #7f007f">&#39;i&#39;</span> * <span style="color: #007f7f">128</span>
ciphertext = encryptor.encrypt(text)
</pre>
</div>
<p>Since the PyCrypto block-level encryption API is very low-level, it expects your key to be either 16, 24 or 32 bytes long (for AES-128, AES-196 and AES-256, respectively). The longer the key, the stronger the encryption.</p>
<p>Having keys of exact length isn&#8217;t very convenient, as you sometimes want to use some mnemonic password for the key. In this case I recommend picking a password and then using the SHA-256 digest algorithm from <tt class="docutils literal"><span class="pre">hashlib</span></tt> to generate a 32-byte key from it. Just replace the assignment to <tt class="docutils literal"><span class="pre">key</span></tt> in the code above with:</p>
<div class="highlight">
<pre><span style="color: #00007f; font-weight: bold">import</span> <span style="color: #00007f">hashlib</span>

password = <span style="color: #7f007f">&#39;kitty&#39;</span>
key = hashlib.sha256(password).digest()
</pre>
</div>
<p>Keep in mind that this 32-byte key only has as much entropy as your original password. So be wary of brute-force password guessing, and pick a relatively strong password (<em>kitty</em> probably won&#8217;t do). What&#8217;s useful about this technique is that you don&#8217;t have to worry about manually padding your password &#8211; SHA-256 will scramble a 32-byte block out of any password for you.</p>
<p>The next thing the code does is set the <a class="reference external" href="http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation">block mode</a> of AES. I won&#8217;t get into all the details, but unless you have some special requirements, CBC should be good enough for you.</p>
<p>We create a new AES encryptor object with <tt class="docutils literal"><span class="pre">Crypto.Cipher.AES.new</span></tt>, and give it the encryption key and the mode. Next comes the encryption itself. Again, since the API is low-level, the <tt class="docutils literal"><span class="pre">encrypt</span></tt> method expects your input to consist of an integral number of 16-byte blocks (16 is the size of the basic AES block).</p>
<p>The <tt class="docutils literal"><span class="pre">encryptor</span></tt> object has an internal state when used in the CBC mode, so if you try to encrypt the same text with the same encryptor once again &#8211; you will get different results. So be careful to create a fresh AES encryptor object for any encryption/decryption job.</p>
</div>
<div class="section" id="decryption">
<h3>Decryption</h3>
<p>To decrypt the ciphertext, simply add:</p>
<div class="highlight">
<pre>decryptor = AES.new(key, mode)
plain = decryptor.decrypt(ciphertext)
</pre>
</div>
<p>And you get your plaintext back again.</p>
</div>
<div class="section" id="a-word-about-the-initialization-vector">
<h3>A word about the initialization vector</h3>
<p>The <a class="reference external" href="http://en.wikipedia.org/wiki/Initialization_vector">initialization vector</a> (IV) is an important part of block encryption algorithms that work in chained modes like CBC. For the simple example above I&#8217;ve ignored the IV, but for a more serious application this is a grave mistake. I don&#8217;t want to get too deep into cryptographic theory here, but it suffices to say that the IV is as important as the salt in hashed passwords, and the lack of correct IV usage led to the cracking of the <a class="reference external" href="http://en.wikipedia.org/wiki/Wired_Equivalent_Privacy">WEP encryption</a> for wireless LAN.</p>
<p><tt class="docutils literal"><span class="pre">PyCrypto</span></tt> allows one to pass an IV into the <tt class="docutils literal"><span class="pre">AES.new</span></tt> creator function. For maximal security, the IV should be randomly generated for every new encryption and can be stored together with the ciphertext. Knowledge of the IV won&#8217;t help the attacker crack your encryption. What can help him, however, is your reusing the same IV with the same encryption key for multiple encryptions.</p>
</div>
<div class="section" id="encrypting-and-decrypting-files">
<h3>Encrypting and decrypting files</h3>
<p>The following function encrypts a file of any size. It makes sure to pad the file to a multiple of the AES block length , and also handles the random generation of IV.</p>
<div class="highlight">
<pre><span style="color: #00007f; font-weight: bold">import</span> <span style="color: #00007f">os</span>, <span style="color: #00007f">random</span>, <span style="color: #00007f">struct</span>
<span style="color: #00007f; font-weight: bold">from</span> <span style="color: #00007f">Crypto.Cipher</span> <span style="color: #00007f; font-weight: bold">import</span> AES

<span style="color: #00007f; font-weight: bold">def</span> <span style="color: #00007f">encrypt_file</span>(key, in_filename, out_filename=<span style="color: #00007f">None</span>, chunksize=<span style="color: #007f7f">64</span>*<span style="color: #007f7f">1024</span>):
    <span style="color: #7f007f">&quot;&quot;&quot; Encrypts a file using AES (CBC mode) with the</span>
<span style="color: #7f007f">        given key.</span>

<span style="color: #7f007f">        key:</span>
<span style="color: #7f007f">            The encryption key - a string that must be</span>
<span style="color: #7f007f">            either 16, 24 or 32 bytes long. Longer keys</span>
<span style="color: #7f007f">            are more secure.</span>

<span style="color: #7f007f">        in_filename:</span>
<span style="color: #7f007f">            Name of the input file</span>

<span style="color: #7f007f">        out_filename:</span>
<span style="color: #7f007f">            If None, &#39;&lt;in_filename&gt;.enc&#39; will be used.</span>

<span style="color: #7f007f">        chunksize:</span>
<span style="color: #7f007f">            Sets the size of the chunk which the function</span>
<span style="color: #7f007f">            uses to read and encrypt the file. Larger chunk</span>
<span style="color: #7f007f">            sizes can be faster for some files and machines.</span>
<span style="color: #7f007f">            chunksize must be divisible by 16.</span>
<span style="color: #7f007f">    &quot;&quot;&quot;</span>
    <span style="color: #00007f; font-weight: bold">if</span> <span style="color: #0000aa">not</span> out_filename:
        out_filename = in_filename + <span style="color: #7f007f">&#39;.enc&#39;</span>

    iv = <span style="color: #7f007f">&#39;&#39;</span>.join(<span style="color: #00007f">chr</span>(random.randint(<span style="color: #007f7f">0</span>, <span style="color: #007f7f">0</span>xFF)) <span style="color: #00007f; font-weight: bold">for</span> i <span style="color: #0000aa">in</span> <span style="color: #00007f">range</span>(<span style="color: #007f7f">16</span>))
    encryptor = AES.new(key, AES.MODE_CBC, iv)
    filesize = os.path.getsize(in_filename)

    <span style="color: #00007f; font-weight: bold">with</span> <span style="color: #00007f">open</span>(in_filename, <span style="color: #7f007f">&#39;rb&#39;</span>) <span style="color: #00007f; font-weight: bold">as</span> infile:
        <span style="color: #00007f; font-weight: bold">with</span> <span style="color: #00007f">open</span>(out_filename, <span style="color: #7f007f">&#39;wb&#39;</span>) <span style="color: #00007f; font-weight: bold">as</span> outfile:
            outfile.write(struct.pack(<span style="color: #7f007f">&#39;&lt;Q&#39;</span>, filesize))
            outfile.write(iv)

            <span style="color: #00007f; font-weight: bold">while</span> <span style="color: #00007f">True</span>:
                chunk = infile.read(chunksize)
                <span style="color: #00007f; font-weight: bold">if</span> <span style="color: #00007f">len</span>(chunk) == <span style="color: #007f7f">0</span>:
                    <span style="color: #00007f; font-weight: bold">break</span>
                <span style="color: #00007f; font-weight: bold">elif</span> <span style="color: #00007f">len</span>(chunk) % <span style="color: #007f7f">16</span> != <span style="color: #007f7f">0</span>:
                    chunk += <span style="color: #7f007f">&#39; &#39;</span> * (<span style="color: #007f7f">16</span> - <span style="color: #00007f">len</span>(chunk) % <span style="color: #007f7f">16</span>)

                outfile.write(encryptor.encrypt(chunk))
</pre>
</div>
<p>Since it might have to pad the file to fit into a multiple of 16, the function saves the original file size in the first 8 bytes of the output file (more precisely, the first <tt class="docutils literal"><span class="pre">sizeof(long</span> <span class="pre">long)</span></tt> bytes). It randomly generates a 16-byte IV and stores it in the file as well. Then, it reads the input file chunk by chunk (with chunk size configurable), encrypts the chunk and writes it to the output. The last chunk is padded with spaces, if required.</p>
<p>Working in chunks makes sure that large files can be efficiently processed without reading them wholly into memory. For example, with the default chunk size it takes about 1.2 seconds on my computer to encrypt a 50MB file. PyCrypto is fast!</p>
<p>Decrypting the file can be done with:</p>
<div class="highlight">
<pre><span style="color: #00007f; font-weight: bold">def</span> <span style="color: #00007f">decrypt_file</span>(key, in_filename, out_filename=<span style="color: #00007f">None</span>, chunksize=<span style="color: #007f7f">24</span>*<span style="color: #007f7f">1024</span>):
    <span style="color: #7f007f">&quot;&quot;&quot; Decrypts a file using AES (CBC mode) with the</span>
<span style="color: #7f007f">        given key. Parameters are similar to encrypt_file,</span>
<span style="color: #7f007f">        with one difference: out_filename, if not supplied</span>
<span style="color: #7f007f">        will be in_filename without its last extension</span>
<span style="color: #7f007f">        (i.e. if in_filename is &#39;aaa.zip.enc&#39; then</span>
<span style="color: #7f007f">        out_filename will be &#39;aaa.zip&#39;)</span>
<span style="color: #7f007f">    &quot;&quot;&quot;</span>
    <span style="color: #00007f; font-weight: bold">if</span> <span style="color: #0000aa">not</span> out_filename:
        out_filename = os.path.splitext(in_filename)[<span style="color: #007f7f">0</span>]

    <span style="color: #00007f; font-weight: bold">with</span> <span style="color: #00007f">open</span>(in_filename, <span style="color: #7f007f">&#39;rb&#39;</span>) <span style="color: #00007f; font-weight: bold">as</span> infile:
        origsize = struct.unpack(<span style="color: #7f007f">&#39;&lt;Q&#39;</span>, infile.read(struct.calcsize(<span style="color: #7f007f">&#39;Q&#39;</span>)))[<span style="color: #007f7f">0</span>]
        iv = infile.read(<span style="color: #007f7f">16</span>)
        decryptor = AES.new(key, AES.MODE_CBC, iv)

        <span style="color: #00007f; font-weight: bold">with</span> <span style="color: #00007f">open</span>(out_filename, <span style="color: #7f007f">&#39;wb&#39;</span>) <span style="color: #00007f; font-weight: bold">as</span> outfile:
            <span style="color: #00007f; font-weight: bold">while</span> <span style="color: #00007f">True</span>:
                chunk = infile.read(chunksize)
                <span style="color: #00007f; font-weight: bold">if</span> <span style="color: #00007f">len</span>(chunk) == <span style="color: #007f7f">0</span>:
                    <span style="color: #00007f; font-weight: bold">break</span>
                outfile.write(decryptor.decrypt(chunk))

            outfile.truncate(origsize)
</pre>
</div>
<p>First the original size of the file is read from the first 8 bytes of the encrypted file. The IV is read next to correctly initialize the AES object. Then the file is decrypted in chunks, and finally it&#8217;s truncated to the original size, so the padding is thrown out.</p>
</div>
<img src="http://eli.thegreenplace.net/?ak_action=api_record_view&id=2227&type=feed" alt="" />

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://eli.thegreenplace.net/2010/06/25/aes-encryption-of-files-in-python-with-pycrypto/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Sad, but just</title>
		<link>http://eli.thegreenplace.net/2010/06/24/sad-but-just/</link>
		<comments>http://eli.thegreenplace.net/2010/06/24/sad-but-just/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 16:19:38 +0000</pubDate>
		<dc:creator>eliben</dc:creator>
				<category><![CDATA[Miscellanea]]></category>

		<guid isPermaLink="false">http://eli.thegreenplace.net/?p=2222</guid>
		<description><![CDATA[
Squadra Azzurra, I love you, but you deserved it. There&#8217;s no one else to blame. In the last 15 minutes of this game we finally saw a real football team wearing blue, but it was too little, too late.


Related posts:Enhorabuena a España It was a tough game against Holland&#8217;s karate^H^H^H^H^H&#8230; err, football...AI-ish attempt at teamsheet [...]


Related posts:<ol><li><a href='http://eli.thegreenplace.net/2010/07/12/enhorabuena-a-espana/' rel='bookmark' title='Permanent Link: Enhorabuena a España'>Enhorabuena a España</a> <small>It was a tough game against Holland&#8217;s karate^H^H^H^H^H&#8230; err, football...</small></li><li><a href='http://eli.thegreenplace.net/2004/12/03/ai-ish-attempt-at-teamsheet-picking/' rel='bookmark' title='Permanent Link: AI-ish attempt at teamsheet picking'>AI-ish attempt at teamsheet picking</a> <small>My ESMS (old website, new, not yet fully updated website)...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://eli.thegreenplace.net/wp-content/uploads/2010/06/200px-Flag_of_Italy.svg_.png" alt="" title="200px-Flag_of_Italy.svg" width="200" height="133" class="alignnone size-full wp-image-2221" /></p>
<p>Squadra Azzurra, I love you, but you deserved it. There&#8217;s no one else to blame. In the last 15 minutes of this game we finally saw a real football team wearing blue, but it was too little, too late.</p>
<img src="http://eli.thegreenplace.net/?ak_action=api_record_view&id=2222&type=feed" alt="" />

<p>Related posts:<ol><li><a href='http://eli.thegreenplace.net/2010/07/12/enhorabuena-a-espana/' rel='bookmark' title='Permanent Link: Enhorabuena a España'>Enhorabuena a España</a> <small>It was a tough game against Holland&#8217;s karate^H^H^H^H^H&#8230; err, football...</small></li><li><a href='http://eli.thegreenplace.net/2004/12/03/ai-ish-attempt-at-teamsheet-picking/' rel='bookmark' title='Permanent Link: AI-ish attempt at teamsheet picking'>AI-ish attempt at teamsheet picking</a> <small>My ESMS (old website, new, not yet fully updated website)...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://eli.thegreenplace.net/2010/06/24/sad-but-just/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Boars in our backyard</title>
		<link>http://eli.thegreenplace.net/2010/06/18/boars-in-our-backyard/</link>
		<comments>http://eli.thegreenplace.net/2010/06/18/boars-in-our-backyard/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 05:50:27 +0000</pubDate>
		<dc:creator>eliben</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://eli.thegreenplace.net/?p=2212</guid>
		<description><![CDATA[A large family of boars is frequently visiting our neighborhood to feed on acorns and drink water from the underground sprinkle tubes. Recently they&#8217;ve become very brave and arrive in full daylight. Here are some photos of the &#8220;baby boars&#8221; (much larger than they were a few weeks ago!) taken from my window at 8:20 [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>A large family of boars is frequently visiting our neighborhood to feed on acorns and drink water from the underground sprinkle tubes. Recently they&#8217;ve become very brave and arrive in full daylight. Here are some photos of the &#8220;baby boars&#8221; (much larger than they were a few weeks ago!) taken from my window at 8:20 AM this morning:</p>
<p><a href="http://thegreenplace.net/photos/albums/uploads/boars/IMG_2760.JPG"><img src="http://thegreenplace.net/photos/albums/uploads/boars/normal_IMG_2760.JPG" alt="Boars" /></a></p>
<p><a href="http://thegreenplace.net/photos/albums/uploads/boars/IMG_2762.JPG"><img src="http://thegreenplace.net/photos/albums/uploads/boars/normal_IMG_2762.JPG" alt="Boars" /></a></p>
<p>I also managed to run down the steps and get a closer shot standing just a couple of meters from them:</p>
<p><a href="http://thegreenplace.net/photos/albums/uploads/boars/IMG_2764.JPG"><img src="http://thegreenplace.net/photos/albums/uploads/boars/normal_IMG_2764.JPG" alt="Boars" /></a></p>
<p>And a few more, 20 minutes later (when they fearlessly came back):</p>
<p><a href="http://thegreenplace.net/photos/albums/uploads/boars/IMG_2765.JPG"><img src="http://thegreenplace.net/photos/albums/uploads/boars/normal_IMG_2765.JPG" alt="Boars" /></a></p>
<p><a href="http://thegreenplace.net/photos/albums/uploads/boars/IMG_2768.JPG"><img src="http://thegreenplace.net/photos/albums/uploads/boars/normal_IMG_2768.JPG" alt="Boars" /></a></p>
<p><a href="http://thegreenplace.net/photos/albums/uploads/boars/IMG_2769.JPG"><img src="http://thegreenplace.net/photos/albums/uploads/boars/normal_IMG_2769.JPG" alt="Boars" /></a></p>
<img src="http://eli.thegreenplace.net/?ak_action=api_record_view&id=2212&type=feed" alt="" />

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://eli.thegreenplace.net/2010/06/18/boars-in-our-backyard/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
