Python 2/3 compatible character encoding detector.