class StringIO(object): def __init__(self, s=b''): if s: self.builder = StringBuilder(len(s)) self.builder.append(s) else: self.builder = StringBuilder() def write(self, s): self.builder.append(s) def getvalue(self): return self.builder.build()
def test_stringbuilder(self): from __pypy__.builders import BytesBuilder b = BytesBuilder() b.append(b"abc") b.append(b"123") assert len(b) == 6 b.append(b"you and me") s = b.build() assert len(b) == 16 assert s == b"abc123you and me" assert b.build() == s
def test_stringbuilder(self): from __pypy__.builders import BytesBuilder b = BytesBuilder() b.append(b"abc") b.append(b"123") assert len(b) == 6 b.append(b"you and me") s = b.build() raises(ValueError, len, b) assert s == b"abc123you and me" raises(ValueError, b.build)
class StringIO(object): def __init__(self, s=b''): if s: self.builder = StringBuilder(len(s)) self.builder.append(s) else: self.builder = StringBuilder() def write(self, s): if isinstance(s, memoryview): s = s.tobytes() self.builder.append(s) def getvalue(self): return self.builder.build()
def __init__(self, s=b""): if s: builder = StringBuilder(len(s)) builder.append(s) else: builder = StringBuilder()