Пример #1
0
 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()
Пример #2
0
 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
Пример #3
0
 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()
Пример #4
0
 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)
Пример #5
0
 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()
Пример #6
0
 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()