<?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>Kevin Deldycke &#187; patch</title> <atom:link href="http://kevin.deldycke.com/tag/patch/feed/" rel="self" type="application/rss+xml" /><link>http://kevin.deldycke.com</link> <description>Free software engineer &#38; wannabe videomaker</description> <lastBuildDate>Fri, 03 Feb 2012 19:08:27 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Got &#8220;unsized object&#8221; errors with Debian&#8217;s Mailman ? Try this patch !</title><link>http://kevin.deldycke.com/2008/12/got-unsized-object-errors-with-debian-mailman-try-this-patch/</link> <comments>http://kevin.deldycke.com/2008/12/got-unsized-object-errors-with-debian-mailman-try-this-patch/#comments</comments> <pubDate>Mon, 29 Dec 2008 18:02:22 +0000</pubDate> <dc:creator>Kev</dc:creator> <category><![CDATA[English]]></category> <category><![CDATA[bug]]></category> <category><![CDATA[Debian]]></category> <category><![CDATA[etch]]></category> <category><![CDATA[hack]]></category> <category><![CDATA[mail]]></category> <category><![CDATA[mailman]]></category> <category><![CDATA[patch]]></category> <category><![CDATA[Python]]></category><guid isPermaLink="false">http://kevin.deldycke.com/?p=459</guid> <description><![CDATA[Last week I came across a showstopper bug on Mailman 2.1.9-7, the current version of Mailman package distributed with Debian Etch. Here is the python traceback (from /var/log/mailman/error logfile) I get each time I&#8217;ve sent a mail to my brand &#8230; <a href="http://kevin.deldycke.com/2008/12/got-unsized-object-errors-with-debian-mailman-try-this-patch/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>Last week I came across a showstopper bug on Mailman 2.1.9-7, the <a href="http://packages.debian.org/etch/mailman">current version of Mailman package distributed with Debian Etch</a>.</p><p>Here is the python traceback (from <code>/var/log/mailman/error</code> logfile) I get each time I&#8217;ve sent a mail to my brand new mailing-list:</p><pre class="brush: bash; title: ; notranslate">
Dec 20 01:20:04 2008 (14275) Uncaught runner exception: len() of unsized object
Dec 20 01:20:04 2008 (14275) Traceback (most recent call last):
  File &quot;/usr/lib/mailman/Mailman/Queue/Runner.py&quot;, line 112, in _oneloop
    self._onefile(msg, msgdata)
  File &quot;/usr/lib/mailman/Mailman/Queue/Runner.py&quot;, line 170, in _onefile
    keepqueued = self._dispose(mlist, msg, msgdata)
  File &quot;/usr/lib/mailman/Mailman/Queue/IncomingRunner.py&quot;, line 130, in _dispose
    more = self._dopipeline(mlist, msg, msgdata, pipeline)
  File &quot;/usr/lib/mailman/Mailman/Queue/IncomingRunner.py&quot;, line 153, in _dopipeline
    sys.modules[modname].process(mlist, msg, msgdata)
  File &quot;/usr/lib/mailman/Mailman/Handlers/ToDigest.py&quot;, line 81, in process
    mbox.AppendMessage(msg)
  File &quot;/usr/lib/mailman/Mailman/Mailbox.py&quot;, line 69, in AppendMessage
    g.flatten(msg, unixfrom=True)
  File &quot;/usr/lib/mailman/pythonlib/email/Generator.py&quot;, line 101, in flatten
    self._write(msg)
  File &quot;/usr/lib/mailman/pythonlib/email/Generator.py&quot;, line 136, in _write
    self._write_headers(msg)
  File &quot;/usr/lib/mailman/pythonlib/email/Generator.py&quot;, line 182, in _write_headers
    header_name=h, continuation_ws='\t').encode()
  File &quot;/usr/lib/mailman/pythonlib/email/Header.py&quot;, line 412, in encode
    newchunks += self._split(s, charset, targetlen, splitchars)
  File &quot;/usr/lib/mailman/pythonlib/email/Header.py&quot;, line 297, in _split
    elen = charset.encoded_header_len(encoded)
  File &quot;/usr/lib/mailman/pythonlib/email/Charset.py&quot;, line 354, in encoded_header_len
    raise repr(s)
TypeError: len() of unsized object

Dec 20 01:20:04 2008 (14275) SHUNTING: 1229732404.1069181+dcd89a08bf7911dac2db804b76cd42d20564c71c
</pre><p>Here is the corresponding (anonymized) mail sent to the mailing list from a Gmail account:</p><pre class="brush: bash; title: ; notranslate">
Received: by 10.180.244.13 with HTTP; Fri, 19 Dec 2008 16:32:22 -0800 (PST)
Message-ID: &lt;1f7b086f0812192632x7427c0f7u2048609ddd50673@mail.gmail.com&gt;
Date: Sat, 20 Dec 2008 01:32:22 +0100
From: &quot;Kevin&quot; &lt;kevin@my-domain.com&gt;
To: my-ml@lists.my-domain.com
Subject: sqdfqsdfqsfd
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: inline
Delivered-To: kevin@my-domain.com

