Can this whole file be sanely indented (PEP8-ified)?  Maybe do this as a last thing after all the other comments have been addressed.