flake8: cleanup lots of lint warnings

Mostly whitespace adjustments, some unused import removal, and no
intentional functionality changes.  Having a cleaner lint allows
easier detection of future errors, as well as providing the benefits
of a consistent style.
don't use mutable types for default parameter values

Mutable kwarg defaults can produce all kinds of unexpected behaviors,
this commit replaces them with immutable values.
connection: comprehensions for performance
connection: added proper logging

Instead of hardcoding debug output to go to stdout, this commit updates
the connection module to use the python logging interface, allowing
clients to customize handling and format of any generated messages.
version: bump to 0.3.1