Re: [Python-Dev] [Python-checkins] r46300 - in python/trunk: Lib/socket.py Lib/test/test_socket.py Lib/test/test_struct.py Modules/_struct.c Modules/arraymodule.c Modules/socketmodule.c
On May 26, 2006, at 4:56 PM, Guido van Rossum wrote:
On 5/26/06, martin.blais
wrote: Log: Support for buffer protocol for socket and struct.
* Added socket.recv_buf() and socket.recvfrom_buf() methods, that use the buffer protocol (send and sendto already did).
* Added struct.pack_to(), that is the corresponding buffer compatible method to unpack_from().
Hm... The file object has a similar method readinto(). Perhaps the methods introduced here could follow that lead instead of using two different new naming conventions?
(speaking specifically about struct and not socket) pack_to and unpack_from are named as such because they work with objects that support the buffer API (not file-like-objects). I couldn't find any existing convention for objects that manipulate buffers in such a way. If there is an existing convention then I'd be happy to rename these. "readinto" seems to imply that some kind of position is being incremented. Grammatically it only works if it's implemented on all buffer objects, but in this case it's implemented on the Struct type. -bob
[python-checkins]
* Added socket.recv_buf() and socket.recvfrom_buf() methods, that use the buffer protocol (send and sendto already did).
* Added struct.pack_to(), that is the corresponding buffer compatible method to unpack_from().
[Guido]
Hm... The file object has a similar method readinto(). Perhaps the methods introduced here could follow that lead instead of using two different new naming conventions?
On 5/27/06, Bob Ippolito
(speaking specifically about struct and not socket)
pack_to and unpack_from are named as such because they work with objects that support the buffer API (not file-like-objects). I couldn't find any existing convention for objects that manipulate buffers in such a way.
Actually, <fileobject>.readinto(<bufferobject>) is the convention I started long ago (at the time the buffer was introduced.
If there is an existing convention then I'd be happy to rename these.
"readinto" seems to imply that some kind of position is being incremented.
No -- it's like read() but instead of returning a new object it reads "into" an object you pass.
Grammatically it only works if it's implemented on all buffer objects, but in this case it's implemented on the Struct type.
It looks like <structobject>.pack_to(<bufferobject>, <other args>) is similar to <fileobject>.readinto(<bufferobject>) in that the buffer object receives the result of packing / reading. (Files don't have a writefrom() method because write() can be polymorphic. read() can't be due to the asymmetry in the API. I guess struct objects are different.) -- --Guido van Rossum (home page: http://www.python.org/~guido/)
On 5/29/06, Guido van Rossum
[python-checkins]
* Added socket.recv_buf() and socket.recvfrom_buf() methods, that use the buffer protocol (send and sendto already did).
* Added struct.pack_to(), that is the corresponding buffer compatible method to unpack_from().
[Guido]
Hm... The file object has a similar method readinto(). Perhaps the methods introduced here could follow that lead instead of using two different new naming conventions?
On 5/27/06, Bob Ippolito
wrote: (speaking specifically about struct and not socket)
pack_to and unpack_from are named as such because they work with objects that support the buffer API (not file-like-objects). I couldn't find any existing convention for objects that manipulate buffers in such a way.
Actually, <fileobject>.readinto(<bufferobject>) is the convention I started long ago (at the time the buffer was introduced.
If there is an existing convention then I'd be happy to rename these.
"readinto" seems to imply that some kind of position is being incremented.
No -- it's like read() but instead of returning a new object it reads "into" an object you pass.
Grammatically it only works if it's implemented on all buffer objects, but in this case it's implemented on the Struct type.
It looks like <structobject>.pack_to(<bufferobject>, <other args>) is similar to <fileobject>.readinto(<bufferobject>) in that the buffer object receives the result of packing / reading.
So I assume you're suggesting the following renames: pack_to -> packinto recv_buf -> recvinto recvfrom_buf -> recvfrominto (I don't like that last one very much. I'll go ahead and make those renames once I return.)
On 5/31/06, Martin Blais
So I assume you're suggesting the following renames:
pack_to -> packinto recv_buf -> recvinto recvfrom_buf -> recvfrominto
(I don't like that last one very much. I'll go ahead and make those renames once I return.)
You could add an underscore before _into. -- --Guido van Rossum (home page: http://www.python.org/~guido/)
On 5/31/06, Guido van Rossum
On 5/31/06, Martin Blais
wrote: So I assume you're suggesting the following renames:
pack_to -> packinto recv_buf -> recvinto recvfrom_buf -> recvfrominto
(I don't like that last one very much. I'll go ahead and make those renames once I return.)
You could add an underscore before _into.
Will do! cheers,
participants (3)
-
Bob Ippolito
-
Guido van Rossum
-
Martin Blais