Avoid using execfile which was removed in python 3.
Avoid implicit relative imports for python 3 compatibility.
Use python 3 compatible except syntax.
Use six module to support python 3 urllib refactor.
Use sys.stderr.write to print to stderr for python 3 compatibility.
Use six to define a metaclass in a python 2 and 3 compatible way.
Use six to get dict items iterator for python 3 compatibility.
Encode strings before passing to md5 which expects bytes in python 3.
Encode http body as bytes for python 3 compatibility.
Normalize the permission url to allow query parameters to be reordered.

This was failing in python 3 because the permission url was being generated
with query params in a different order.
Fix unclosed file warning in python 3 when running the tests.
Don't inherit from StandardError which was removed in python 3.

StandardError is actually meant for builtin excpetions (i.e. ones defined
by the standard library).
Use compile to associate filename with exec code.
Use reduce in functools module for python 3 compatibility.
Use open instead of file function for python 3 compatibility.
Explicitly convert keys to a list before appending for python 3 compatibility.