Fixing backwards-compatibility patches

Several functions are patched in for compatibility with various
versions of Python. These patches are now done the same way.