Python3 compatibility for UserDict

Check python version before trying to import UserDict, get it from collections if 3+, from UserDict otherwise.