Author jeff.allen
Recipients jeff.allen, santa4nt, zyasoft
Date 2014-06-13.20:38:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I decided step 1 was to make PyBuffer extend AutoCloseable, because this work by Indra Talip would have been neater:

Been meaning to since Java 7. So I've done that (testing now, maybe push tonight). You can take over from there if you like.

This article is about the buffer protocol: , but it needs to be updated with the change I just made.

If you look into how some choice codecs work, at the bottom they all seem to depend on entry points in modules/, so it's those that need changing. For a start, accept a PyObject obytes argument, then something like:
if (obytes instanceof BufferProtocol) {
    try (PyBuffer bytes = ((BufferProtocol)obytes).getBuffer(PyBUF.SIMPLE)) {
} else {
    throw Py.TypeError("must be string or buffer, not " ... )

You should then find the existing code bytes.charAt() still works, or it might be better to say this stuff really is bytes now. The soft option is ask for it as a String again, but IMO that's perpetuating a misdemeanor.

My worry was that a lot of helper methods, and maybe some clients of these methods, would have to change signature, so it would end up really quite extensive. Maybe they should anyway.

I couldn't find a test that exposes this problem, so I was going to add to, something like:
def round_trip(u, name) :
    s = u.encode(name)
    dec = codecs.getdecoder(name)
    for B in (buffer, memoryview, bytearray) :
        self.assertEqual(u, dec(B(s))[0])

(I think that's correct.) Then call it with a variety of unicode strings and codec names.
Date User Action Args
2014-06-13 20:38:08jeff.allensetmessageid: <>
2014-06-13 20:38:08jeff.allensetrecipients: + jeff.allen, zyasoft, santa4nt
2014-06-13 20:38:08jeff.allenlinkissue2164 messages
2014-06-13 20:38:07jeff.allencreate