ENH Add magic number based format autodetection
BUG Use PyBytes* in Python 3

Misunderstood docs: it's the Bytes version that is portable across
Python 2 and 3.
ENH Return a str from detect_format() in Python 3
Manual merge from upstream