2023-08-22 11:15:46 -04:00
|
|
|
import io
|
2016-03-25 09:01:19 -04:00
|
|
|
|
|
|
|
try:
|
|
|
|
io.BytesIO
|
|
|
|
io.BufferedWriter
|
|
|
|
except AttributeError:
|
2021-03-15 09:57:36 -04:00
|
|
|
print("SKIP")
|
2017-06-10 13:14:16 -04:00
|
|
|
raise SystemExit
|
2016-03-25 09:01:19 -04: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-16 21:12:50 -05: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-18 22:15:55 -04:00
|
|
|
|
|
|
|
# hashing a BufferedWriter
|
|
|
|
print(type(hash(buf)))
|