replace StringIO by BytesIO, basestring by str to enable a subset of features in Python 3.