PEP 3108 calls for StringIO (which is io.StringIO in 3.0) to have an accelerated version behind it when available. Alexandre has been working on this so assigning to him.
Here's a preliminary patch that add the C optimization for StringIO. All tests are passing except two which depends on the StringIO.buffer attribute of the TextIOWrapper class. Honestly, I am not sure what is the correct way to fix this. I cannot simply "fake" the attribute by returning a BytesIO object, since the file position of buffer is undecidable. It seems to me that the only way to fix these failing tests would be to define a FakeIO class, in their test file, that would wrap ByteIO with TextIOWrapper, just like the old and inefficient StringIO. So, any idea on what would be the best thing to do?
Here's another patch fixes the failing tests. I have tried to support the buffer attribute using following hack: @property def buffer(self): # XXX Hack to support the buffer attribute. buf = codecs.getwriter(self.encoding)(BytesIO(), self.errors) value = self.getvalue() buf.write(value[:self.tell()]) pos = buf.stream.tell() buf.write(value[self.tell():]) buf.stream.seek(pos) return buf.stream but this doesn't work since some application might want to modify the buffer. So, I removed it. Another thing that bothered me were the bogus encoding and errors arguments. So, I also removed them.