LS0KS2V2LgogIOKAoiBiYW5kOiBodHRwOi8vY29vbGNhdmVtZW4uY29tCiAg4oCiIGJsb2c6IGh0
dHA6Ly9rZXZpbi5kZWxkeWNrZS5jb20K
</pre><p>And now my hackish tale. Based on a quick look at Mailman&#8217;s source code, I made an educated guess that this error is just a side effect of the wrong assumption that the <code>s</code> variable in the <code>Charset.encoded_header_len()</code> method is always a string. So I came up with the following evil patch to handle (gracefully, I hope) the case of <code>s</code> being <code>None</code>.</p><p>Here is the <a href='http://kevin.deldycke.com/wp-content/uploads/2008/12/mailman-219-7-charset-handling.patch'>resulting patch</a> of my python-fu:</p><pre class="brush: diff; title: ; notranslate">
--- /usr/lib/mailman/pythonlib/email/Charset.py.orig   2008-12-28 19:46:23.000000000 +0100
+++ /usr/lib/mailman/pythonlib/email/Charset.py        2008-12-20 01:42:37.000000000 +0100
@@ -351,6 +351,7 @@
             lenqp = email.quopriMIME.header_quopri_len(s)
             return min(lenb64, lenqp) + len(cset) + MISC_LEN
         else:
+            return s is not None and len(str(s)) or 0
             return len(s)

     def header_encode(self, s, convert=False):
</pre><p>And it do the trick ! Of course I can&#8217;t guarantee that this patch is the way to definitely fix the bug. And it may corrupt data. So <strong>use it only if you&#8217;re as crazy as me</strong> ! <img src='http://kevin.deldycke.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /></p><p>But I know, I know&#8230; As a responsible and serious hacker (sigh), I should report this bug to the Debian or Mailman project. But I&#8217;m still not familiar with Dedian&#8217;s way of reporting bugs (and to be honest, I feel lazy these days :p ). Maybe, one day&#8230;</p> ]]></content:encoded> <wfw:commentRss>http://kevin.deldycke.com/2008/12/got-unsized-object-errors-with-debian-mailman-try-this-patch/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>How-to add Google Analytics tracking to Zenphoto</title><link>http://kevin.deldycke.com/2008/08/how-to-add-google-analytics-tracking-to-zenphoto/</link> <comments>http://kevin.deldycke.com/2008/08/how-to-add-google-analytics-tracking-to-zenphoto/#comments</comments> <pubDate>Sat, 16 Aug 2008 20:49:55 +0000</pubDate> <dc:creator>Kev</dc:creator> <category><![CDATA[English]]></category> <category><![CDATA[analytics]]></category> <category><![CDATA[Google]]></category> <category><![CDATA[hack]]></category> <category><![CDATA[patch]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Snippet]]></category> <category><![CDATA[Web]]></category> <category><![CDATA[Zenphoto]]></category><guid isPermaLink="false">http://kevin.deldycke.com/?p=286</guid> <description><![CDATA[This is the patch I apply on each Zenphoto I install and upgrade. This little hack add Google Analytics tracking for all users except administrators. Why ? As you can see in ticket #441 in Zenphoto bugtracker, there is no &#8230; <a href="http://kevin.deldycke.com/2008/08/how-to-add-google-analytics-tracking-to-zenphoto/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p><img src="http://kevin.deldycke.com/wp-content/uploads/2008/08/zenphoto-12-150x23.png" alt="" title="zenphoto-12" width="150" height="23" class="alignleft size-thumbnail wp-image-299" /></p><p>This is the patch I apply on each <a href="http://www.zenphoto.org">Zenphoto</a> I install and upgrade. This little hack add <a href="http://www.google.com/analytics/">Google Analytics</a> tracking for all users except administrators.</p><p>Why ? As you can see in <a href="http://www.zenphoto.org/trac/ticket/441">ticket #441 in Zenphoto bugtracker</a>, there is no intention of adding support of GA in Zenphoto, even as an optional plugin. Hence my tiny hack. And for the non-admin stuff, I like having unbiased statistics: on low-audience websites, administrators can generate more traffic than legitimate users (if not all&#8230;).</p><p>Here is the <a href='http://kevin.deldycke.com/wp-content/uploads/2008/08/google-analytics-tracking-for-non-admin-users.patch'>downloadable patch file</a>, and its content:</p><pre class="brush: diff; title: ; notranslate">
diff -ru ./zenphoto-orig/zp-core/template-functions.php ./zenphoto/zp-core/template-functions.php
--- ./zenphoto-orig/zp-core/template-functions.php  2008-08-15 07:43:05.000000000 +0200
+++ ./zenphoto/zp-core/template-functions.php 2008-08-16 17:08:03.000000000 +0200
@@ -147,7 +147,16 @@

    echo &quot;&lt;li&gt;&lt;a href=\&quot;&quot;.$zf.&quot;/admin.php?logout$redirect\&quot;&gt;&quot;.gettext(&quot;Logout&quot;).&quot;&lt;/a&gt;&lt;/li&gt;\n&quot;;
    echo &quot;&lt;/ul&gt;&lt;/div&gt;\n&quot;;
