The attached patches make py-Xlib compile with python-3.1, while dropping support for python-2.4.x and python-2.5.x (2.6.x and 2.7.x are fine).
Patch for python-3.1 support.
I'm afraid above patch was only the tip of the iceberg. Current xlib still uses tons of deprecated Python concepts, such as old-style classes, intermixing bytes and str, calling apply(), obsolete cmp(), the "new" module, and so on. On top of that, there are some Python 3 specific things which need to be ported, such as / now yielding a float (needs //), and imports now always being absolute instead of relative.
The attached patch ports the whole Xlib, plus the examples and the tests. With this, all test cases and examples work with both python 2.7 and 3.3.
Here is an updated version of the patch that fixes a couple of porting errors.