Make sure hmac.compare_digest() gets string args in Python 2

The hmac.compare_digest() function in Python 2 only accepts string arguments
(i.e. not unicode objects) so when running under older Python versions we
patch-up the definition so it converts its arguments to string if needed
before calling the actual function.

Also, StringIO in Python 2 is an old-style class, so it needs to
additionally inherit from "object" to be able to use super() invocations.