2022-08-18 07:57:45 +01:00
|
|
|
import io
|
2016-03-25 13:01:19 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
io.BytesIO
|
|
|
|
io.BufferedWriter
|
|
|
|
except AttributeError:
|
|
|
|
print('SKIP')
|
2017-06-10 18:14:16 +01:00
|
|
|
raise SystemExit
|
2016-03-25 13:01:19 +00:00
|
|
|
|
|
|
|
bts = io.BytesIO()
|
|
|
|
buf = io.BufferedWriter(bts, 8)
|
|
|
|
|
|
|
|
buf.write(b"foobar")
|
|
|
|
print(bts.getvalue())
|
|
|
|
buf.write(b"foobar")
|
|
|
|
# CPython has different flushing policy, so value below is different
|
|
|
|
print(bts.getvalue())
|
|
|
|
buf.flush()
|
|
|
|
print(bts.getvalue())
|
|
|
|
buf.flush()
|
|
|
|
print(bts.getvalue())
|
2017-01-17 02:12:50 +00:00
|
|
|
|
|
|
|
# special case when alloc is a factor of total buffer length
|
|
|
|
bts = io.BytesIO()
|
|
|
|
buf = io.BufferedWriter(bts, 1)
|
|
|
|
buf.write(b"foo")
|
|
|
|
print(bts.getvalue())
|
2023-05-19 03:15:55 +01:00
|
|
|
|
|
|
|
# hashing a BufferedWriter
|
|
|
|
print(type(hash(buf)))
|