<?xml version="1.0" encoding="iso-8859-1"?>

<!-- name="generator" content="pyblosxom/1.4.1 7/27/2007" -->
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">

<rss version="0.91">
<channel>
<title>Menno's Musings   </title>
<link>http://freshfoo.com/blog</link>
<description>software | life | whatever</description>
<language>en</language>
<item>
  <title>TypeError: object.__init__() takes no parameters</title>
  <link>http://freshfoo.com/blog/object__init__takes_no_parameters</link>
  <description><![CDATA[
<p>At my employer we are in the process of migrating from Python 2.4 to
2.6. When running some existing code under Python 2.6 we started
getting DeprecationWarnings about &quot;object.__new__() takes no
parameters&quot; and &quot;object.__init__() takes no parameters&quot;.</p>
<p>A simple example that triggers the warning:</p>
<div class="highlight" ><pre><span class="k">class</span> <span class="nc">MyClass</span>(<span class="nb">object</span>):

    <span class="k">def</span> <span class="nf">__new__</span>(<span class="n">cls</span>, <span class="n">a</span>, <span class="n">b</span>):
        <span class="k">print</span> <span class="s">&#39;MyClass.__new__&#39;</span>, <span class="n">a</span>, <span class="n">b</span>
        <span class="k">return</span> <span class="nb">super</span>(<span class="n">MyClass</span>, <span class="n">cls</span>).<span class="n">__new__</span>(<span class="n">cls</span>, <span class="n">a</span>, <span class="n">b</span>)

    <span class="k">def</span> <span class="nf">__init__</span>(<span class="bp">self</span>, <span class="n">a</span>, <span class="n">b</span>):
        <span class="k">print</span> <span class="s">&#39;MyClass.__init__&#39;</span>, <span class="n">a</span>, <span class="n">b</span>
        <span class="nb">super</span>(<span class="n">MyClass</span>, <span class="bp">self</span>).<span class="n">__init__</span>(<span class="n">a</span>, <span class="n">b</span>)

<span class="n">obj</span> <span class="o">=</span> <span class="n">MyClass</span>(<span class="mi">6</span>, <span class="mi">7</span>)
</pre></div>
<p>This gives:</p>
<pre class="literal-block">
$ python2.4 simple-warning.py
MyClass.__new__ 6 7
MyClass.__init__ 6 7

$ python2.6 simple-warning.py
MyClass.__new__ 6 7
simple-warning.py:5: DeprecationWarning: object.__new__() takes no parameters
  return super(MyClass, cls).__new__(cls, a, b)
MyClass.__init__ 6 7
simple-warning.py:9: DeprecationWarning: object.__init__() takes no parameters
  super(MyClass, self).__init__(a, b)
</pre>
<p>It turns out that a <a class="reference external" href="http://svn.python.org/view?view=rev&amp;revision=54539">change to Python</a> for 2.6 (and 3) means that
object.__new__ and object.__init__ no longer take arguments - a
TypeError is raised when arguments are passed. To avoid breaking too
much pre-existing code, there is a special case that will cause a
DeprecationWarning instead of TypeError if both __init__ and __new__
are overridden. This is the case we were running into with our code at
work.</p>
<p>The reason for this change seems to make enough sense: object doesn't
do anything with arguments to __init__ and __new__ so it shouldn't
accept them. Raising an error when arguments are passed highlights
code where the code might be doing the wrong thing.</p>
<p>Unfortunately this change also breaks Python's multiple inheritance in
a fairly serious way when cooperative <a class="reference external" href="http://docs.python.org/library/functions.html#super">super</a> calls are used. Looking
at the <a class="reference external" href="http://bugs.python.org/issue1683368">ticket</a> for this change, this issue was thought about but
perhaps the implications were not fully understood. Given that using
super with multiple inheritance is common and &quot;correct&quot; practice, it
would seem that this change to Python is a step backwards.</p>
<a href="http://freshfoo.com/blog/object__init__takes_no_parameters">Read more...</a>
]]></description>
</item>

