<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Fragments of Code</title>
	<atom:link href="http://fragmentsofcode.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://fragmentsofcode.wordpress.com</link>
	<description>Some assembly required</description>
	<lastBuildDate>Fri, 27 Jan 2012 21:43:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='fragmentsofcode.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Fragments of Code</title>
		<link>http://fragmentsofcode.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://fragmentsofcode.wordpress.com/osd.xml" title="Fragments of Code" />
	<atom:link rel='hub' href='http://fragmentsofcode.wordpress.com/?pushpress=hub'/>
		<item>
		<title>WSGI daemon mode solves python-ldap connection issues</title>
		<link>http://fragmentsofcode.wordpress.com/2012/01/27/wsgi-daemon-mode-solves-python-ldap-connection-issues/</link>
		<comments>http://fragmentsofcode.wordpress.com/2012/01/27/wsgi-daemon-mode-solves-python-ldap-connection-issues/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 21:43:00 +0000</pubDate>
		<dc:creator>David Chandek-Stark</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[mod_wsgi]]></category>
		<category><![CDATA[WSGI]]></category>

		<guid isPermaLink="false">http://fragmentsofcode.wordpress.com/?p=733</guid>
		<description><![CDATA[I was porting a Django/python-ldap application to another server and getting sporadic ldap.SERVER_DOWN errors.  Some basic troubleshooting showed that the problem was occurring specifically when requests routed through mod_wsgi.  If I just ran the Python code &#8212; no problem; just the Django app via the dev server &#8212; fine; Apache straight to Django (proxying to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=733&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was porting a Django/python-ldap application to another server and getting sporadic ldap.SERVER_DOWN errors.  Some basic troubleshooting showed that the problem was occurring specifically when requests routed through mod_wsgi.  If I just ran the Python code &#8212; no problem; just the Django app via the dev server &#8212; fine; Apache straight to Django (proxying to dev server) &#8212; OK.  Now, while I had been planning to investigate mod_wsgi&#8217;s &#8220;daemon mode&#8221; for some time, I was still running all my apps in &#8220;embedded mode&#8221;.  But with this python-ldap problem, I had to dig deeper into the docs.  The mod_wsgi <a href="http://code.google.com/p/modwsgi/wiki/ApplicationIssues">ApplicationIssues</a> page discusses a number of problems related to C extension modules, and while not specifically mentioning python-ldap, it does make this generalization:</p>
<blockquote><p>Because of the possibilty that extension module writers have not written their code to take into consideration it being used from multiple sub interpreters, the safest approach is to force all WSGI applications to run within the same application group, with that preferably being the first interpreter instance created by Python.</p>
<p>To force a specific WSGI application to be run within the very first Python sub interpreter created when Python is initialised, the WSGIApplicationGroup directive should be used and the group set to &#8216;%{GLOBAL}&#8217;.</p>
<p><code>WSGIApplicationGroup %{GLOBAL}</code></p>
<p>If it is not feasible to force all WSGI applications to run in the same interpreter, then daemon mode of mod_wsgi should be used to assign different WSGI applications to their own daemon processes. Each would then be made to run in the first Python sub interpreter instance within their respective processes.</p></blockquote>
<p>I did try <code>WSGIApplicationGroup %{GLOBAL}</code> first, but (assuming I implemented it correctly), the problem remained. So I tried WSGI daemon mode and the process has proved stable.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fragmentsofcode.wordpress.com/733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fragmentsofcode.wordpress.com/733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fragmentsofcode.wordpress.com/733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fragmentsofcode.wordpress.com/733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fragmentsofcode.wordpress.com/733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fragmentsofcode.wordpress.com/733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fragmentsofcode.wordpress.com/733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fragmentsofcode.wordpress.com/733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fragmentsofcode.wordpress.com/733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fragmentsofcode.wordpress.com/733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fragmentsofcode.wordpress.com/733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fragmentsofcode.wordpress.com/733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fragmentsofcode.wordpress.com/733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fragmentsofcode.wordpress.com/733/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=733&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fragmentsofcode.wordpress.com/2012/01/27/wsgi-daemon-mode-solves-python-ldap-connection-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dchandek</media:title>
		</media:content>
	</item>
		<item>
		<title>A detached user object for Django</title>
		<link>http://fragmentsofcode.wordpress.com/2011/11/18/a-detached-user-object-for-django/</link>
		<comments>http://fragmentsofcode.wordpress.com/2011/11/18/a-detached-user-object-for-django/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 23:31:23 +0000</pubDate>
		<dc:creator>David Chandek-Stark</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://fragmentsofcode.wordpress.com/?p=712</guid>
		<description><![CDATA[Django&#8217;s authentication framework (django.contrib.auth) is both pluggable and stackable, which makes integrating custom authentication requirements into Django pretty smooth and easy in most cases.  But I had an edge case: the user ids of the backend system could not be guaranteed to conform to Django&#8217;s restriction on user names (even with the recent expansion to accommodate [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=712&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Django&#8217;s authentication framework (<code>django.contrib.auth</code>) is both pluggable and stackable, which makes integrating custom authentication requirements into Django pretty smooth and easy in most cases.  But I had an edge case: the user ids of the backend system could not be guaranteed to conform to Django&#8217;s restriction on user names (even with the recent expansion to accommodate email addresses).  Thus the usual pattern of creating a Django user corresponding to each backend account required a workaround.  At first I tried a hack in which user id from the backend were base64-encoded and munged to conform to Django&#8217;s user name limits.  Communication with the backend then required de-munging and decoding the Django user name, etc.  While this seemed to work it was ugly as hell, and in any case, I was using neither the Django admin site nor Django permissions, so I didn&#8217;t need a real Django User model instance for that.  On the other hand, I did want to keep the goodness of my pluggable authentication backend and the login view from <code>django.contrib.auth.views</code>, both of which expect User-like objects.</p>
<p>So, I decided to try something kinda crazy: subclassing <code>django.contrib.auth.models.AnonymousUser</code>  and overriding the &#8220;anonymity&#8221;.  <code>AnonymousUser</code> really takes advantage of Python <a href="http://en.wikipedia.org/wiki/Duck_typing">duck-typing</a> by mimicking the <code>django.contrib.auth.models.User</code> without being a Django model itself, and so isn&#8217;t tied to Django&#8217;s database.  Here&#8217;s what I came up with:</p>
<pre>from django.contrib.auth.models import AnonymousUser

class DetachedUser(AnonymousUser):
    """
    Implements a user-like object for user authentication
    when linkage of a backend user identity to a Django user
    is undesirable or unnecessary.
    """

    # mark as not hashable -- see also __eq__() and __ne__(), below
    __hash__ = None 

    # is_active might matter in some contexts, so override
    is_active = True 

    #
    # AnonymousUser sets username to '' and id to None, so we need to at least
    # override those values.
    #
    def __init__(self, username):
        self.username = username
        self.id = username

    def __unicode__(self):
        return self.username

    #
    # is_anonymous() and is_authenticated() are key to distinguishing truly
    # anonymous/unauthenticated users from known/authenticated ones.
    #
    def is_anonymous(self):
        return False

    def is_authenticated(self):
        return True

    #
    # __eq__ and __ne__ are related to hashing, so be consistent with __hash__, above.
    #
    def __eq__(self, other):
        return NotImplemented

    def __ne__(self, other):
        return NotImplemented

    #
    # Some django.contrib.auth code may call this method,
    # e.g, to update the last login time
    #
    def save(self):
        pass</pre>
<p>Now I can code the <code>get_user</code> and <code>authenticate</code> methods of my custom authentication backend to return <code>DetachedUser</code> objects instead of Django users. So far, so good.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fragmentsofcode.wordpress.com/712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fragmentsofcode.wordpress.com/712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fragmentsofcode.wordpress.com/712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fragmentsofcode.wordpress.com/712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fragmentsofcode.wordpress.com/712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fragmentsofcode.wordpress.com/712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fragmentsofcode.wordpress.com/712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fragmentsofcode.wordpress.com/712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fragmentsofcode.wordpress.com/712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fragmentsofcode.wordpress.com/712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fragmentsofcode.wordpress.com/712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fragmentsofcode.wordpress.com/712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fragmentsofcode.wordpress.com/712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fragmentsofcode.wordpress.com/712/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=712&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fragmentsofcode.wordpress.com/2011/11/18/a-detached-user-object-for-django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dchandek</media:title>
		</media:content>
	</item>
		<item>
		<title>Django-Apache-WSGI reverse proxy and load balancing</title>
		<link>http://fragmentsofcode.wordpress.com/2011/11/15/django-apache-wsgi-reverse-proxy-and-load-balancing/</link>
		<comments>http://fragmentsofcode.wordpress.com/2011/11/15/django-apache-wsgi-reverse-proxy-and-load-balancing/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 20:56:58 +0000</pubDate>
		<dc:creator>David Chandek-Stark</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://fragmentsofcode.wordpress.com/?p=679</guid>
		<description><![CDATA[Serving Django apps behind a reverse proxy is really pretty straightforward once you&#8217;ve set it up, but you might run into a few snags along the way, depending on your requirements.  Load-balancing only adds a little more complexity.  Here&#8217;s how I&#8217;ve done it. Example Architecture Front end web server (www.example.com): Apache 2.2 + mod_proxy, mod_proxy_balancer, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=679&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Serving Django apps behind a reverse proxy is really pretty straightforward once you&#8217;ve set it up, but you might run into a few snags along the way, depending on your requirements.  Load-balancing only adds a little more complexity.  Here&#8217;s how I&#8217;ve done it.</p>
<p><strong>Example Architecture</strong></p>
<ul>
<li>Front end web server (www.example.com): <em>Apache 2.2 + mod_proxy, mod_proxy_balancer, mod_ssl.</em></li>
<li>Back end application servers (apps-01.example.com, apps-02.example.com): <em>Apache 2.2 + mod_wsgi, mod_ssl; Python 2.6; Django 1.3.1.</em></li>
<li>Backend database server.</li>
<li>Additional requirements: <em>Remote user authentication; SSL and non-SSL proxies.</em></li>
</ul>
<p>Let&#8217;s start with the application servers and deal with the front end later.</p>
<h2>Application Servers</h2>
<p>Obviously both app servers will be configured the same way.  How to keep them in sync will be discussed briefly.</p>
<p><strong>Django Settings Module</strong></p>
<p>In order for Django to properly create fully-qualified URLs for the front-end client, you must set:</p>
<pre>USE_X_FORWARDED_HOST = True</pre>
<p>This setting, new in Django 1.3.1, affects the <code>get_host()</code> and <code>build_absolute_uri()</code> methods of <code>django.http.HttpRequest</code>.  If not set, Django will use the value of the <code>HTTP_HOST</code> or <code>SERVER_NAME</code> variables, which are most likely set to the host name of the app server, not the front end.</p>
<p>If you&#8217;re using Django&#8217;s <code>RemoteUserMiddleware</code> and <code>RemoteUserBackend</code> for authentication, you will need to replace <code>RemoteUserMiddleware</code> with a custom subclass:</p>
<pre>from django.contrib.auth.middleware import RemoteUserMiddleware

class ProxyRemoteUserMiddleware(RemoteUserMiddleware):
    header = 'HTTP_REMOTE_USER'</pre>
<p>Then update your settings:</p>
<pre>MIDDLEWARE_CLASSES = (
    'path.to.ProxyRemoteUserMiddleware',
    )</pre>
<p>(It is possible to avoid this by setting <code>REMOTE_USER</code> on the app web server to the value of <code>HTTP_REMOTE_USER</code>, but here I will assume a default setup.)</p>
<p>If you&#8217;re using Django&#8217;s &#8220;sites&#8221; framework, you will probably want to set <code>SITE_ID</code> to correspond to the front-end site.  And if your <code>WSGIScriptAlias</code> path differs from the proxied path on the front-end server (not covered in detail here), you may have to use <code>FORCE_SCRIPT_NAME</code> (check the docs).</p>
<p><strong>Django Application Modules and Templates</strong></p>
<p>If your code or templates contain references to <code>REMOTE_ADDR</code>, <code>REMOTE_USER</code> or other server variables (via <code>HttpRequest.META</code>) affected by proxies, you will probably have to change them.  If you&#8217;re using Django&#8217;s <code>RemoteUserMiddleware</code> or the <code>ProxyRemoteUserMiddleware</code> subclass shown above, you should probably code with <code>request.user.username</code> instead of <code>request.META['REMOTE_USER']</code>; otherwise, you&#8217;ll want to reference <code>HTTP_REMOTE_USER</code>.  <code>REMOTE_ADDR</code> will be set to the IP address of the app server, not the proxy front-end; instead you will have to use <code>HTTP_X_FORWARDED_FOR</code>, which can have multiple comma-separated values.</p>
<p><strong>Django Projects and Python Environments</strong></p>
<p>Since we&#8217;ve got two app servers, each will have its own Python environment (created with virtualenv) and Django project.  In my setup I decided to serve the Django <code>MEDIA_ROOT</code> from network storage mounted at the same point on each server to avoid synchronization issues.  Otherwise, it seems OK to keep each instance separate (YMMV).  I use <a href="http://fabfile.org/">Fabric</a> for ensuring that the Python environments and Django projects stay in sync across the two servers.  The precise way you do this syncing depends on your preferences, the available tools, etc.</p>
<p><strong>Apache Configuration</strong></p>
<p>The Apache config on each app server follows the normal Django/WSGI pattern, so I&#8217;ll skip the details here.  Note that while it is possible for <code>WSGIScriptAlias</code> path on the app server to differ from the proxied path on the front-end web server (which we&#8217;ll get to), this introduces some additional complexities which we will avoid here.  Some issues can be handled on the reverse proxy (front-end) server by Apache directives such as <code>ProxyPassReverse</code> and <code>ProxyPassReverseCookiePath</code>, but you may also need to use Django&#8217;s <code>FORCE_SCRIPT_PATH</code> setting in your project settings module.</p>
<h2>Front-end Server</h2>
<p>At this point you should have working Django projects on each app server under both SSL and non-SSL virtual hosts.  Now we&#8217;re going to set up the reverse proxy and load balancing on the front-end server.</p>
<p>Let&#8217;s assume your apps are served under the path <code>/webapps</code> on both port 80 and port 443 (SSL) virtual hosts.</p>
<p>Then, you can add to your port 80 virtual host:</p>
<pre>&lt;Proxy balancer://django-http&gt;
    BalancerMember http://apps-01.example.com/webapps route=http-1
    BalancerMember http://apps-02.example.com/webapps route=http-2
&lt;/Proxy&gt;

&lt;Location /webapps&gt;
    ProxyPass balancer://django-http stickysession=sessionid
    ProxyPassReverse http://apps-01.example.com/webapps
    ProxyPassReverse http://apps-02.example.com/webapps
    ProxyPassReverseCookieDomain apps-01.example.com www.example.com
    ProxyPassReverseCookieDomain apps-02.example.com www.example.com
&lt;/Location&gt;</pre>
<p>And to your SSL virtual host on port 443:</p>
<pre>&lt;Proxy balancer://django-https&gt;
    BalancerMember https://apps-01.example.com/webapps route=https-1
    BalancerMember https://apps-02.example.com/webapps route=https-2
&lt;/Proxy&gt;

&lt;Location /webapps&gt;
    ProxyPass balancer://django-https stickysession=sessionid
    ProxyPassReverse https://apps-01.example.com/webapps
    ProxyPassReverse https://apps-02.example.com/webapps
    ProxyPassReverseCookieDomain apps-01.example.com www.example.com
    ProxyPassReverseCookieDomain apps-02.example.com www.example.com
&lt;/Location&gt;</pre>
<p>This isn&#8217;t the only way to do it, of course, and you may have different requirements, but I&#8217;ve tried to cover the basics.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fragmentsofcode.wordpress.com/679/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fragmentsofcode.wordpress.com/679/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fragmentsofcode.wordpress.com/679/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fragmentsofcode.wordpress.com/679/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fragmentsofcode.wordpress.com/679/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fragmentsofcode.wordpress.com/679/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fragmentsofcode.wordpress.com/679/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fragmentsofcode.wordpress.com/679/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fragmentsofcode.wordpress.com/679/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fragmentsofcode.wordpress.com/679/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fragmentsofcode.wordpress.com/679/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fragmentsofcode.wordpress.com/679/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fragmentsofcode.wordpress.com/679/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fragmentsofcode.wordpress.com/679/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=679&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fragmentsofcode.wordpress.com/2011/11/15/django-apache-wsgi-reverse-proxy-and-load-balancing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dchandek</media:title>
		</media:content>
	</item>
		<item>
		<title>SVN 1.7 breaks Python packaging</title>
		<link>http://fragmentsofcode.wordpress.com/2011/11/14/svn-1-7-breaks-python-packaging/</link>
		<comments>http://fragmentsofcode.wordpress.com/2011/11/14/svn-1-7-breaks-python-packaging/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 18:54:58 +0000</pubDate>
		<dc:creator>David Chandek-Stark</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://fragmentsofcode.wordpress.com/?p=675</guid>
		<description><![CDATA[Forget my problems with Emacs and SVN 1.7.  A much worse problem is that my Python package distributions are breaking because neither setuptools nor distribute groks the new working copy format introduced in SVN 1.7, and so not all files which are actually under version control get included in the output of dist commands (without [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=675&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Forget <a title="Emacs + SVN 1.7 = Ouch" href="http://fragmentsofcode.wordpress.com/2011/10/31/emacs-svn-1-7-ouch/">my problems with Emacs and SVN 1.7</a>.  A much worse problem is that my Python package distributions are breaking because neither <a href="http://bugs.python.org/setuptools/issue79">setuptools</a> nor <a href="https://bitbucket.org/tarek/distribute/issue/252/subversion-17-introduces-new-storage">distribute</a> groks the new working copy format introduced in SVN 1.7, and so not all files which are actually under version control get included in the output of dist commands (without using an explicit manifest).  So, I&#8217;m forced to downgrade to SVN 1.6, which is alright by me.  First I had to uninstall from Cygwin SVN and all packages that depend on it.  Then I installed the SlikSVN Win64 distribution of SVN 1.6.  And, finally, I had to trash all my SVN 1.7 working copies (no way to downgrade those) and re-checkout everything.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fragmentsofcode.wordpress.com/675/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fragmentsofcode.wordpress.com/675/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fragmentsofcode.wordpress.com/675/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fragmentsofcode.wordpress.com/675/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fragmentsofcode.wordpress.com/675/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fragmentsofcode.wordpress.com/675/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fragmentsofcode.wordpress.com/675/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fragmentsofcode.wordpress.com/675/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fragmentsofcode.wordpress.com/675/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fragmentsofcode.wordpress.com/675/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fragmentsofcode.wordpress.com/675/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fragmentsofcode.wordpress.com/675/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fragmentsofcode.wordpress.com/675/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fragmentsofcode.wordpress.com/675/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=675&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fragmentsofcode.wordpress.com/2011/11/14/svn-1-7-breaks-python-packaging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dchandek</media:title>
		</media:content>
	</item>
		<item>
		<title>Emacs + SVN 1.7 = Ouch</title>
		<link>http://fragmentsofcode.wordpress.com/2011/10/31/emacs-svn-1-7-ouch/</link>
		<comments>http://fragmentsofcode.wordpress.com/2011/10/31/emacs-svn-1-7-ouch/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 15:27:46 +0000</pubDate>
		<dc:creator>David Chandek-Stark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fragmentsofcode.wordpress.com/?p=668</guid>
		<description><![CDATA[It&#8217;s only partly in jest when I say that working in IT means being annoyed most of the time.   Sometimes it feels that way.  The latest annoyance came last week: updating my Cygwin install brought SVN 1.7.  I knew about the required updating of working copies to the new format.  What I didn&#8217;t know [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=668&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s only partly in jest when I say that working in IT means being annoyed most of the time.   Sometimes it feels that way.  The latest annoyance came last week: updating my Cygwin install brought SVN 1.7.  I knew about the required updating of working copies to the new format.  What I didn&#8217;t know was that my beloved <a href="http://benjisimon.blogspot.com/2011/10/gotcha-of-day-emacs-svn-support-breaks.html">Emacs version control integration would break</a> so horribly.  I suppose this is another reason for Emacs-haters to chuckle, and I&#8217;m rarely inclined to tinker with the config or try alternative Emacs modes, so I&#8217;m basically stuck with the brokenness until a fix comes down stream.  All in a day&#8217;s work.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fragmentsofcode.wordpress.com/668/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fragmentsofcode.wordpress.com/668/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fragmentsofcode.wordpress.com/668/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fragmentsofcode.wordpress.com/668/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fragmentsofcode.wordpress.com/668/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fragmentsofcode.wordpress.com/668/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fragmentsofcode.wordpress.com/668/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fragmentsofcode.wordpress.com/668/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fragmentsofcode.wordpress.com/668/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fragmentsofcode.wordpress.com/668/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fragmentsofcode.wordpress.com/668/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fragmentsofcode.wordpress.com/668/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fragmentsofcode.wordpress.com/668/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fragmentsofcode.wordpress.com/668/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=668&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fragmentsofcode.wordpress.com/2011/10/31/emacs-svn-1-7-ouch/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dchandek</media:title>
		</media:content>
	</item>
		<item>
		<title>Use the framework</title>
		<link>http://fragmentsofcode.wordpress.com/2011/05/20/use-the-framework/</link>
		<comments>http://fragmentsofcode.wordpress.com/2011/05/20/use-the-framework/#comments</comments>
		<pubDate>Fri, 20 May 2011 18:16:47 +0000</pubDate>
		<dc:creator>David Chandek-Stark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[applications]]></category>
		<category><![CDATA[frameworks]]></category>

		<guid isPermaLink="false">http://fragmentsofcode.wordpress.com/?p=639</guid>
		<description><![CDATA[I don&#8217;t know how many times I&#8217;ve developed or implemented some clever enhancement of an application or framework (e.g., Plone, Django, others) only to regret it later.  Of course it always seems like a reasonable idea at the time, but the more repetitions of this pattern I experience, the more skeptical I am of fancy [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=639&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know how many times I&#8217;ve developed or implemented some clever enhancement of an application or framework (e.g., Plone, Django, others) only to regret it later.  Of course it always seems like a reasonable idea <em>at the time</em>, but the more repetitions of this pattern I experience, the more skeptical I am of fancy solutions (included many of my own published on this site) and add-ons that promise short-term feature additions but too often incur long-term maintenance costs that simply aren&#8217;t worth the benefits.  Here&#8217;s how I&#8217;m thinking about it now:</p>
<ul>
<li><strong>Don&#8217;t reverse engineer the system.</strong>  By all means, read the code, just don&#8217;t try to outsmart it.</li>
<li><strong>If you can help it, don&#8217;t use methods or attributes marked as private </strong>(yes, I have a beef with Django&#8217;s <code>Model._meta</code>).</li>
<li><strong>Don&#8217;t use a third-party product for something you can do <em>relatively easily</em> without it.</strong>  Stop and ask yourself if the coding you may save is worth the headache of maintaining the product through framework upgrades, etc.</li>
<li><strong>Keep an eye on framework developments. </strong> Watch the roadmap.  Read the release notes!  I&#8217;ve been pleasantly surprised a number of times to find out about new (or existing) features by re-reading documentation.</li>
<li><strong>Participate in the core community.</strong>  Everybody benefits from improvements to the core framework.  This is not to say that every good product should ultimately aim for inclusion in the framework, but with a strong group of core developers new features are subjected to critical analysis, rigorous testing and benefit from wide usage and long term support.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fragmentsofcode.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fragmentsofcode.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fragmentsofcode.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fragmentsofcode.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fragmentsofcode.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fragmentsofcode.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fragmentsofcode.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fragmentsofcode.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fragmentsofcode.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fragmentsofcode.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fragmentsofcode.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fragmentsofcode.wordpress.com/639/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fragmentsofcode.wordpress.com/639/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fragmentsofcode.wordpress.com/639/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=639&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fragmentsofcode.wordpress.com/2011/05/20/use-the-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dchandek</media:title>
		</media:content>
	</item>
		<item>
		<title>Django management command barfs on sites framework</title>
		<link>http://fragmentsofcode.wordpress.com/2011/05/20/django-management-command-barfs-on-sites-framework/</link>
		<comments>http://fragmentsofcode.wordpress.com/2011/05/20/django-management-command-barfs-on-sites-framework/#comments</comments>
		<pubDate>Fri, 20 May 2011 16:49:01 +0000</pubDate>
		<dc:creator>David Chandek-Stark</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[management commands]]></category>
		<category><![CDATA[memoization]]></category>
		<category><![CDATA[sites framework]]></category>

		<guid isPermaLink="false">http://fragmentsofcode.wordpress.com/?p=633</guid>
		<description><![CDATA[As always, the story is a bit convoluted &#8230; I had recently made changes to the get_absolute_url() methods on a couple of application models (Django 1.3/Python 2.4).  For various reasons, the admin UI for the app is on an intranet site, which is a different host from the public site (represented by a different Django [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=633&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As always, the story is a bit convoluted &#8230;</p>
<p>I had recently made changes to the <code>get_absolute_url()</code> methods on a couple of application models (Django 1.3/Python 2.4).  For various reasons, the admin UI for the app is on an intranet site, which is a different host from the public site (represented by a different Django <code>Site</code> object).  The changes involved calling a new function that uses the current site object to determine the appropriate domain for constructing a fully-qualified URL for <code>get_absolute_url()</code>.  As originally implemented, I set a variable at the module level in <code>models.py</code>:</p>
<pre>BASE_PUBLIC_URL = 'http://%s/path/to/app' % get_public_domain()</pre>
<p>where <code>get_public_domain()</code> imports the <code>Site</code> model class from <code>django.contrib.sites, </code>calls <code>Site.objects.get_current()</code> and returns the appropriate public domain.  The <code>get_absolute_url()</code> methods then used <code>BASE_PUBLIC_URL</code> in constructing the final URL.</p>
<p>This worked fine in the normal application contexts, i.e., the admin site and the public site.  However, a custom management command which updates app data from an external source raised an <code>ImportError</code> on the relevant model.  The significant part of the traceback was as follows:</p>
<pre>  File "/path/to/pyenv/lib/python2.4/site-packages/django/contrib/sites/models.py", line 25, in get_current
    current_site = self.get(pk=sid)</pre>
<p>Ad hoc testing showed the <code>ImportError</code> to be a red herring &#8212; and, in any case, it didn&#8217;t square with the fact that the rest of the app (minus the admin command) was functional.</p>
<p>Now, the management command doesn&#8217;t actually call <code>get_absolute_url()</code>, so I figured that maybe the solution was to wrap the base public URL in a memoized function, so that the current site object is accessed lazily:</p>
<pre>@memoize
def get_base_public_url():
    from path.to.mymodule import get_public_domain
    return 'http://%s/path/to/app' % get_public_domain()</pre>
<p>That did the trick.  I&#8217;m still not sure exactly why the sites framework barfed, and it doesn&#8217;t seem worth digging for &#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fragmentsofcode.wordpress.com/633/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fragmentsofcode.wordpress.com/633/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fragmentsofcode.wordpress.com/633/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fragmentsofcode.wordpress.com/633/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fragmentsofcode.wordpress.com/633/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fragmentsofcode.wordpress.com/633/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fragmentsofcode.wordpress.com/633/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fragmentsofcode.wordpress.com/633/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fragmentsofcode.wordpress.com/633/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fragmentsofcode.wordpress.com/633/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fragmentsofcode.wordpress.com/633/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fragmentsofcode.wordpress.com/633/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fragmentsofcode.wordpress.com/633/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fragmentsofcode.wordpress.com/633/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=633&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fragmentsofcode.wordpress.com/2011/05/20/django-management-command-barfs-on-sites-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dchandek</media:title>
		</media:content>
	</item>
		<item>
		<title>Django 1.3 First Impressions</title>
		<link>http://fragmentsofcode.wordpress.com/2011/04/01/django-1-3-first-impressions/</link>
		<comments>http://fragmentsofcode.wordpress.com/2011/04/01/django-1-3-first-impressions/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 21:43:39 +0000</pubDate>
		<dc:creator>David Chandek-Stark</dc:creator>
				<category><![CDATA[Django]]></category>

		<guid isPermaLink="false">http://fragmentsofcode.wordpress.com/?p=622</guid>
		<description><![CDATA[On the whole I am very pleased with Django 1.3.  The developers did a good job of taking care of some of the outstanding warts in Django, particularly the lack of &#8220;static file&#8221; management.  While I have not yet used the django.contrib.staticfiles app, it appears to solve the problem in a reasonable way.  Now I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=622&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>On the whole I am very pleased with Django 1.3.  The developers did a good job of taking care of some of the outstanding warts in Django, particularly the lack of &#8220;static file&#8221; management.  While I have not yet used the <code>django.contrib.staticfiles</code> app, it appears to solve the problem in a reasonable way.  Now I can retire the workarounds (such as <a title="Managing static files for Django applications" href="http://fragmentsofcode.wordpress.com/2009/01/07/managing-static-files-for-django-applications/">this</a>) that I had developed to deal with the problem.  The addition of built-in logging support is certainly welcome.  Improving and fixing inconsistencies in certain template tags all seems good.  I previously <a title="Django: Hurray for the render() shortcut" href="http://fragmentsofcode.wordpress.com/2011/01/07/django-hurray-for-render-shortcut/">praised the <code>render()</code> shortcut</a>, which will eliminate the repetitive nonsense of <code>render_to_response(context_instance=RequestContext(request))</code>.  The ORM got an important patch allowing configuration of on-delete behavior for ForeignKey (and OneToOneField) fields, about which I had also <a title="Django gotcha: related objects deleted by default" href="http://fragmentsofcode.wordpress.com/2009/03/06/django-gotcha-related-objects-deleted-by-default/">posted</a>.  One interesting, small, but nice improvement came unannounced: <code>help_text</code> on a form field is now wrapped by a <code>&lt;span&gt;&lt;/span&gt;</code> when rendered as HTML by the <code>as_*()</code> methods.  I actually filed a <a href="http://code.djangoproject.com/ticket/15728">ticket</a> reporting this omission from the announcement.  For some reason, it seems that getting this change into the code and documentation has been a challenge.</p>
<p>I suspect there may be some moaning around the deprecation of function-based generic views in favor of class-based views.   Class-based views make sense, but it looks like there will be a little pain in the transition, partly because the keyword arguments for Django&#8217;s built-in generic view functions don&#8217;t map exactly to the generic view class keyword arguments.  It would have been nice to provide a little smoother transition there.  Also, the class-based view documentation is rather dense because you have to refer to the mixin classes that compose the actual generic view class you want to use.  I&#8217;m sure it will get easier with time, but it does feel like a jump in complexity that could make generic views more difficult for new users.    For example, where I did this before in a URLconf module:</p>
<pre>from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template

urlpatterns = patterns('',
    (r'^status/$', direct_to_template,
     {'template': 'sitetest/status.txt', 'mimetype': 'text/plain'}),
)</pre>
<p>I now have to do something like this:</p>
<pre>from django.conf.urls.defaults import *
from django.views.generic.base import TemplateView

class PlainTextTemplateView(TemplateView):
    """A plain text generic template view."""
    def render_to_response(self, context, **kwargs):
        return super(PlainTextTemplateView, self).render_to_response(
            context, content_type='text/plain', **kwargs
            )

urlpatterns = patterns('',
    (r'^status/$', PlainTextTemplateView.as_view(template_name='sitetest/status.txt')),
)</pre>
<p>While class-based views may have been a step in the right direction for the framework, I wonder how it will play out.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fragmentsofcode.wordpress.com/622/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fragmentsofcode.wordpress.com/622/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fragmentsofcode.wordpress.com/622/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fragmentsofcode.wordpress.com/622/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fragmentsofcode.wordpress.com/622/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fragmentsofcode.wordpress.com/622/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fragmentsofcode.wordpress.com/622/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fragmentsofcode.wordpress.com/622/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fragmentsofcode.wordpress.com/622/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fragmentsofcode.wordpress.com/622/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fragmentsofcode.wordpress.com/622/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fragmentsofcode.wordpress.com/622/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fragmentsofcode.wordpress.com/622/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fragmentsofcode.wordpress.com/622/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=622&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fragmentsofcode.wordpress.com/2011/04/01/django-1-3-first-impressions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dchandek</media:title>
		</media:content>
	</item>
		<item>
		<title>Apache LDAP authentication and Active Directory</title>
		<link>http://fragmentsofcode.wordpress.com/2011/02/23/apache-ldap-active-directory-authentication/</link>
		<comments>http://fragmentsofcode.wordpress.com/2011/02/23/apache-ldap-active-directory-authentication/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 22:51:15 +0000</pubDate>
		<dc:creator>David Chandek-Stark</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[LDAP]]></category>

		<guid isPermaLink="false">http://fragmentsofcode.wordpress.com/?p=608</guid>
		<description><![CDATA[I needed to authenticate users in Apache against Active Directory using mod_authnz_ldap.  Normally I would have set the URL and base DN like this: ldaps://example.com ou=CompanyPeople,dc=example,dc=com In this case, however, the users spanned two different top-level containers or &#8220;domains&#8221;: ou=CompanyPeople,dc=example,dc=com ou=OtherPeople,dc=example,dc=com So, I tried setting the base DN to the top level: dc=example,dc=com but authentication [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=608&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I needed to authenticate users in Apache against Active Directory using <a href="http://httpd.apache.org/docs/mod/mod_authnz_ldap.html">mod_authnz_ldap</a>.  Normally I would have set the URL and base DN like this:</p>
<p style="padding-left:30px;"><code>ldaps://example.com<br />
ou=CompanyPeople,dc=example,dc=com</code></p>
<p>In this case, however, the users spanned two different top-level containers or &#8220;domains&#8221;:</p>
<p style="padding-left:30px;"><code>ou=CompanyPeople,dc=example,dc=com<br />
</code><code>ou=OtherPeople,dc=example,dc=com</code></p>
<p>So, I tried setting the base DN to the top level:</p>
<p style="padding-left:30px;"><code>dc=example,dc=com</code></p>
<p>but authentication failed with this ugly error in the log:</p>
<p style="padding-left:30px;"><code>[ldap_search_ext_s() for user failed][Operations error]</code></p>
<p>It took some hunting, but I finally found that if you want to query the Active Directory &#8220;Global Catalog&#8221; (GC) via LDAP, you have to use port 3268 or 3269 (LDAPS) instead of the usual default port 389 or 636.  So, the working URL and base DN are:</p>
<p style="padding-left:30px;"><code>ldaps://example.com:3269<br />
dc=example,dc=com</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fragmentsofcode.wordpress.com/608/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fragmentsofcode.wordpress.com/608/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fragmentsofcode.wordpress.com/608/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fragmentsofcode.wordpress.com/608/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fragmentsofcode.wordpress.com/608/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fragmentsofcode.wordpress.com/608/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fragmentsofcode.wordpress.com/608/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fragmentsofcode.wordpress.com/608/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fragmentsofcode.wordpress.com/608/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fragmentsofcode.wordpress.com/608/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fragmentsofcode.wordpress.com/608/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fragmentsofcode.wordpress.com/608/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fragmentsofcode.wordpress.com/608/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fragmentsofcode.wordpress.com/608/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=608&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fragmentsofcode.wordpress.com/2011/02/23/apache-ldap-active-directory-authentication/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dchandek</media:title>
		</media:content>
	</item>
		<item>
		<title>My favorite Python packages</title>
		<link>http://fragmentsofcode.wordpress.com/2011/02/10/my-favorite-python-packages/</link>
		<comments>http://fragmentsofcode.wordpress.com/2011/02/10/my-favorite-python-packages/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 22:16:17 +0000</pubDate>
		<dc:creator>David Chandek-Stark</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://fragmentsofcode.wordpress.com/?p=517</guid>
		<description><![CDATA[Python generally lives up to its motto, &#8220;Batteries included.&#8221;  Here I want to give credit to folks who have provided some of my extra &#8220;batteries&#8221; &#8212; freely available Python tools that make my work easier and better. Django &#8211; The de facto standard for Python web application development.  I&#8217;ve learned a lot from studying its [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=517&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Python generally lives up to its motto, &#8220;Batteries included.&#8221;  Here I want to give credit to folks who have provided some of my extra &#8220;batteries&#8221; &#8212; freely available Python tools that make my work easier and better.</p>
<p><strong>Django </strong>&#8211; The de facto standard for Python web application development.  I&#8217;ve learned a lot from studying its code.  Includes a library of useful utilities (django.utils) that can used outside of web application contexts (e.g., check out <code>django.utils.datastructures.SortedDict</code>).</p>
<p><strong>sphinx </strong>&#8211; Also a de facto standard in the Python universe.  It&#8217;s made me appreciate reStructured Text and improve my code documentation practices.  Ironically I find its own documentation rather hard to use.</p>
<p><strong>virtualenv </strong>&#8211; How did we manage without it?</p>
<p><strong>pip </strong>&#8211; Better package management than <code>easy_install</code>.</p>
<p><strong>ipython </strong>&#8211; Worth it for the command history alone.</p>
<p><strong>decorator </strong>&#8211; Almost essential for writing decorators, especially if you&#8217;re on Python &lt; 2.5.</p>
<p><strong>Fabric </strong>&#8211; A great addition to the developer&#8217;s or sysadmin&#8217;s toolkit.</p>
<p><strong>lxml </strong>&#8211; For XML processing, I almost never use Python&#8217;s builtin XML libraries.</p>
<p><strong>pycurl </strong>&#8211; Brings the power of libcurl into Python, filling gaps left by urllib/urllib2 and httplib (e.g., <a title="pycurl CurlMulti example" href="http://fragmentsofcode.wordpress.com/2011/01/22/pycurl-curlmulti-example/">multiple asynchronous requests</a>, <a title="Python and multipart/form-data: Where’s the love?" href="http://fragmentsofcode.wordpress.com/2009/12/12/python-and-multipartform-data-wheres-the-love/">multipart form data</a>).</p>
<p><strong>xlrd, xlwt</strong> &#8212; Good API for MS Excel processing.  Unfortunately, no support (yet) for Excel 2007 XML format.</p>
<p><strong>simplejson </strong>&#8211; The standard JSON library for Python &lt; 2.6.</p>
<p><strong>py.test</strong> &#8212; Anything that makes writing and running unit tests easier is very good.</p>
<p><strong>unittest2</strong> &#8212; Makes available to Python 2.4-2.6 the significant enhancements made to the standard unittest module in Python 2.7.</p>
<p>I also want to thank <strong>Christof Gohlke</strong> for his <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/">&#8220;Unofficial Windows Binaries&#8221; site</a>, since up-to-date versions of lxml and pycurl would be difficult to use on Windows without his builds.</p>
<p>And finally, there are essential libraries that I depend on without normally using directly: <strong>MySQL-Python</strong>, <strong>pysqlite</strong> (stuck on CentOS 5/Python 2.4), <strong>python-ldap</strong>, <strong>docutils</strong>, <strong>setuptools</strong>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fragmentsofcode.wordpress.com/517/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fragmentsofcode.wordpress.com/517/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fragmentsofcode.wordpress.com/517/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fragmentsofcode.wordpress.com/517/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fragmentsofcode.wordpress.com/517/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fragmentsofcode.wordpress.com/517/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fragmentsofcode.wordpress.com/517/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fragmentsofcode.wordpress.com/517/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fragmentsofcode.wordpress.com/517/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fragmentsofcode.wordpress.com/517/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fragmentsofcode.wordpress.com/517/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fragmentsofcode.wordpress.com/517/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fragmentsofcode.wordpress.com/517/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fragmentsofcode.wordpress.com/517/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fragmentsofcode.wordpress.com&amp;blog=5756830&amp;post=517&amp;subd=fragmentsofcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fragmentsofcode.wordpress.com/2011/02/10/my-favorite-python-packages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dchandek</media:title>
		</media:content>
	</item>
	</channel>
</rss>
