Improve compatibility with python 2.6
Fix some deprecation warning (always use the new API)