Issue2188

classification
Title: struct.pack_into / unpack_from don't support bytearray or buffer
Type: behaviour Severity: normal
Components: Library Versions: Jython 2.7
Milestone:
process
Status: open Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: ajdavis, behackett, zyasoft
Priority: normal Keywords:

Created on 2014-08-12.23:06:52 by behackett, last changed 2014-10-06.03:11:22 by zyasoft.

Messages
msg8916 (view) Author: Bernie Hackett (behackett) Date: 2014-08-12.23:06:51
Jython 2.7b3 (default:e81256215fb0, Aug 4 2014, 02:39:51) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_65
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> b = bytearray(b"\x01\x00\x00\x00")
>>> b
bytearray(b'\x01\x00\x00\x00')
>>> struct.pack_into("<i", b, 0, 5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: pack_into takes an array arg
>>> struct.unpack_from("<i", buffer(b))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unpack_from(): 2nd arg can't be coerced to String


These both work in CPython and pypy

Python 2.7.8 (default, Jul 30 2014, 09:03:23) 
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> b = bytearray(b"\x01\x00\x00\x00")
>>> struct.pack_into("<i", b, 0, 5)
>>> b
bytearray(b'\x05\x00\x00\x00')
>>> struct.unpack_from("<i", buffer(b))
(5,)
msg8917 (view) Author: Jim Baker (zyasoft) Date: 2014-08-13.07:47:18
Will be a straightforward fix, by applying the same support for the buffer protocol, vs just taking strings, that we have done elsewhere in the Jython runtime.
msg8918 (view) Author: Jim Baker (zyasoft) Date: 2014-08-13.07:47:28
Target beta 4
History
Date User Action Args
2014-10-06 03:11:22zyasoftsetpriority: normal
2014-08-13 07:47:28zyasoftsetmessages: + msg8918
2014-08-13 07:47:19zyasoftsetresolution: accepted
messages: + msg8917
nosy: + zyasoft
2014-08-13 01:42:11ajdavissetnosy: + ajdavis
2014-08-12 23:06:52behackettcreate