Message8198

Author jeff.allen
Recipients jamesls, jeff.allen, santa4nt
Date 2013-12-14.22:40:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1387060817.72.0.198898984648.issue2062@psf.upfronthosting.co.za>
In-reply-to
Content
A complete solution, here and many other places where a String argument really means bytes, is to accept any PyObject supporting the Buffer API. Then this would work as it does on CPython:

>>> fd = os.open('x.tmp', os.O_CREAT | os.O_RDWR)
>>> a = bytearray("Stuff and nonsense. ")
>>> os.write(fd, a)
20
>>> os.write(fd, buffer(a))
20
>>> os.write(fd, memoryview(a))
20

It would be cool to find some automagic implementation, but I think it has to be a ByteUtil class (or some such), offering few well-crafted static methods, and a re-write of these methods one by one. Asking a buffer for its String is least work but goes completely against the idea of the buffer API as efficient in-place access, unless it's really a PyString after all.
History
Date User Action Args
2013-12-14 22:40:17jeff.allensetmessageid: <1387060817.72.0.198898984648.issue2062@psf.upfronthosting.co.za>
2013-12-14 22:40:17jeff.allensetrecipients: + jeff.allen, santa4nt, jamesls
2013-12-14 22:40:17jeff.allenlinkissue2062 messages
2013-12-14 22:40:17jeff.allencreate