posativ / acrylamid

(unmaintained) static blog generator in python with incremental rendering ⛺
http://posativ.org/acrylamid/
Other
277 stars 40 forks source link

fix TypeError from `acrylamid view` in Python 3 #126

Closed sashahart closed 11 years ago

sashahart commented 11 years ago

When a browser asks acrylamid's server for something that doesn't exist in output (e.g.: favicon.ico), an IOError bubbles up from http.server. In the course of handling this, acrylamid.lib.httpd:end_headers (line 47) tries to write a Cache-Control header. However, the string arg is of type str, yielding:

TypeError: 'str' does not support the buffer interface

that's really because write() is expecting a bytestring, like b''. So, this change just adds that b prefix before the string literal.

posativ commented 11 years ago

Most sub commands are not covered by the testsuite unfortunately, so there might be more incompabilities.

sashahart commented 11 years ago

At least heuristically, it worked by checking manually against fresh installs into clean python2.7 and python3.2 virtualenvs, with the relevant change made in httpd.py. If you wanted to support Python 2.5, that will reject b'' with SyntaxError, so in that case this would be a bad change.

And heuristically, I'm not having any other problems with python 3 yet but will notify if I spot some.

posativ commented 11 years ago

I dropped support for 2.5 in favour of easier adoption to python 3 and I would also drop support for 2.6 if it would make it easier to port to python 3. But I would rather wait for adoption of a recent python 3 in most linux distribution and then switch immediately to python 3 without having to maintain both versions.

sashahart commented 11 years ago

Sensible. But I bet you won't have to deprecate even 2.6 any time soon, and I feel that portability with 2.7 is relatively much easier. Considering that I installed and tried 4 different static site generators tonight before acrylamid, all of which either completely failed to install or immediately threw errors when trying to initialize a project, with the most popular one requiring invasive surgery to get anywhere despite plenty of past compatibility effort - this is already doing better than roughly 80% of comparable projects for Python 3 support.. ;)

posativ commented 11 years ago

This surprises me a bit, at least for Pelican (I guess this is the popular generator you meant). Nevertheless, the devil is in the detail, e.g. acrylamid/lib/html.py#L44 and acrylamid/readers.py#L126.