…or I might just stop loving you.

So following on from Tollef’s recent pyblosxom-related posting I thought that the discovery I made about how to fix unicode comments deserved to be blogged for the world to see.

Scott James Remnant pointed out to me on IRC that there exists a problem with people who post comments in utf-8. The issue it seems is that the comments plugin assumes uploaded comments are in iso-8859-1 which sucks a little. Line 200 of the standard comments.py is about the right place for a fix; and here’s mine. Remember I’m not a good python coder…:

Replace: cfile.write(‘<?xml version=“1.0” encoding=“iso-8859-1”?>n’)

With:

<code>        try:
            comment['description'].decode('utf-8')
            cfile.write('&lt;?xml version="1.0" encoding="utf-8"?&gt;n')
        except:
            cfile.write('&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;n')</code>
Comments on this page are closed.