compatible with python 2.6+ and python 3.1+