fix some syntax errors, partially restore python 3.x compatibility (tests still fail)