On Sat, Sep 28, 2013 at 4:18 PM, Jeff Allen <email@example.com> wrote:
> The alert will have noticed that Jython now supports the buffer type.
> buffer() is reasonably complete (not sure about comparisons) but the
> thing that lets it down is that other objects do not know how to accept
> the buffer interface as an argument. That needs correcting, and I'm
> starting with str (PyString).
> I have worked through the API of str, and almost everywhere a str/bytes
> argument is allowed, it will accept a buffer in CPython 2.7.5. It
> doesn't accept a memoryview in the same places, until Python 3k. In
> Jython buffer() and memoryview() both implement the same buffer
> interface, so to accept one is to accept the other (unless I actively
> prevent it for consistency with CPython, which I think foolish).
>Is it possible to overload the functions so that we still take
> I would like to check that these things are not bad ideas before I write
> too much:
> 1. I will change the signature of about a dozen of the exposed methods
> to take a PyObject argument where they currently take Java String. (They
> are package-visible, so I should find any call sites easily.)
java.lang.String? I think it would be too bad if we had to lose the
ability to call the methods that take java.lang.String. For example,
if we are calling from Java we might have a java.lang.String and it
would be inconvenient to be forced to wrap it in a PyObject first.
> 2. l will re-use the implementation of affected methods, but have a
> helper function that derives the String from whatever the PyObject
> argument is. This helper function is also responsible for raising a
> TypeError. The CPython 2.7.5 message is "expected a character buffer
> object". I propose to use the 3.3-ish "expected str, bytearray or buffer
> compatible object".
Might it be possible to just keep the methods public?
That sounds good to me.
> 3. The CPython 3.3 bytes type accepts memoryview in a few more places
> than 2.7.5 accepts buffer. I plan to accept either in all the places 3.3
> accepts memoryview.