Serhiy Storchaka added the comment:
There is also a problem with deepcopying:
>>> class MemReader:
... def __init__(self, data):
... self.buf = memoryview(data).cast('B')
... def read(self, size=-1):
... if size < 0:
... size = len(self.buf)
... res = bytes(self.buf[:size])
... self.buf = self.buf[size:]
... return res
... def close():
... pass
... def __deepcopy__(self, memo):
... return MemReader(self.buf)
... def __reduce__(self):
... return MemReader, (bytes(self.buf),)
...
>>> import codecs, copy
>>> s1 = codecs.getreader('utf-8')(MemReader(b'abcd'))
>>> s2 = copy.deepcopy(s1)
>>> s1.read()
'abcd'
>>> s2.read()
b'abcd'
>>> s2
<__main__.MemReader object at 0xb701988c>
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue6395>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com