Fix spacing according to the PEP-8 style guide

Top-level functions and classes should be separated with two line
breaks. Also remove extra spaces where used.

Signed-off-by: Marcus Karlsson <mk@acc.umu.se>
Use is instead of == for comparison with None

Use the is operator instead of == when comparing with None, as
recommended by the PEP-8 style guide.

Signed-off-by: Marcus Karlsson <mk@acc.umu.se>
Use in instead of deprecated has_key

The has_key method is deprecated. Instead use the in operator.

Signed-off-by: Marcus Karlsson <mk@acc.umu.se>