port to python 2.6/2.7 and >= 3.3 using same codebase

Reused already implemented compatibility code from flask._compat
(needs latest flask repo code).

All tests succeed on py 2.7, 1 strange failure left on py 3.3.