classification
Title: mmap buffer implementation does not respect seek pos
Type: Stage:
Components: Versions: Python 2.6
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: pitrou Nosy List: Matt.Gattis, georg.brandl, pitrou
Priority: normal Keywords:

Created on 2010-03-02 21:26 by Matt.Gattis, last changed 2010-08-02 16:49 by pitrou. This issue is now closed.

Messages (2)
msg100308 - (view) Author: Matt Gattis (Matt.Gattis) Date: 2010-03-02 21:26
If you do:

import io,mmap

b = io.BytesIO("abc")
m = mmap.mmap(-1,10)
m.seek(5)
b.readinto(m)

M is now:
'abc\x00\x00\x00\x00\x00\x00\x00'

Basically there is no way to readinto/recv_into an arbitary position in an mmap object without creating a middle-man string.
msg112499 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-08-02 16:49
If you want to slice into a writable buffer, you can use a memoryview:

>>> b = io.BytesIO(b"abc")
>>> m = mmap.mmap(-1, 10)
>>> b.readinto(memoryview(m)[5:])
3
>>> m[:]
b'\x00\x00\x00\x00\x00abc\x00\x00'

This only works on 3.x, though.
As for changing the mmap buffer implementation, it would break compatibility and is therefore not acceptable, sorry.
History
Date User Action Args
2010-08-02 16:49:42pitrousetstatus: open -> closed

nosy: + georg.brandl
messages: + msg112499

resolution: rejected
2010-08-01 22:55:16georg.brandlsetassignee: pitrou

nosy: + pitrou
2010-03-02 21:26:04Matt.Gattiscreate