Fix all pyflakes warnings and errors.

This fixes all the warnings and errors pyflakes had found. Most of these
were fairly harmless, but there were a couple newly introduced failures
with undefined functions.