port to 2.6/2.7 and >= 3.3 - same method as for flask itself

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.