<?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>gefira blog</title>
	<atom:link href="http://www.gefira.pl/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gefira.pl/blog</link>
	<description>Les mains de l&#039;empereur</description>
	<lastBuildDate>Thu, 10 Nov 2011 15:11:17 +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>Don&#8217;t register the same ZeroMQ socket with a poller twice</title>
		<link>http://www.gefira.pl/blog/2011/11/10/dont-register-the-same-zeromq-socket-with-a-poller-twice/</link>
		<comments>http://www.gefira.pl/blog/2011/11/10/dont-register-the-same-zeromq-socket-with-a-poller-twice/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 15:11:17 +0000</pubDate>
		<dc:creator>Dariusz Suchojad</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[ZeroMQ]]></category>

		<guid isPermaLink="false">http://www.gefira.pl/blog/?p=1608</guid>
		<description><![CDATA[Remember not to register the same ZeroMQ socket with a poller twice or it will seem it&#8217;s hanging or processing every other message only &#8211; that&#8217;s a piece of advice I have for you after several hours of bug squashing  
]]></description>
			<content:encoded><![CDATA[<p>Remember not to register the same ZeroMQ socket with a poller twice or it will seem it&#8217;s hanging or processing every other message only &#8211; that&#8217;s a piece of advice I have for you after several hours of bug squashing <img src='http://www.gefira.pl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.gefira.pl%2Fblog%2F2011%2F11%2F10%2Fdont-register-the-same-zeromq-socket-with-a-poller-twice%2F&amp;title=Don%26%238217%3Bt%20register%20the%20same%20ZeroMQ%20socket%20with%20a%20poller%20twice"><img src="http://www.gefira.pl/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.gefira.pl/blog/2011/11/10/dont-register-the-same-zeromq-socket-with-a-poller-twice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A book wrecks my car</title>
		<link>http://www.gefira.pl/blog/2011/11/02/a-book-wrecks-my-car/</link>
		<comments>http://www.gefira.pl/blog/2011/11/02/a-book-wrecks-my-car/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 17:19:39 +0000</pubDate>
		<dc:creator>Dariusz Suchojad</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.gefira.pl/blog/?p=1592</guid>
		<description><![CDATA[Hm.. when I hear that &#8216;the research says the [Duqu] Trojan exploited a previously unknown vulnerability embedded in Word files, allowing Duqu to modify computers&#8217; security protection&#8216;, I just can&#8217;t help but imagine my opening a car, tossing a book on the back seat and then later on, being unable to use the brakes anymore [...]]]></description>
			<content:encoded><![CDATA[<p>Hm.. when I hear that &#8216;<a title="BBC - Duqu infection linked to Microsoft Word exploit" href="http://www.bbc.co.uk/news/technology-15554361">the research says the [Duqu] Trojan exploited a previously unknown vulnerability embedded in Word files, allowing Duqu to modify computers&#8217; security protection</a>&#8216;, I just can&#8217;t help but imagine my opening a car, tossing a book on the back seat and then later on, being unable to use the brakes anymore because the publisher had used a wrong type of ink, one that makes the disc brakes vaporise immediately upon the book&#8217;s opening on page 51 when it lands on the seat.</p>
<p>That&#8217;s simply insane.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.gefira.pl%2Fblog%2F2011%2F11%2F02%2Fa-book-wrecks-my-car%2F&amp;title=A%20book%20wrecks%20my%20car"><img src="http://www.gefira.pl/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.gefira.pl/blog/2011/11/02/a-book-wrecks-my-car/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>advWhy prnI vDon&#8217;t vLike daThe adjHungarian nNotation</title>
		<link>http://www.gefira.pl/blog/2011/10/21/why-i-dont-like-the-hungarian-notation/</link>
		<comments>http://www.gefira.pl/blog/2011/10/21/why-i-dont-like-the-hungarian-notation/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 12:59:08 +0000</pubDate>
		<dc:creator>Dariusz Suchojad</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://www.gefira.pl/blog/?p=1553</guid>
		<description><![CDATA[vNote cThat pThis vIs prpTo vDo prpWith nProgramming adjOnly advNot daThe nCountry pm! sml:-)
nTwo naThings vPrompted prnMe prpInto nWriting pThis pm.
prnI&#8217;ve adjRecently vSeen iaA adjPromising nJavaScript nLibrary cnjAnd prnI vWas intrjOh advSo advClose prpTo vStart vUsing cnjExcept prnThat cnjWhen prnI vHad iaA vLook prpAt adjIts nAPI adjMy nJaw vFell prpTo daThe nFloor pm- daThe nThing [...]]]></description>
			<content:encoded><![CDATA[<p>vNote cThat pThis vIs prpTo vDo prpWith nProgramming adjOnly advNot daThe nCountry pm! sml:-)</p>
<p>nTwo naThings vPrompted prnMe prpInto nWriting pThis pm.</p>
<p>prnI&#8217;ve adjRecently vSeen iaA adjPromising nJavaScript nLibrary cnjAnd prnI vWas intrjOh advSo advClose prpTo vStart vUsing cnjExcept prnThat cnjWhen prnI vHad iaA vLook prpAt adjIts nAPI adjMy nJaw vFell prpTo daThe nFloor pm- daThe nThing vWas vUsing daThe adjHungarian nNotation, vIncluding vPrefixing naFunctions prpWith iaAn nFn pm- advSo prnI vConsulted iaA nCalendar cnjAnd advYes pm, prnIt vWas advStill daThe nNear n2011 pm.  </p>
<p>prnI vAm vWriting prnThis nPost advSo prnThat adjPotential adjHungarian nNotation naUsers vCan vUnderstand advHow adjSuch iaAn nAPI vLooks prpLike prpIn daThe nEye prpOf daThe nBeholder pm, prnI vAm advPerfectly adjSure penThey advJust vDo advNot vRealise adjWhat nSort prpOf nCommotion prnThey vCause pm. prnThere vIs adjNo nBeauty prpIn prnIt pm, vDon&#8217;t prnYou vAgree pm? intrjSo vPlease pm, vCan pwnWe vStop prnIt advNow pm? </p>
<p>prnI vRemember vSeeing adjSuch naThings prpLike n15 naYears advAgo cnjAnd advReally pm, adThe nWorld vHas advSince vChanged pm, prnWe vDon&#8217;t advLonger vUse nVi cnjOr nEd pm- intrjWell, advNot prpTo daThe advSame nExtent prpAt advLeast pm- prnWe vHave nAuto-completion pm, nSyntax vHighlighting pm, nCode vRefactoring pm, nUnit vTesting pm, adjContinuous nIntegration cnjAnd nWhatnot pm. </p>
<p>vLet&#8217;s vLeave daThe adjMundane nJob prpOf nType nInference prpTo naCompilers cnjAnd prpUnless daThe adjParticular nLanguage vDoesn&#8217;t  vEnforce daThe nUsage prpOf prnThese naPrefixes pm, intrjWell pm, vLet&#8217;s advNot vDo prnIt advThen pm, advAright pm? naThanks pm!</p>
<p>prnAnother nThing vWas iaAn nSQLite nDatabase prnI vHad iaA nMisfortune prpOf vHaving vHad iaA vLook prpAt prnWhich vHad adjEach nTable conjAnd nColumn vPrefixed prpWith nTbl cnjAnd nCol advRespectively pm. prnI vMean pm, prnI&#8217;ve vSeen prpAt advLeast naDozens prpOf naDatabases pm, prpFrom nFirebird prpOn nWindows prpTo nDB2 prpOn nMainframe cnjAnd prnI&#8217;m advYet prpTo vConfuse iaA nTable prpWith iaA nColumn pm- prnIt vIs advOK prpTo vUse nUq or nIdx prpIn daThe naNames cnjBut prpBy nApollo&#8217;s adjHoly naTrousers, vLet&#8217;s advNot vDo daThe prnSame prpWith naTables cnjAnd naAolumns prnThemselves pm!</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.gefira.pl%2Fblog%2F2011%2F10%2F21%2Fwhy-i-dont-like-the-hungarian-notation%2F&amp;title=advWhy%20prnI%20vDon%26%238217%3Bt%20vLike%20daThe%20adjHungarian%20nNotation"><img src="http://www.gefira.pl/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.gefira.pl/blog/2011/10/21/why-i-dont-like-the-hungarian-notation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Read about securing web services with Python using UserNameTokens</title>
		<link>http://www.gefira.pl/blog/2011/10/20/read-about-securing-web-services-with-python-using-usernametokens/</link>
		<comments>http://www.gefira.pl/blog/2011/10/20/read-about-securing-web-services-with-python-using-usernametokens/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 13:40:51 +0000</pubDate>
		<dc:creator>Dariusz Suchojad</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Planet Python]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[sec-wall]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.gefira.pl/blog/?p=1547</guid>
		<description><![CDATA[András Veres-Szentkirályi has started a series on securing web services with Python; the first part deals with UserNameTokens and mentions sec-wall, the security proxy, yay!  
]]></description>
			<content:encoded><![CDATA[<p><a title="VSzA techblog" href="http://techblog.vsza.hu/">András Veres-Szentkirályi</a> has started a series on securing web services with Python; <a title="VSzA techblog - Secure web services with Python part 1 - UserNameToken" href="http://techblog.vsza.hu/posts/Secure_web_services_with_Python_part_1_-_UserNameToken.html">the first part</a> deals with UserNameTokens and mentions <a title="sec-wall project's home page" href="http://sec-wall.gefira.pl/">sec-wall</a>, the security proxy, yay! <img src='http://www.gefira.pl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.gefira.pl%2Fblog%2F2011%2F10%2F20%2Fread-about-securing-web-services-with-python-using-usernametokens%2F&amp;title=Read%20about%20securing%20web%20services%20with%20Python%20using%20UserNameTokens"><img src="http://www.gefira.pl/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.gefira.pl/blog/2011/10/20/read-about-securing-web-services-with-python-using-usernametokens/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sort of tired of long constant names &#8211; Bunch to the rescue!</title>
		<link>http://www.gefira.pl/blog/2011/10/14/sort-of-tired-of-long-constant-names-bunch-to-the-rescue/</link>
		<comments>http://www.gefira.pl/blog/2011/10/14/sort-of-tired-of-long-constant-names-bunch-to-the-rescue/#comments</comments>
		<pubDate>Fri, 14 Oct 2011 16:05:13 +0000</pubDate>
		<dc:creator>Dariusz Suchojad</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Planet Python]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.gefira.pl/blog/?p=1509</guid>
		<description><![CDATA[I&#8217;ve gotten a little bit tired of long constant names, like imagine there&#8217;s constants.py module which has the following:

&#160;
MESSAGE_CREATE_FOO = '1000'
MESSAGE_DELETE_FOO = '1001'
&#160;
# And so on..

Now the trouble is with importing it all. I can do either:

from constants import *

Which may be considered a bad style on one hand and on the other hand it [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve gotten a little bit tired of long constant names, like imagine there&#8217;s constants.py module which has the following:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
MESSAGE_CREATE_FOO = <span style="color: #483d8b;">'1000'</span>
MESSAGE_DELETE_FOO = <span style="color: #483d8b;">'1001'</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># And so on..</span></pre></div></div>

<p>Now the trouble is with importing it all. I can do either:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> constants <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span></pre></div></div>

<p>Which may be considered a bad style on one hand and on the other hand it becomes a mess if your IDE, like <a title="Wing IDE homepage" href="http://www.wingware.com/">Wing IDE</a>, autocompletes the names for you, so you type ME and then have to scroll through several dozens of them. Not to mention that it&#8217;s hardly ever the case that all of the constants are needed in any single module.</p>
<p>I can also carefully pick the names I need, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> constants <span style="color: #ff7700;font-weight:bold;">import</span> MESSAGE_CREATE_FOO, MESSAGE_DELETE_FOO <span style="color: #808080; font-style: italic;"># And so on..</span></pre></div></div>

<p>But that&#8217;s yet another place that needs to be kept in sync with the rest of the code.</p>
<p>So I&#8217;ve finally settled on using the <a title="Bunch class on PyPI" href="http://pypi.python.org/pypi/bunch">Bunch</a> class, which basically is a regular dictionary with an extra attribute-style access, meaning I can now write it all like so:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> bunch <span style="color: #ff7700;font-weight:bold;">import</span> Bunch
&nbsp;
MESSAGE = Bunch<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
MESSAGE.<span style="color: black;">CREATE_FOO</span> = <span style="color: #483d8b;">'1000'</span>
MESSAGE.<span style="color: black;">DELETE_FOO</span> = <span style="color: #483d8b;">'1001'</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># And so on..</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># Yay, we're importing one thing only, the only one needed</span>
<span style="color: #808080; font-style: italic;"># in this module, and if the code below ever starts deleting</span>
<span style="color: #808080; font-style: italic;"># FOO, we won't have to update the import statement!</span>
<span style="color: #ff7700;font-weight:bold;">from</span> constants <span style="color: #ff7700;font-weight:bold;">import</span> MESSAGE
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span>MESSAGE.<span style="color: black;">CREATE_FOO</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Isn&#8217;t that nicer? <img src='http://www.gefira.pl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.gefira.pl%2Fblog%2F2011%2F10%2F14%2Fsort-of-tired-of-long-constant-names-bunch-to-the-rescue%2F&amp;title=Sort%20of%20tired%20of%20long%20constant%20names%20%26%238211%3B%20Bunch%20to%20the%20rescue%21"><img src="http://www.gefira.pl/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.gefira.pl/blog/2011/10/14/sort-of-tired-of-long-constant-names-bunch-to-the-rescue/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>ON DELETE CASCADE and LEFT JOIN in SQLAlchemy</title>
		<link>http://www.gefira.pl/blog/2011/10/10/on-delete-cascade-and-left-join-in-sqlalchemy/</link>
		<comments>http://www.gefira.pl/blog/2011/10/10/on-delete-cascade-and-left-join-in-sqlalchemy/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 21:16:34 +0000</pubDate>
		<dc:creator>Dariusz Suchojad</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Planet Python]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQLAlchemy]]></category>

		<guid isPermaLink="false">http://www.gefira.pl/blog/?p=1490</guid>
		<description><![CDATA[Here&#8217;s another one in the hoping-it-saves-someone-at-least-half-an-hour-worth-of-searching-around category   which shows nothing but how to define an ON DELETE CASCADE constraint and then how to issue a LEFT JOIN in SQLAlchemy.

# -*- coding: utf-8 -*-
&#160;
# SQLAlchemy
from sqlalchemy import create_engine
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import backref, relationship, sessionmaker
&#160;
Base = declarative_base&#40;&#41;
&#160;
# [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s another one in the hoping-it-saves-someone-at-least-half-an-hour-worth-of-searching-around category <img src='http://www.gefira.pl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  which shows nothing but how to define an ON DELETE CASCADE constraint and then how to issue a LEFT JOIN in SQLAlchemy.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># -*- coding: utf-8 -*-</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># SQLAlchemy</span>
<span style="color: #ff7700;font-weight:bold;">from</span> sqlalchemy <span style="color: #ff7700;font-weight:bold;">import</span> create_engine
<span style="color: #ff7700;font-weight:bold;">from</span> sqlalchemy <span style="color: #ff7700;font-weight:bold;">import</span> Column, Integer, String, ForeignKey
<span style="color: #ff7700;font-weight:bold;">from</span> sqlalchemy.<span style="color: black;">ext</span>.<span style="color: black;">declarative</span> <span style="color: #ff7700;font-weight:bold;">import</span> declarative_base
<span style="color: #ff7700;font-weight:bold;">from</span> sqlalchemy.<span style="color: black;">orm</span> <span style="color: #ff7700;font-weight:bold;">import</span> backref, relationship, sessionmaker
&nbsp;
Base = declarative_base<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The definitions, note the use of both 'ondelete' and 'cascade'.</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Mom<span style="color: black;">&#40;</span>Base<span style="color: black;">&#41;</span>:
    __tablename__ = <span style="color: #483d8b;">'mom'</span>
&nbsp;
    <span style="color: #008000;">id</span> = Column<span style="color: black;">&#40;</span>Integer, primary_key=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    name = Column<span style="color: black;">&#40;</span>String<span style="color: black;">&#40;</span><span style="color: #ff4500;">60</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Daughter<span style="color: black;">&#40;</span>Base<span style="color: black;">&#41;</span>:
    __tablename__ = <span style="color: #483d8b;">'daughter'</span>
&nbsp;
    <span style="color: #008000;">id</span> = Column<span style="color: black;">&#40;</span>Integer, primary_key=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    name = Column<span style="color: black;">&#40;</span>String<span style="color: black;">&#40;</span><span style="color: #ff4500;">60</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    mom_id = Column<span style="color: black;">&#40;</span>Integer, ForeignKey<span style="color: black;">&#40;</span><span style="color: #483d8b;">'mom.id'</span>, ondelete=<span style="color: #483d8b;">'CASCADE'</span><span style="color: black;">&#41;</span>, 
                nullable=<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
    mom = relationship<span style="color: black;">&#40;</span>Mom, 
        backref=backref<span style="color: black;">&#40;</span><span style="color: #483d8b;">'daughters'</span>, cascade=<span style="color: #483d8b;">'all, delete, delete-orphan'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Son<span style="color: black;">&#40;</span>Base<span style="color: black;">&#41;</span>:
    __tablename__ = <span style="color: #483d8b;">'son'</span>
&nbsp;
    <span style="color: #008000;">id</span> = Column<span style="color: black;">&#40;</span>Integer, primary_key=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>    
    name = Column<span style="color: black;">&#40;</span>String<span style="color: black;">&#40;</span><span style="color: #ff4500;">60</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    mom_id = Column<span style="color: black;">&#40;</span>Integer, ForeignKey<span style="color: black;">&#40;</span><span style="color: #483d8b;">'mom.id'</span>, ondelete=<span style="color: #483d8b;">'CASCADE'</span><span style="color: black;">&#41;</span>, 
                nullable=<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
    mom = relationship<span style="color: black;">&#40;</span>Mom, 
                backref=backref<span style="color: black;">&#40;</span><span style="color: #483d8b;">'sons'</span>, cascade=<span style="color: #483d8b;">'all, delete, delete-orphan'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;"># Create an in-memory database.</span>
engine = create_engine<span style="color: black;">&#40;</span><span style="color: #483d8b;">'sqlite:///:memory:'</span>, echo=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
Base.<span style="color: black;">metadata</span>.<span style="color: black;">create_all</span><span style="color: black;">&#40;</span>engine<span style="color: black;">&#41;</span>
Session = sessionmaker<span style="color: black;">&#40;</span>bind=engine<span style="color: black;">&#41;</span>
session = Session<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Let's find out how LEFT JOIN works, note the usage of .outerjoin</span>
&nbsp;
mom1 = Mom<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
mom1.<span style="color: black;">name</span> = <span style="color: #483d8b;">'Molly'</span>
&nbsp;
mom2 = Mom<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
mom2.<span style="color: black;">name</span> = <span style="color: #483d8b;">'Sarah'</span>
&nbsp;
mom3 = Mom<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
mom3.<span style="color: black;">name</span> = <span style="color: #483d8b;">'Martha'</span>
&nbsp;
daughter = Daughter<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
daughter.<span style="color: black;">name</span> = <span style="color: #483d8b;">'Matilda'</span>
daughter.<span style="color: black;">mom</span> = mom1
&nbsp;
son1 = Son<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
son1.<span style="color: black;">name</span> = <span style="color: #483d8b;">'Robert'</span>
son1.<span style="color: black;">mom</span> = mom1
&nbsp;
son2 = Son<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
son2.<span style="color: black;">name</span> = <span style="color: #483d8b;">'Tom'</span>
son2.<span style="color: black;">mom</span> = mom2
&nbsp;
session.<span style="color: black;">add_all</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>mom1, mom2, mom3<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
session.<span style="color: black;">commit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
session.<span style="color: black;">delete</span><span style="color: black;">&#40;</span>mom2<span style="color: black;">&#41;</span>
session.<span style="color: black;">commit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># All moms and their children.</span>
rows1 = session.<span style="color: black;">query</span><span style="color: black;">&#40;</span>Mom.<span style="color: #008000;">id</span>, Mom.<span style="color: black;">name</span>, 
            Daughter.<span style="color: black;">name</span>.<span style="color: black;">label</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'daughter_name'</span><span style="color: black;">&#41;</span>,
            Son.<span style="color: black;">name</span>.<span style="color: black;">label</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'son_name'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.\
              outerjoin<span style="color: black;">&#40;</span>Daughter, Mom.<span style="color: #008000;">id</span>==Daughter.<span style="color: black;">mom_id</span><span style="color: black;">&#41;</span>.\
              outerjoin<span style="color: black;">&#40;</span>Son, Mom.<span style="color: #008000;">id</span>==Son.<span style="color: black;">mom_id</span><span style="color: black;">&#41;</span>.\
              order_by<span style="color: black;">&#40;</span><span style="color: #483d8b;">'mom.name'</span><span style="color: black;">&#41;</span>.\
              <span style="color: #008000;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Sarah doesn't like us anymore so Tom should be gone as well.</span>
rows2 = session.<span style="color: black;">query</span><span style="color: black;">&#40;</span>Son.<span style="color: #008000;">id</span>, Son.<span style="color: black;">name</span><span style="color: black;">&#41;</span>.<span style="color: #008000;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> row <span style="color: #ff7700;font-weight:bold;">in</span> rows1:
    <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span>row<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span>    
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> row <span style="color: #ff7700;font-weight:bold;">in</span> rows2:
    <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span>row<span style="color: black;">&#41;</span></pre></div></div>

<p>As expected, the result is</p>
<pre>
(3, u'Martha', None, None)
(1, u'Molly', u'Matilda', u'Robert')

(1, u'Robert')
</pre>
<p>We can also confirm the SQL code that&#8217;s being generated &#8211; notice the ON DELETE CASCADE clause ..</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> mom <span style="color: #66cc66;">&#40;</span>
	id INTEGER <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> 
	name VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
	<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> daughter <span style="color: #66cc66;">&#40;</span>
	id INTEGER <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> 
	name VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
	mom_id INTEGER <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> 
	<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
	<span style="color: #993333; font-weight: bold;">FOREIGN</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">&#40;</span>mom_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> mom <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #993333; font-weight: bold;">DELETE</span> CASCADE
<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> son <span style="color: #66cc66;">&#40;</span>
	id INTEGER <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> 
	name VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
	mom_id INTEGER <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> 
	<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
	<span style="color: #993333; font-weight: bold;">FOREIGN</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">&#40;</span>mom_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> mom <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #993333; font-weight: bold;">DELETE</span> CASCADE
<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>.. and the LEFT JOIN is here indeed.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> mom<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">AS</span> mom_id<span style="color: #66cc66;">,</span> mom<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> mom_name<span style="color: #66cc66;">,</span> 
    daughter<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> daughter_name<span style="color: #66cc66;">,</span> son<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> son_name 
<span style="color: #993333; font-weight: bold;">FROM</span> mom 
    <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> daughter <span style="color: #993333; font-weight: bold;">ON</span> mom<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> daughter<span style="color: #66cc66;">.</span>mom_id 
    <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> son <span style="color: #993333; font-weight: bold;">ON</span> mom<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> son<span style="color: #66cc66;">.</span>mom_id
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> mom<span style="color: #66cc66;">.</span>name</pre></div></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.gefira.pl%2Fblog%2F2011%2F10%2F10%2Fon-delete-cascade-and-left-join-in-sqlalchemy%2F&amp;title=ON%20DELETE%20CASCADE%20and%20LEFT%20JOIN%20in%20SQLAlchemy"><img src="http://www.gefira.pl/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.gefira.pl/blog/2011/10/10/on-delete-cascade-and-left-join-in-sqlalchemy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>If version control systems were vehicles&#8230;</title>
		<link>http://www.gefira.pl/blog/2011/10/02/if-version-control-systems-were-vehicles/</link>
		<comments>http://www.gefira.pl/blog/2011/10/02/if-version-control-systems-were-vehicles/#comments</comments>
		<pubDate>Sun, 02 Oct 2011 10:50:48 +0000</pubDate>
		<dc:creator>Dariusz Suchojad</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Bazaar]]></category>
		<category><![CDATA[BitKeeper]]></category>
		<category><![CDATA[CVS]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[hg]]></category>
		<category><![CDATA[SVN]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://www.gefira.pl/blog/?p=1423</guid>
		<description><![CDATA[Here&#8217;s a short visualisation of how I perceive various revision control systems, given in the order of my being exposed to each of them throughout all those years.
BitKeeper


Many winters ago, it was the first RCS I used and I remember it was pretty powerful yet somewhat clumsy to steer and handle not to mention the [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a short visualisation of how I perceive various revision control systems, given in the order of my being exposed to each of them throughout all those years.</p>
<h2>BitKeeper</h2>
<p><br/></p>
<p>
Many winters ago, it was the first RCS I used and I remember it was pretty powerful yet somewhat clumsy to steer and handle not to mention the thick armour that wouldn&#8217;t let me peek inside and have a look at its source code. I hear it&#8217;s still being sold to customers around the world who don&#8217;t mind to trade a little bit of the manoeuvrability in exchange for its main gun&#8217;s fire-power.
</p>
<p><a href="http://www.gefira.pl/blog/wp-content/uploads/2011/10/vcs-bk.jpg"><img class="aligncenter size-medium wp-image-1426" title="vcs-bk" src="http://www.gefira.pl/blog/wp-content/uploads/2011/10/vcs-bk-300x185.jpg" alt="" width="300" height="185" /></a></p>
<h2>CVS</h2>
<p><br/></p>
<p>
A funny-looking though not really forgiving system that would bring a lot of projects home. The crucial point was its low price (opensource) yet the lack of features (like no real &#8216;reverse gear&#8217;, one couldn&#8217;t easily delete empty directories) meant I was looking for something else pretty soon.
</p>
<p><a href="http://www.gefira.pl/blog/wp-content/uploads/2011/10/vcs-cvs.jpg"><img class="aligncenter size-medium wp-image-1425" title="vcs-cvs" src="http://www.gefira.pl/blog/wp-content/uploads/2011/10/vcs-cvs-300x257.jpg" alt="" width="300" height="257" /></a></p>
<h2>Subversion (svn)</h2>
<p><br/></p>
<p>
Now, I spent a couple of years working with svn for various corporate clients and it&#8217;s clear that&#8217;s what the prevailing majority of them can easily understand. It&#8217;s a centrally-managed system with no push and pull steps like in those fancy modern <i>distributed</i> ones and usually does its job sufficiently well. The feature most important for all the selfish &#8216;enterprise&#8217; clients is that it has a built-in <i>lock</i> command with the power to break the locks if need be.
</p>
<p><a href="http://www.gefira.pl/blog/wp-content/uploads/2011/10/vcs-svn.jpg"><img class="aligncenter size-medium wp-image-1428" title="vcs-svn" src="http://www.gefira.pl/blog/wp-content/uploads/2011/10/vcs-svn-300x225.jpg" alt="" width="300" height="225" /></a></p>
<h2>Bazaar (bzr)</h2>
<p><br/></p>
<p>
A very versatile modern system whose only issue was the maker&#8217;s marketing department who in the system&#8217;s early days wasn&#8217;t able to stop warning people that features were first and the speed advancements would come later so in the end pretty much everyone still thinks the system&#8217;s slow. Well, it isn&#8217;t. It&#8217;s called being &#8216;fast enough&#8217; my friend. Oh, and the maker&#8217;s move to hire a couple of experienced user interface designers means the system&#8217;s a pure pleasure to use with no surprising commands required for everyday usage.
</p>
<p><a href="http://www.gefira.pl/blog/wp-content/uploads/2011/10/vcs-bzr.jpg"><img class="aligncenter size-medium wp-image-1435" title="vcs-bzr" src="http://www.gefira.pl/blog/wp-content/uploads/2011/10/vcs-bzr-300x215.jpg" alt="" width="300" height="215" /></a></p>
<h2>Mercurial (hg)</h2>
<p><br/></p>
<p>
Another system that&#8217;s good all-around, fast,  fuel efficient and very comfortable to drive. Doesn&#8217;t have as many fans as it deserves to because it&#8217;s not called Volkswagen Golf even though 99% of the features are precisely the same.
</p>
<p><a href="http://www.gefira.pl/blog/wp-content/uploads/2011/10/vcs-hg.jpg"><img class="aligncenter size-full wp-image-1430" title="vcs-hg" src="http://www.gefira.pl/blog/wp-content/uploads/2011/10/vcs-hg.jpg" alt="" width="294" height="171" /></a></p>
<h2>Git</h2>
<p><br/></p>
<p>
So now it&#8217;s git. A prime example of why space rocket engineers shouldn&#8217;t really design end user-facing technologies. It&#8217;s fast and that&#8217;s all one can say. There&#8217;s no hood so all of the gory details are left exposed and you&#8217;re supposed to deal with it (like it&#8217;s natural that one needs to check out two consecutive dashes when there&#8217;s a need to <i>revert</i> something). Just notice the number of times the words &#8216;unusual&#8217;, &#8217;surprising&#8217;, &#8216;unexpected&#8217; get mentioned in books on git. Really, the only thing that makes git usable is GitHub, which indeed is a very good service, like git done correctly only in the browser.
</p>
<p><a href="http://www.gefira.pl/blog/wp-content/uploads/2011/10/vcs-git.jpg"><img class="aligncenter size-medium wp-image-1427" title="vcs-git" src="http://www.gefira.pl/blog/wp-content/uploads/2011/10/vcs-git-300x188.jpg" alt="" width="300" height="188" /></a></p>
<h2></h2>
<p>
I guess you can easily tell where my heart is, eh? <img src='http://www.gefira.pl/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.gefira.pl%2Fblog%2F2011%2F10%2F02%2Fif-version-control-systems-were-vehicles%2F&amp;title=If%20version%20control%20systems%20were%20vehicles%26%238230%3B"><img src="http://www.gefira.pl/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.gefira.pl/blog/2011/10/02/if-version-control-systems-were-vehicles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inserting new &#8216;&lt;tr&gt;&#8217; and &#8216;&lt;br/&gt;&#8217; elements with PrototypeJS</title>
		<link>http://www.gefira.pl/blog/2011/10/01/inserting-new-tr-and-br-elements-with-prototypejs/</link>
		<comments>http://www.gefira.pl/blog/2011/10/01/inserting-new-tr-and-br-elements-with-prototypejs/#comments</comments>
		<pubDate>Sat, 01 Oct 2011 21:05:59 +0000</pubDate>
		<dc:creator>Dariusz Suchojad</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PrototypeJS]]></category>

		<guid isPermaLink="false">http://www.gefira.pl/blog/?p=1397</guid>
		<description><![CDATA[Apparently one can&#8217;t insert two and more &#8216;&#60;tr&#62;&#8217; elements into a &#8216;&#60;tbody&#62;&#8217; using PrototypeJS 1.7.0.0 and 1.6.0.3 if there&#8217;s also a &#8216;&#60;br/&#62;&#8217; element involved in the conspiracy so that code simply won&#8217;t work at all:

var new_content = '&#60;tr&#62;&#60;td&#62;foo&#60;/td&#62;&#60;/tr&#62;&#60;br/&#62;&#60;tr&#62;&#60;td&#62;bar&#60;/td&#62;&#60;/tr&#62;';
$&#40;'my-tbody'&#41;.insert&#40;new_content&#41;;

One needs to leave out the poor &#8216;&#60;br/&#62;&#8217; and I guess that applies to inserting &#8216;&#60;br/&#62;&#8217; in general, [...]]]></description>
			<content:encoded><![CDATA[<p>Apparently one can&#8217;t insert two and more &#8216;&lt;tr&gt;&#8217; elements into a &#8216;&lt;tbody&gt;&#8217; using <a title="The PrototypeJS framework's homepage" href="http://prototypejs.org/">PrototypeJS</a> 1.7.0.0 and 1.6.0.3 if there&#8217;s <em>also</em> a &#8216;&lt;br/&gt;&#8217; element involved in the conspiracy so that code simply won&#8217;t work at all:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> new_content <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;tr&gt;&lt;td&gt;foo&lt;/td&gt;&lt;/tr&gt;&lt;br/&gt;&lt;tr&gt;&lt;td&gt;bar&lt;/td&gt;&lt;/tr&gt;'</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'my-tbody'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">insert</span><span style="color: #009900;">&#40;</span>new_content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>One needs to leave out the poor &#8216;&lt;br/&gt;&#8217; and I guess that applies to inserting &#8216;&lt;br/&gt;&#8217; in general, not only in this situation but thankfully right now I only need to dynamically add new table rows not line breaks..</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.gefira.pl%2Fblog%2F2011%2F10%2F01%2Finserting-new-tr-and-br-elements-with-prototypejs%2F&amp;title=Inserting%20new%20%26%238216%3B%26lt%3Btr%26gt%3B%26%238217%3B%20and%20%26%238216%3B%26lt%3Bbr%2F%26gt%3B%26%238217%3B%20elements%20with%20PrototypeJS"><img src="http://www.gefira.pl/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.gefira.pl/blog/2011/10/01/inserting-new-tr-and-br-elements-with-prototypejs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;CSRF verification failed. Request aborted. CSRF token missing or incorrect.&#8221; with Django and YUI</title>
		<link>http://www.gefira.pl/blog/2011/09/30/csrf-verification-failed-request-aborted-csrf-token-missing-or-incorrect-with-django-and-yui/</link>
		<comments>http://www.gefira.pl/blog/2011/09/30/csrf-verification-failed-request-aborted-csrf-token-missing-or-incorrect-with-django-and-yui/#comments</comments>
		<pubDate>Fri, 30 Sep 2011 08:37:17 +0000</pubDate>
		<dc:creator>Dariusz Suchojad</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.gefira.pl/blog/?p=1386</guid>
		<description><![CDATA[So if you have a piece of YUI Javascript code similar to the one shown below

function foo&#40;&#41; &#123;
&#160;
    var on_success = function&#40;o&#41; &#123;
        alert&#40;'Yay!'&#41;;
    &#125;;
&#160;
    var on_failure = function&#40;o&#41; &#123;
        alert&#40;'Oh ones!'&#41;
 [...]]]></description>
			<content:encoded><![CDATA[<p>So if you have a piece of <a title="The YUI library" href="http://developer.yahoo.com/yui/">YUI</a> Javascript code similar to the one shown below</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> foo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> on_success <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Yay!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> on_failure <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Oh ones!'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> callback <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        success<span style="color: #339933;">:</span> on_success<span style="color: #339933;">,</span>
        failure<span style="color: #339933;">:</span> on_failure<span style="color: #339933;">,</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> <span style="color: #3366CC;">'/url/to/invoke'</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> transaction <span style="color: #339933;">=</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Connect</span>.<span style="color: #660066;">asyncRequest</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'POST'</span><span style="color: #339933;">,</span> url<span style="color: #339933;">,</span> callback<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>and the URL the AJAX call invokes returns the &#8220;CSRF verification failed. Request aborted. CSRF token missing or incorrect.&#8221; error, the easiest way to properly handle is to set the custom <strong>X-CSRFToken HTTP header</strong> to the same value the <strong>csrftoken cookie</strong> has been set by Django to, just like <a title="CSRF &amp; AJAX in the Django docs" href="https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax">the Django documentation</a> says it can be done.</p>
<p>In code terms, that will do the trick</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> foo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> on_success <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Yay!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> on_failure <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Oh ones!'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> callback <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        success<span style="color: #339933;">:</span> on_success<span style="color: #339933;">,</span>
        failure<span style="color: #339933;">:</span> on_failure<span style="color: #339933;">,</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> <span style="color: #3366CC;">'/url/to/invoke'</span><span style="color: #339933;">;</span>
&nbsp;
    YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Connect</span>.<span style="color: #660066;">initHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'X-CSRFToken'</span><span style="color: #339933;">,</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Cookie</span>.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'csrftoken'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> transaction <span style="color: #339933;">=</span> YAHOO.<span style="color: #660066;">util</span>.<span style="color: #660066;">Connect</span>.<span style="color: #660066;">asyncRequest</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'POST'</span><span style="color: #339933;">,</span> url<span style="color: #339933;">,</span> callback<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Hoping this helps someone some day! <img src='http://www.gefira.pl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.gefira.pl%2Fblog%2F2011%2F09%2F30%2Fcsrf-verification-failed-request-aborted-csrf-token-missing-or-incorrect-with-django-and-yui%2F&amp;title=%26%238220%3BCSRF%20verification%20failed.%20Request%20aborted.%20CSRF%20token%20missing%20or%20incorrect.%26%238221%3B%20with%20Django%20and%20YUI"><img src="http://www.gefira.pl/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.gefira.pl/blog/2011/09/30/csrf-verification-failed-request-aborted-csrf-token-missing-or-incorrect-with-django-and-yui/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A minimal lighttpd SSL/TLS reverse proxy</title>
		<link>http://www.gefira.pl/blog/2011/08/02/a-minimal-lighttpd-ssltls-reverse-proxy/</link>
		<comments>http://www.gefira.pl/blog/2011/08/02/a-minimal-lighttpd-ssltls-reverse-proxy/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 12:05:47 +0000</pubDate>
		<dc:creator>Dariusz Suchojad</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.gefira.pl/blog/?p=1356</guid>
		<description><![CDATA[Here&#8217;s a minimal lighttpd SSL/TLS reverse proxy configuration that allows for securing the traffic to plain HTTP servers using client certificates.

For easier management, the config has been broken into two modules, the main part and a list of variables. A caveat one needs to be aware of is that even though we&#8217;re interested in lighttd&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a minimal lighttpd SSL/TLS reverse proxy configuration that allows for securing the traffic to plain HTTP servers using client certificates.</p>
<p><a href="http://www.gefira.pl/blog/wp-content/uploads/2011/08/lighttpd2.png"><img class="aligncenter wp-image-1364" title="lighttpd2" src="http://www.gefira.pl/blog/wp-content/uploads/2011/08/lighttpd2.png" alt="" /></a></p>
<p>For easier management, the config has been broken into two modules, the main part and a list of variables. A caveat one needs to be aware of is that even though we&#8217;re interested in lighttd&#8217;s proxying capabilities only, we still need to configure everything as though lighttpd was going to serve plain HTTP traffic using static files &#8211; hence the need for configuring <em>server.port</em> and <em>server.document-root</em>.</p>
<p>The config files as well as the crypto material (courtesy of the <a title="Spring Python project's home page" href="http://springpython.webfactional.com/">Spring Python</a> project) being used below can be also fetched from <a title="Alle the downloads for the blog article on a minimal lighttpd SSL/TLS reverse proxy" href="https://bitbucket.org/dsuch/stuff/src">bitbucket</a>. Of course, being uploaded to a public site, the private key is <em>useless</em> outside of a development environment and should never be used for anything close to production.</p>
<p>Enjoy <img src='http://www.gefira.pl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<pre># Include necessary modules.
server.modules = ("mod_proxy", "mod_setenv")

# Include config variables.
include "./config-variables.conf"

server.document-root = my-dummy-document-root
server.username = my-username
server.groupname = my-groupname

# IP address or hostname to listen on.
server.bind = my-host
server.port = my-plain-http-port

$SERVER["socket"] == my-host + ":" + my-ssl-client-validation-port {

    ssl.engine = "enable"
    ssl.use-sslv2 = "disable"
    ssl.verifyclient.exportcert = "enable"
    ssl.verifyclient.username = "enable"

    proxy.server = ("" =&gt; (("host"=&gt;my-backend-host,
                                     "port"=&gt;my-backend-plain-http-port)))

    # Server certificate.
    ssl.pemfile = my-ssl-server-certificate-key

    # Verify client's certificate.
    ssl.verifyclient.activate = "enable"
    ssl.verifyclient.enforce = "enable"
    ssl.verifyclient.depth = my-verifyclient-depth
    ssl.ca-file = my-ca-certificate
}</pre>
<pre>var.my-host = "localhost"
var.my-ssl-client-validation-port = "17443"
var.my-plain-http-port = "18080"
var.my-backend-host = "localhost"
var.my-backend-plain-http-port = "28080"
var.my-dummy-document-root="./"
var.my-username="dsuch"
var.my-groupname="dsuch"
var.my-ssl-server-certificate-key = "server-pair.pem"
var.my-ca-certificate = "./ca-chain.pem"
var.my-verifyclient-depth = "3"</pre>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.gefira.pl%2Fblog%2F2011%2F08%2F02%2Fa-minimal-lighttpd-ssltls-reverse-proxy%2F&amp;title=A%20minimal%20lighttpd%20SSL%2FTLS%20reverse%20proxy"><img src="http://www.gefira.pl/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.gefira.pl/blog/2011/08/02/a-minimal-lighttpd-ssltls-reverse-proxy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

