def unpickleStringO(val, sek): """ Convert the output of L{pickleStringO} into an appropriate type for the current python version. This may be called on Python 3 and will convert a cStringIO into an L{io.StringIO}. @param val: The content of the file. @type val: L{bytes} @param sek: The seek position of the file. @type sek: L{int} @return: a file-like object which you can write bytes to. @rtype: L{cStringIO.OutputType} on Python 2, L{io.StringIO} on Python 3. """ x = _cStringIO() x.write(val) x.seek(sek) return x
def StringIO(*args): if args and isinstance(args[0], str): return _cStringIO(*args) return _PureStringIO(*args)