<?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>My Own Private Thermopylae &#187; Python</title>
	<atom:link href="http://thermopylae.net/blog/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://thermopylae.net/blog</link>
	<description>Do I know what a rhetorical question is?</description>
	<lastBuildDate>Sat, 14 Mar 2009 18:53:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Login on behalf of a user in Django</title>
		<link>http://thermopylae.net/blog/2009/02/26/login-on-behalf-ofa-user-in-django/</link>
		<comments>http://thermopylae.net/blog/2009/02/26/login-on-behalf-ofa-user-in-django/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 18:57:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://thermopylae.net/blog/?p=107</guid>
		<description><![CDATA[There are several points during the pieces of a Django app&#8217;s lifecycle where you&#8217;d like to log in a user without going through the standard login views. These are situations when the user has authenticated their identity in some other way, for example: User just successfully signed up.  There&#8217;s no reason to ask them to [...]]]></description>
			<content:encoded><![CDATA[<p>There are several points during the pieces of a Django app&#8217;s lifecycle where you&#8217;d like to log in a user without going through the standard login views. These are situations when the user has authenticated their identity in some other way, for example:</p>
<ul>
<li>User just successfully signed up.  There&#8217;s no reason to ask them to re-enter the credentials they just set up.</li>
<li>User just reset their password.</li>
</ul>
<p>The official documentation isn&#8217;t super clear on how to do it, but it turns out its incredibly easy:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span>.<span style="color: black;">auth</span> <span style="color: #ff7700;font-weight:bold;">import</span> login
&nbsp;
<span style="color: #dc143c;">user</span>.<span style="color: black;">backend</span> = <span style="color: #483d8b;">'django.contrib.auth.backends.ModelBackend'</span>
login<span style="color: black;">&#40;</span>request, <span style="color: #dc143c;">user</span><span style="color: black;">&#41;</span></pre></div></div>

<p>The backend is used by the auth system later on in the process.</p>
]]></content:encoded>
			<wfw:commentRss>http://thermopylae.net/blog/2009/02/26/login-on-behalf-ofa-user-in-django/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Facebook API &#8211; setFBML() and profile_main</title>
		<link>http://thermopylae.net/blog/2008/09/10/facebook-api-setfbml-profile-main/</link>
		<comments>http://thermopylae.net/blog/2008/09/10/facebook-api-setfbml-profile-main/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 07:26:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://thermopylae.net/blog/?p=68</guid>
		<description><![CDATA[This is a stupid gotcha that took me WAAAAY too long to figure out. If you&#8217;re using the Facebook API with the new profile pages and attempting to set the FBML for a box on the wall and info pages it won&#8217;t work out of the box. You need to take whichever client library you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>This is a stupid gotcha that took me WAAAAY too long to figure out.</p>
<p>If you&#8217;re using the Facebook API with the new profile pages and attempting to set the FBML for a box on the wall and info pages it won&#8217;t work out of the box. You need to take whichever client library you&#8217;re using (PyFacebook, PHP, etc.) and make sure to point it at  <code>http://api.new.facebook.com/</code>. Only then will the profile_main parameter get properly parsed. It would be fabulous if Facebook was to make API differences like that explicit by say, oh, I don&#8217;t know, revving the protocol version?</p>
<p>In addition, if you&#8217;re using PyFacebook (at least up to r157) you should add the type parameter to facebook.profile.getFBML() in the __init__.py file for the library. Here&#8217;s <a href="http://code.google.com/p/pyfacebook/issues/detail?id=80">the open issue</a> in PyFacebook&#8217;s issue tracker.</p>
]]></content:encoded>
			<wfw:commentRss>http://thermopylae.net/blog/2008/09/10/facebook-api-setfbml-profile-main/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Playing with S3 in Python</title>
		<link>http://thermopylae.net/blog/2008/07/22/playing-with-s3-in-python/</link>
		<comments>http://thermopylae.net/blog/2008/07/22/playing-with-s3-in-python/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 22:31:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[S3]]></category>

		<guid isPermaLink="false">http://thermopylae.net/blog/?p=4</guid>
		<description><![CDATA[This is a brief guide to getting up and running against S3 in Python. You will need the following things: AWS Developer account (you can sign up for it on http://aws.amazon.com) Make sure you sign up for S3 (select Amazon Simple Storage Service in the sidebar on the left of the AWS page and then [...]]]></description>
			<content:encoded><![CDATA[<p>This is a brief guide to getting up and running against S3 in Python.</p>
<p>You will need the following things:</p>
<ol>
<li>AWS Developer account (you can sign up for it on <a href="http://aws.amazon.com">http://aws.amazon.com</a>)</li>
<li>Make sure you sign up for S3 (select Amazon Simple Storage Service in the sidebar on the left of the AWS page and then click &#8216;Sign Up For This Web Service&#8217; over on the right)</li>
<li>Python (I&#8217;m assuming you have it set up and working already)</li>
</ol>
<p>A great library to use for access to AWS is called boto and its homepage is here: <a href="http://code.google.com/p/boto">http://code.google.com/p/boto</a>. You can download the code directly and then run its setup.py to install it, or if you already have <a href="http://peak.telecommunity.com/DevCenter/EasyInstall">easy_install</a> you can make it do all of the work:</p>
<pre class="shell">C:boto-1.3a&gt;python setup.py install</pre>
<p>or</p>
<pre class="shell">C:&gt;python easy_install.py boto</pre>
<p>Either way, you can verify that boto is properly installed by trying to import it in python:</p>
<pre class="shell">C:&gt;python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import boto
&gt;&gt;&gt;</pre>
<p>Once boto is set up correctly get your AWS identifiers from the &#8220;Your Web Services Account&#8221; dropdown in the upper right of the AWS pages. You&#8217;ll need to use both the Access key and the Secret key when you make the connection.</p>
<p>At the highest level AWS stores data in &#8216;buckets&#8217;. These are unique across the entire service and each account is limited to a max of 100 of them. Within the bucket you create key/data pairs that look like filenames.</p>
<p>The code to do this is super simple. You&#8217;ll probably need to replace &#8216;examplebucket&#8217; with something else:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> boto.<span style="color: black;">s3</span>.<span style="color: black;">connection</span> <span style="color: #ff7700;font-weight:bold;">import</span> S3Connection
<span style="color: #ff7700;font-weight:bold;">from</span> boto.<span style="color: black;">s3</span>.<span style="color: black;">key</span> <span style="color: #ff7700;font-weight:bold;">import</span> Key
conn = S3Connection<span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span>, <span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span>
bucket = conn.<span style="color: black;">create_bucket</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'examplebucket'</span><span style="color: black;">&#41;</span>
k = Key<span style="color: black;">&#40;</span>bucket<span style="color: black;">&#41;</span>
k.<span style="color: black;">key</span> = <span style="color: #483d8b;">'foo'</span>
k.<span style="color: black;">set_contents_from_filename</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'foo.png'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Doing this will upload the file foo.png to the bucket &#8216;examplebucket&#8217;. That would mean that the file is accessible at: http://s3.amazonaws.com/examplebucket/foo. If you attempt to go to the appropriate URL for that file you&#8217;ll get an access denied error back. By default new objects in the bucket aren&#8217;t publicly readable. Making the object readable takes advantage of a shortcut built into boto. In the boto.s3.acl module there is a list of &#8216;ready-to-use&#8217; modes:</p>
<pre class="shell">CannedACLStrings = ['private', 'public-read', 'public-read-write', 'authenticated-read']</pre>
<p>Now we just set the &#8216;public-read&#8217; ACL on our key and it will become accessible through the URL:</p>
<pre class="shell">k.set_acl('public-read')</pre>
<p>From here, check out the <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=123&#038;ref=latest-docs">official documentation</a> and tools such as <a href="https://addons.mozilla.org/en-US/firefox/addon/3247">S3Fox</a> that will make your S3 experience much easier.</p>
<p>You should also grab the bota documentation archive and save it locally to use as a reference.</p>
]]></content:encoded>
			<wfw:commentRss>http://thermopylae.net/blog/2008/07/22/playing-with-s3-in-python/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
