def string_io(data=None):  # cStringIO can't handle unicode
    try:
        return cStringIO(bytes(data))
    except (UnicodeEncodeError, TypeError):
        return StringIO(data)
Pass data through to stringIO module and return result
dataset/ETHPy150Open saltstack/salt/salt/_compat.py/string_io