<item>
  <title>rst_break plugin for PyBlosxom</title>
  <link>http://freshfoo.com/blog/rst_break-plugin</link>
  <description><![CDATA[
<p>I just scratched an itch by writing a small plugin for PyBlosxom that
allows the <a class="reference external" href="http://pyblosxom.sourceforge.net/registry/text/rst.html">rst</a> (<a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructured Text</a>) and <a class="reference external" href="http://pyblosxom.sourceforge.net/registry/display/readmore.html">readmore</a> plugins to work
together <a class="footnote-reference" href="#id2" id="id1">[1]</a>. It defines a reST &quot;break&quot; directive which gets transformed
into the breakpoint string the readmore plugin looks out for. This
allows for &quot;Read more...&quot; breaks to be inserted in for reST based
articles.</p>
<p>For further information see the <a class="reference external" href="/code/">Code</a> page here and at the top of the
<a class="reference external" href="/hg/pyblosxom-plugins/trunk/raw-file/9afdcd2bf738/rst_break/rst_break.py">plugin</a> itself.</p>
<table class="docutils footnote" frame="void" id="id2" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>Yes, the audience for this plugin is probably tiny!</td></tr>
</tbody>
</table>

]]></description>
</item>

<item>
  <title>IMAPClient 0.5.2</title>
  <link>http://freshfoo.com/blog/IMAPClient-0.5.2</link>
  <description><![CDATA[
<p>IMAPClient 0.5.2 has just been released. This release fixes 2 bugs
(<a class="reference external" href="http://imapclient.freshfoo.com/ticket/28">#28</a> and <a class="reference external" href="http://imapclient.freshfoo.com/ticket/33">#33</a>).  Much thanks to Fergal Daly and Mark Eichin for
reporting these bugs.</p>
<p>Install from the <a class="reference external" href="/projects/IMAPClient/IMAPClient-0.5.2.tar.gz">tarball</a> or <a class="reference external" href="/projects/IMAPClient/IMAPClient-0.5.2.zip">zip</a> or upgrade using easy_install or pip.</p>

]]></description>
</item>

<item>
  <title>A little thing about cron</title>
  <link>http://freshfoo.com/blog/crontab-updates</link>
  <description><![CDATA[
<p>Here's something I just learned the hard way.</p>
<p>If you edit a crontab with &quot;crontab -e&quot;, cron won't reload the updated
crontab immediately. Changes will be read at 1 second past the next
minute boundary. For example, if you change the crontab at 10:54:32,
cron will reload it at 10:55:01. This means if you're trying to test
how something runs under cron and you're impatient so you set that
thing to run at the next minute, you won't see it run!</p>
<p>I spent a good half hour chasing my tail on this one. Set the
test entry to run 2 minutes ahead instead.</p>

]]></description>
</item>

<item>
  <title>IMAPClient Trac instance now allows for user registrations</title>
  <link>http://freshfoo.com/blog/IMAPClient-Trac_AccountManagerPlugin</link>
  <description><![CDATA[
<p>I've had several requests over the last few weeks to open up the
IMAPClient Trac instance so that anyone can submit tickets. Initially
I changed access levels so that anoymous users could create
tickets. This turned out to be fairly inflexible: it doesn't allow
people to add attachments or modify tickets later. This approach also
resulted in one strange ticket being created where all fields were
filled with random characters - a bot looking for buffer overruns?</p>
<p>Since then, I've disabled anonymous ticket creation and have set up
the fantastic <a class="reference external" href="http://trac-hacks.org/wiki/AccountManagerPlugin">AccountManagerPlugin</a> which allows people to register
accounts for themselves. Once someone has created an account and
logged in they can create and modify tickets. I have a feeling I'm
going to have to turn on the optional CAPTCHA support, but I'm willing
to see how it goes for a while first.</p>

]]></description>
</item>

<item>
  <title>IMAPClient 0.5.1</title>
  <link>http://freshfoo.com/blog/IMAPClient-0.5.1</link>
  <description><![CDATA[
<p>I've just made a quick point release of IMAPClient. <a class="reference external" href="http://python.net/crew/skippy/">Mark Hammond</a> is
interested in using it for a <a class="reference external" href="https://mozillalabs.com/raindrop">project</a> he's working on but the licenses
(GPL and MPL) were incompatible. I was thinking about <a class="reference external" href="http://imapclient.freshfoo.com/ticket/8">relaxing the
license</a> of IMAPClient anyway so this presented a good opportunity to
make the switch.</p>
<p>Work on the 0.6 release is coming along. This version will fix a
number issues with parsing of FETCH responses - the FETCH parsing code
is being completely rewritten. This is the first time that IMAPClient
will bypass most of <a class="reference external" href="http://docs.python.org/library/imaplib.html">imaplib</a> for some functionality. It's looking like
that at some point IMAPClient may not use imaplib at all.</p>
<p>IMAPClient can be installed from PyPI using <tt class="docutils literal"><span class="pre">pip</span> <span class="pre">install</span> <span class="pre">IMAPClient</span></tt>
or <tt class="docutils literal"><span class="pre">easy_install</span> <span class="pre">IMAPClient</span></tt>. It can also be downloaded from the
<a class="reference external" href="http://imapclient.freshfoo.com">IMAPClient project page</a>. As
always, feedback and patches are most welcome.</p>

]]></description>
</item>

<item>
  <title>PyBlosxom to Disqus import script</title>
  <link>http://freshfoo.com/blog/disqus-import-script</link>
  <description><![CDATA[
<p>I've had a few requests for the little hack I created to import comments from
PyBlosxom into Disqus. A cleaned up version of disqus-import.py is now on the
<a class="reference external" href="/code/">Code</a> page. There's some docs at the top of the file.</p>

]]></description>
</item>

<item>
  <title>Setting PYTHON_EGG_CACHE when deploying Python apps using FastCGI</title>
  <link>http://freshfoo.com/blog/fastcgi-python-egg-cache</link>
  <description><![CDATA[
<p>I recently sorted out an issue with the <a class="reference external" href="http://imapclient.freshfoo.com/">IMAPClient</a> Trac instance
that's been bugging me for a while.</p>
<p>The problem was that whenever the web server logs were rotated
logrotate would restart <a class="reference external" href="http://www.lighttpd.net/">Lighttpd</a>. The web server restart would in
turn restart the Trac (FastCGI) processes. Unfortunately, the Trac
processes would fail to start with the following error.</p>
<pre class="literal-block">
pkg_resources.ExtractionError: Can't extract file(s) to egg cache

The following error occurred while trying to extract file(s) to the Python egg
cache:

  [Errno 13] Permission denied: '/root/.python-eggs'

The Python egg cache directory is currently set to:

  /root/.python-eggs
</pre>
<p>Bang, no <a class="reference external" href="http://imapclient.freshfoo.com/">IMAPClient</a> web site (the rest of the site was ok). To band-aid
the problem when it happened (and I noticed!) I issue a <tt class="docutils literal"><span class="pre">sudo</span>
<span class="pre">/etc/init.d/lighttpd</span> <span class="pre">restart</span></tt> and everything would be fine again.</p>
<p>After some investigation I found that running <tt class="docutils literal"><span class="pre">/etc/init.d/lighttpd</span>
<span class="pre">restart</span></tt> as root always triggered the problem where-as restarting
using sudo always worked. My guess is that restarting when logged in
as root was leaving $HOME at /root even after Lighttpd had dropped to
its unprivileged user account. The unprivileged user isn't allowed to
write to /root so Trac blows up. setuptools seems to use $HOME
instead of looking up the actual home directory of the current user.</p>
<p>The fix for me was to set the PYTHON_EGG_CACHE environment variable
for the FastCGI processes to somewhere they are allowed to write
to. This is done with the bin-environment option if you're using
Lighttpd like me.</p>
<p>I imagine similar problems can happen with any Python app deployed
using FastCGI.</p>

]]></description>
</item>

<item>
  <title>Why I chose Disqus Comments</title>
  <link>http://freshfoo.com/blog/disqus</link>
  <description><![CDATA[
<p>I recently moved my blog comments away the <a class="reference external" href="http://pyblosxom.sourceforge.net/">PyBlosxom</a> <a class="reference external" href="http://pyblosxom.sourceforge.net/registry/input/comments/comments.html">comments</a> plugin
to a hosted system. The main driver was the ability for people to
subscribe to comments for an article using email or RSS. It's a pain
for people to have to check back to the site to see if someone has
replied to their comments. I was also keen on
user-experience-enhancing features such as integration with external
systems like OpenID, Twitter and Yahoo.</p>
<p>My criteria were:</p>
<ul class="simple">
<li>email subscription, RSS a bonus</li>
<li>support for pre-formatted text sections in comments (essential for
code samples)</li>
<li>an import mechanism for existing comments</li>
<li>threading of comments to allow commenters to respond to each other
sensibly</li>
<li>clean look with some ability to customise</li>
<li>support for a variety of authentication/profile systems</li>
</ul>
<p>There are a number of hosted comment systems out there. The most
popular options seem to be <a class="reference external" href="http://disqus.com/">Disqus</a>, <a class="reference external" href="http://js-kit.com/">JS-Kit Echo</a> and
<a class="reference external" href="http://www.intensedebate.com/">IntenseDebate</a>.</p>
<p>IntenseDebate was eliminated first because it doesn't seem to provide
an import mechanism for custom websites. Import only seems to be
supported for well known blog platforms such as Wordpress. There's no
comment API either. The approach seems to be to leave your old comment
system in place and just have new comments go into IntenseDebate. Not
good enough, I wanted to completely replace the existing comments
system.</p>
<p>After some deliberation I decided on JS-Kit Echo for one tiny reason:
it supports the &lt;pre&gt; tag. The closest Disqus supported was the
&lt;code&gt; tag which doesn't preserve white-space (useless for Python code
samples).</p>
<p>So I paid my US$12 (it's the only service that doesn't have a free
option) and started looking at how to import my existing comments
using their API ... and quickly found that it sucks. Comments can be
submitted but you can't specify a timestamp so they are dated with the
import date. Far from ideal. Then there's the API for retrieving
comments: it returns the data as JavaScript code (no not JSON)! It's
pretty clear that the API is what they use with the JavaScript for
Echo itself and geared for that use only. They've just thrown it out
there and documented it, warts and all.</p>
<p>Back to the drawing board.</p>
<p>The only showstopper for Disqus was the lack of &lt;pre&gt;. Everything else
about it was great: it met all my requirements and the API was clean
and comprehensive. If only there was a way to have properly formatted
source code in the comments.</p>
<p>Light bulb moment: use a CSS hack to make &lt;code&gt; in comments behave
like &lt;pre&gt;. The trick is to turn code into a block element and change
how white-space is handled. The CSS snippet looks like:</p>
<div class="highlight" ><pre>.dsq-comment-message code {
  display:block;
  white-space:pre;
}
</pre></div>
<p>Works great.</p>
<p>With the only blocker gone, I wrote a Python script with the help of
Ian Lewis' excellent <a class="reference external" href="http://code.google.com/p/disqus-python-client/">disqus-python-client</a> package to pull in the
existing comments from the old system. Within an hour or so it was
ready to go.</p>
<p>Hopefully this article saves someone else some time if they decide to
use one of these systems. Getting things running chewed up a lot more
time then I had expected.</p>

]]></description>
</item>

<item>
  <title>IMAPClient has a new home</title>
  <link>http://freshfoo.com/blog/new-imapclient-site</link>
  <description><![CDATA[
<p>I've just (finally) finished setting up a proper website for
IMAPClient. The new home for the project is
<a class="reference external" href="http://imapclient.freshfoo.com/">http://imapclient.freshfoo.com/</a>.</p>
<p>It's a Trac instance with Mercurial support that monitors the main
trunk repository. All items from the TODO file in the source have been
converted to tickets in the bug tracker. I've even created a hokey
little logo.</p>
<p>Let me know me know if anything looks broken.</p>
<p>Time to work on some long-standing bugs...</p>

]]></description>
</item>

</channel>
</rss>
