Title: cStringIO does not support arrays as arguments
Type: behaviour Severity: normal
Components: Library Versions: Jython 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amak, fwierzbicki, santa4nt
Priority: high Keywords: patch, test failure causes

Created on 2012-03-20.20:19:10 by fwierzbicki, last changed 2013-03-22.20:26:28 by fwierzbicki.

File name Uploaded Description Edit Remove
issue1862.patch santa4nt, 2013-03-22.05:10:53 Support cStringIO.StringIO(array.array)
msg6929 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2012-03-20.20:19:10
see FIXMEs
msg6998 (view) Author: Alan Kennedy (amak) Date: 2012-03-31.19:22:01
test_getvalue() works for me.

Did you run it again after I fixed this bug?
msg7003 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2012-03-31.20:35:03
I will check today, thanks! I just went through a bunch of tests and slapped FIXMEs around so that I could have a better regression test.
msg7736 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-25.18:17:31
Hmmm - looks like I don't have a very good definition of "today". Setting to high so it stands out on my list.
msg7951 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-03-21.21:16:20
See skipped test in our
msg7952 (view) Author: Santoso Wijaya (santa4nt) Date: 2013-03-22.05:10:53
Should be as simple as adding an overloaded constructor that accepts PyArray, right?
msg7955 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-03-22.16:17:12
Unfortunately not (I tried :) - apparently StringIO.StringIO and cStringIO.StringIO have very different behaviors in CPython:

Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cStringIO
>>> import StringIO
>>> import array
>>> a = array.array('B', [0,1,2])
>>> c = cStringIO(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
>>> c = cStringIO.StringIO(a)
>>> s = StringIO.StringIO(a)
>>> c.getvalue()
>>> s.getvalue()
"array('B', [0, 1, 2])"

Your patch will make our cStringIO act like StringIO. Seems like a CPython bug to me that they behave differently. Maybe they think so too since it looks like StringIO was dropped in Python3.
msg7957 (view) Author: Santoso Wijaya (santa4nt) Date: 2013-03-22.17:08:52
I noticed the same thing! See:
msg7958 (view) Author: Santoso Wijaya (santa4nt) Date: 2013-03-22.17:10:55
Note, though, that with my patch it brings Jython behavior in line with Python behavior, for 2.7.x, warts and all:

Jython 2.7b1+ (default:5554cdeb2854+, Mar 22 2013, 10:09:56) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_17
Type "help", "copyright", "credits" or "license" for more information.
>>> import array
>>> from cStringIO import StringIO
>>> a = array.array('B', [1,2,3])
>>> StringIO(a).getvalue()
>>> from StringIO import StringIO
>>> StringIO(a).getvalue()
"array('B', [1, 2, 3])"
msg7959 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-03-22.17:45:43
Oh! I shot my mouth off before actually testing the patch since it superficially looked like my first try. Thanks!
msg7961 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-03-22.20:26:28
Fixed in - thanks Santoso Wijaya!
Date User Action Args
2013-03-22 20:26:28fwierzbickisetstatus: open -> closed
resolution: fixed
messages: + msg7961
2013-03-22 17:45:43fwierzbickisetmessages: + msg7959
2013-03-22 17:10:55santa4ntsetmessages: + msg7958
2013-03-22 17:08:52santa4ntsetmessages: + msg7957
2013-03-22 16:17:12fwierzbickisetmessages: + msg7955
2013-03-22 05:11:03santa4ntsettype: behaviour
2013-03-22 05:10:54santa4ntsetfiles: + issue1862.patch
keywords: + patch
messages: + msg7952
nosy: + santa4nt
2013-03-21 21:16:20fwierzbickisetassignee: fwierzbicki ->
messages: + msg7951
title: test failures in -> cStringIO does not support arrays as arguments
2013-02-25 18:17:31fwierzbickisetpriority: high
messages: + msg7736
2013-02-20 00:41:32fwierzbickisetassignee: fwierzbicki
versions: + Jython 2.7, - 2.7a1
2012-03-31 20:35:03fwierzbickisetmessages: + msg7003
2012-03-31 19:22:01amaksetnosy: + amak
messages: + msg6998
2012-03-20 20:19:10fwierzbickicreate