- }
+ } else {
+    echo &quot;&lt;script type=\&quot;text/javascript\&quot;&gt;
+var gaJsHost = ((\&quot;https:\&quot; == document.location.protocol) ? \&quot;https://ssl.\&quot; : \&quot;http://www.\&quot;);
+document.write(unescape(\&quot;%3Cscript src='\&quot; + gaJsHost + \&quot;google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\&quot;));
+&lt;/script&gt;
+&lt;script type=\&quot;text/javascript\&quot;&gt;
+var pageTracker = _gat._getTracker(\&quot;UA-XXXXXX-Y\&quot;);
+pageTracker._trackPageview();
+&lt;/script&gt;&quot;;
+  }
 }

 /**
</pre><p>This patch was generated from a <a href="http://www.zenphoto.org/2008/08/zenphoto-12-release-announcement/">Zenphoto v1.2</a> and will likely not work with any other version.</p><p>Do not forget to update the dummy Google Analytics account ID above (<code>UA-XXXXXX-Y</code>) by yours.</p><p>And finally, to apply the patch, invoke the classic <code>patch</code> command:</p><pre class="brush: bash; title: ; notranslate">
patch -p0 &lt; ./google-analytics-tracking-for-non-admin-users.patch
</pre>]]></content:encoded> <wfw:commentRss>http://kevin.deldycke.com/2008/08/how-to-add-google-analytics-tracking-to-zenphoto/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>How-to fix ruby&#8217;s FeedTools latin-1 parsing</title><link>http://kevin.deldycke.com/2008/07/how-to-fix-rubys-feedtools-latin-1-parsing/</link> <comments>http://kevin.deldycke.com/2008/07/how-to-fix-rubys-feedtools-latin-1-parsing/#comments</comments> <pubDate>Thu, 31 Jul 2008 18:48:22 +0000</pubDate> <dc:creator>Kev</dc:creator> <category><![CDATA[English]]></category> <category><![CDATA[feed]]></category> <category><![CDATA[FeedTools]]></category> <category><![CDATA[monkey patch]]></category> <category><![CDATA[parsing]]></category> <category><![CDATA[patch]]></category> <category><![CDATA[RSS]]></category> <category><![CDATA[ruby]]></category> <category><![CDATA[Ruby on Rails]]></category> <category><![CDATA[Snippet]]></category> <category><![CDATA[Web]]></category><guid isPermaLink="false">http://kevin.deldycke.com/?p=236</guid> <description><![CDATA[While playing with FeedTools, a ruby library to parse RSS (or other) feeds, I&#8217;ve spotted a strange behavior, that at first looks like typical unicode parsing issue. So I&#8217;ve started to check that the original feed was encoded in the &#8230; <a href="http://kevin.deldycke.com/2008/07/how-to-fix-rubys-feedtools-latin-1-parsing/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p><img src="http://kevin.deldycke.com/wp-content/uploads/2008/07/feedtools-logo-150x150.png" alt="" title="feedtools-logo" width="150" height="150" class="alignleft size-thumbnail wp-image-237" /></p><p>While playing with <a href="http://sporkmonger.com/projects/feedtools/">FeedTools</a>, a ruby library to parse RSS (or other) feeds, I&#8217;ve spotted a strange behavior, that at first looks like typical unicode parsing issue. So I&#8217;ve started to check that the original feed was encoded in the right format, and that its charset was clearly set to the right value. But I found nothing wrong&#8230; So I dug in the <a href="http://feedtools.rubyforge.org/svn/trunk/">FeedTools source code</a>, and what I found is particularly disappointing&#8230;</p><p>FeedTools do a really nice job to detect the charset and handle feed&#8217;s data. So when it encounter <a href="http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references">HTML entities</a>, it decode them to plain text. That&#8217;s good as at the end you get ready-to-use strings. Unfortunately, the method it use, <a href="http://www.noobkit.com/show/ruby/ruby/standard-library/cgi/unescapehtml.html">CGI::unescapeHTML</a>, stick too much to the <a href="http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent">W3C specification</a>, which state that some of the HTML entities (if not all) are the expression of latin-1 characters. Hence the presence of latin-1 characters in pure UTF-8 RSS feeds&#8230;</p><p>To fix that, I&#8217;ve recoded the <a href="http://rubyfurnace.com/docs/feedtools-0.2.26/classes/FeedTools/HtmlHelper.html#M007308">FeedTools::HtmlHelper.unescape_entities()</a> method to convert each HTML entity it encounter to pure unicode. Here is the monkey patch I call by default from the <code>environment.rb</code> file of all my <a href="http://www.rubyonrails.org">Ruby on Rails</a> projects:</p><pre class="brush: ruby; title: ; notranslate">
require 'feed_tools'

# Monkey patch feed tool.
# Use case mixed UTF-8 chars and html entities: &lt;description&gt;Téléchargements et Multim&amp;#233;dia&lt;/description&gt;
module FeedTools::HtmlHelper
  class &lt;&lt; self

    # Force UTF-8 conversion of HTML entities with number lower than 256.
    # Based on CGI::unescapeHTML method.
    def convert_html_entities_to_unicode(string)
      string.gsub(/&amp;(.*?);/n) do
        $KCODE = &quot;UTF8&quot;
        match = $1.dup
        case match
        when /\A#0*(\d+)\z/n       then
          if Integer($1) &lt; 256
            [Integer($1)].pack(&quot;U&quot;)
          else
            &quot;&amp;##{$1};&quot;
          end
        when /\A#x([0-9a-f]+)\z/ni then
          if $1.hex &lt; 256
            [$1.hex].pack(&quot;U&quot;)
          else
            &quot;&amp;#x#{$1};&quot;
          end
        else
          &quot;&amp;#{match};&quot;
        end
      end
    end

    # Patch unescape_entities() method
    alias_method :unescape_entities_orig, :unescape_entities
    def unescape_entities(html)
      return unescape_entities_orig(convert_html_entities_to_unicode(html))
    end

  end
end
</pre><p>Ok, so this fix the issue.</p><p>But I&#8217;m not comfortable about this problem not solved cleanly. I still don&#8217;t have a clue about which component should solve the problem definitively. But I have some ideas&#8230; Here are my propositions:</p><ol><li>Submit my monkey patch to FeedTools project for integration, or</li><li>Merge my monkey patch upstream in legacy ruby CGI library, or</li><li>Do not allow usage of HTML entities in feeds.</li></ol> ]]></content:encoded> <wfw:commentRss>http://kevin.deldycke.com/2008/07/how-to-fix-rubys-feedtools-latin-1-parsing/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>My First WordPress Patch !</title><link>http://kevin.deldycke.com/2007/02/my-first-wordpress-patch/</link> <comments>http://kevin.deldycke.com/2007/02/my-first-wordpress-patch/#comments</comments> <pubDate>Wed, 14 Feb 2007 21:27:14 +0000</pubDate> <dc:creator>Kev</dc:creator> <category><![CDATA[Blog]]></category> <category><![CDATA[kubrick]]></category> <category><![CDATA[patch]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Template]]></category> <category><![CDATA[Theme]]></category> <category><![CDATA[Web]]></category> <category><![CDATA[WordPress]]></category><guid isPermaLink="false">http://kevin.deldycke.com/2007/02/my-first-wordpress-patch/</guid> <description><![CDATA[Last week I&#8217;ve submitted a patch to the WordPress open souce project. This tiny patch fix a little bug on Kubrick default theme which didn&#8217;t display the list of comments associated with a page. I&#8217;ve spotted that bug some months &#8230; <a href="http://kevin.deldycke.com/2007/02/my-first-wordpress-patch/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>Last week I&#8217;ve submitted a patch to the WordPress open souce project. This <a href="http://trac.wordpress.org/attachment/ticket/3753/wp-default-theme-show-comments-on-pages.diff">tiny patch</a> fix a little bug on Kubrick default theme which didn&#8217;t display the list of comments associated with a page. I&#8217;ve <a href="http://kevin.deldycke.com/2006/11/wordpress-to-e107-v05-static-pages-import-added/">spotted that bug some months ago</a> when working on my e107 to WordPress import script. As you can see in the <a href="http://trac.wordpress.org/ticket/3753">trac ticket</a>, my patch was committed in the trunk of the project, and you can expect to see it in the next 2.2 version release.</p> ]]></content:encoded> <wfw:commentRss>http://kevin.deldycke.com/2007/02/my-first-wordpress-patch/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 2/20 queries in 0.010 seconds using apc
Object Caching 702/742 objects using apc

Served from: kevin.deldycke.com @ 2012-02-08 10:09:31 -->
