From 07241cd37a732e4219257e6b2fc67a84085b37f6 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 5 Jun 2017 23:54:21 +0300 Subject: py/objstringio: If created from immutable object, follow copy on write policy. Don't create copy of immutable object's contents until .write() is called on BytesIO. --- tests/io/bytesio_cow.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/io/bytesio_cow.py (limited to 'tests/io/bytesio_cow.py') diff --git a/tests/io/bytesio_cow.py b/tests/io/bytesio_cow.py new file mode 100644 index 000000000..92654a000 --- /dev/null +++ b/tests/io/bytesio_cow.py @@ -0,0 +1,20 @@ +# Make sure that write operations on io.BytesIO don't +# change original object it was constructed from. +try: + import uio as io +except ImportError: + import io + +b = b"foobar" + +a = io.BytesIO(b) +a.write(b"1") +print(b) +print(a.getvalue()) + +b = bytearray(b"foobar") + +a = io.BytesIO(b) +a.write(b"1") +print(b) +print(a.getvalue()) -- cgit v1.2.3