Enable Python 3 compatibility

Make the StringIO import conditional. Add parentheses to print statements.
Refactor function "subscribe"

Try to make the function easy to read, and do make the function
pylint-compliant.