Run autopep8 to comply with PEP8
Don't override built-in name 'dir'
Remove a couple of unnecessary variables
Keep static analyzers like pyflakes happy about globals

_BASE_ENVIRON and _THE_NETWORK are set programmatically in main(), so static
analyzers think that they may not always be declared. So declare them as
global variables at the beginning and we're good.