Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue13532] In IDLE, sys.stdout and sys.stderr can write any pickleable object

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Jul 8, 2012, 10:09 PM

Post #1 of 15 (269 views)
Permalink
[issue13532] In IDLE, sys.stdout and sys.stderr can write any pickleable object

Terry J. Reedy <tjreedy [at] udel> added the comment:

The patch (to my production Idle, with name fix) prevents crashing and raises an error instead when an object *can* be pickled, so I will apply before 3.3 if no problems appear and we cannot do better.

But written objects are still pickled, so sys.stdout.write(sys) still raises the PicklingError instead of (as in CP interpreter)
TypeError: must be str, not module

It seems to me that the type check should be done in the subprocess before the object (which should be a string) is pickled. (I also wonder if it is really necessary to pickle a string or the encoded bytes to send it back. The pickle is just a stream of bytes.)

----------
title: In IDLE, sys.stdout.write and sys.stderr can write any pickleable object -> In IDLE, sys.stdout and sys.stderr can write any pickleable object

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13532>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 9, 2012, 11:53 AM

Post #2 of 15 (260 views)
Permalink
[issue13532] In IDLE, sys.stdout and sys.stderr can write any pickleable object [In reply to]

Roundup Robot <devnull [at] psf> added the comment:

New changeset 422242dbce30 by Martin v. Löwis in branch '3.2':
Issue #13532: Check that arguments to sys.stdout.write are strings.
http://hg.python.org/cpython/rev/422242dbce30

----------
nosy: +python-dev

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13532>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 9, 2012, 12:02 PM

Post #3 of 15 (260 views)
Permalink
[issue13532] In IDLE, sys.stdout and sys.stderr can write any pickleable object [In reply to]

Roundup Robot <devnull [at] psf> added the comment:

New changeset 58189e37331c by Martin v. Löwis in branch '2.7':
- Issue #13532: Check that arguments to sys.stdout.write are strings.
http://hg.python.org/cpython/rev/58189e37331c

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13532>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 9, 2012, 12:05 PM

Post #4 of 15 (262 views)
Permalink
[issue13532] In IDLE, sys.stdout and sys.stderr can write any pickleable object [In reply to]

Martin v. Löwis <martin [at] v> added the comment:

All problems in computer science can be solved by another indirection...

I've added another wrapper around the RPC proxy to cause the type error. (A variant of) Roger's patch is still included to support the -n case.

----------
resolution: -> fixed
status: open -> closed

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13532>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 9, 2012, 12:26 PM

Post #5 of 15 (268 views)
Permalink
[issue13532] In IDLE, sys.stdout and sys.stderr can write any pickleable object [In reply to]

Roger Serwy <roger.serwy [at] gmail> added the comment:

I just pulled Martin's patches and they fix the issue. Indirection to the rescue!

There is one very slight problem though with the error message raised on 2.7 since it is different than 3.3. Attached is a patch to fix it.

----------
Added file: http://bugs.python.org/file26333/issue13532_27.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13532>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 9, 2012, 1:28 PM

Post #6 of 15 (264 views)
Permalink
[issue13532] In IDLE, sys.stdout and sys.stderr can write any pickleable object [In reply to]

Martin v. Löwis <martin [at] v> added the comment:

Ah, this indicates that we should support any buffer object...

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13532>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 9, 2012, 1:45 PM

Post #7 of 15 (270 views)
Permalink
[issue13532] In IDLE, sys.stdout and sys.stderr can write any pickleable object [In reply to]

Terry J. Reedy <tjreedy [at] udel> added the comment:

Thanks Martin. I was thinking of adding special-casing inside the rpcproxy class, but the wrapping is pretty clean and clear. Works great in 3.3 Win7-64.

The 2.7 message 'expected a character buffer object' is technically correct*, but opaque, especially to beginners. I actually prefer the 3.x style message, except that 'str' should be expanded to 'string'. (We especially should not say 'character buffer object' until we test for exactly that.)

*My impression is that 2.7 unicode is not a character buffer object, but gets auto converted to str/bytes, which is.

On the technically correct front, bytearray in 2.7 is a character buffer object that .write() can write, but it is not a subclass of basestring. So the widened test in the followup patch
http://hg.python.org/cpython/rev/2993f566c82e
should be widened further.

- if not isinstance(s, basestring):
- raise TypeError('must be str, not ' + type(s).__name__)

+ if not isinstance(s, (basestring, bytearray)):
+ raise TypeError('must be string, not ' + type(s).__name__)

Are there any other 'character buffer' classes that should be included? What *is* the test that 2.7 .write() uses to determine what is such? Can it even be written in Python (rather than C)?

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13532>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 9, 2012, 1:48 PM

Post #8 of 15 (262 views)
Permalink
[issue13532] In IDLE, sys.stdout and sys.stderr can write any pickleable object [In reply to]

Martin v. Löwis <martin [at] v> added the comment:

I'm losing interest in this issue. It already got more attention than it deserves. Terry, feel free to make whatever change you consider desirable.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13532>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 9, 2012, 2:58 PM

Post #9 of 15 (260 views)
Permalink
[issue13532] In IDLE, sys.stdout and sys.stderr can write any pickleable object [In reply to]

Roundup Robot <devnull [at] psf> added the comment:

New changeset 4f891f44ec15 by Terry Jan Reedy in branch '2.7':
Issue 13532: Allow bytearrays to be written also.
http://hg.python.org/cpython/rev/4f891f44ec15

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13532>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 9, 2012, 3:01 PM

Post #10 of 15 (260 views)
Permalink
[issue13532] In IDLE, sys.stdout and sys.stderr can write any pickleable object [In reply to]

Terry J. Reedy <tjreedy [at] udel> added the comment:

I tested and pushed the change to allow bytestrings. If anyone is printing other character buffer objects in 2.7 with Idle, they can explicitly convert to str/bytes, patch run.py, and/or post here or on a new issue for further expansion. I am otherwise done with this too.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13532>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 9, 2012, 11:40 PM

Post #11 of 15 (260 views)
Permalink
[issue13532] In IDLE, sys.stdout and sys.stderr can write any pickleable object [In reply to]

Serhiy Storchaka <storchaka [at] gmail> added the comment:

> + sys.stdin = self.console = _RPCFile(self.get_remote_proxy("stdin"))

write to sys.stdin?

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13532>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 10, 2012, 7:10 AM

Post #12 of 15 (249 views)
Permalink
[issue13532] In IDLE, sys.stdout and sys.stderr can write any pickleable object [In reply to]

Roger Serwy <roger.serwy [at] gmail> added the comment:

sys.stdin has a write method, but it should raise "io.UnsupportedOperation: not writable" when passed a string. It looks like IDLE has allowed writes to stdin even before Martin's patch. I'll open a separate issue for this case.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13532>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 10, 2012, 7:38 AM

Post #13 of 15 (252 views)
Permalink
[issue13532] In IDLE, sys.stdout and sys.stderr can write any pickleable object [In reply to]

Roger Serwy <roger.serwy [at] gmail> added the comment:

Running "input" from IDLE now raises an error. Attached is a fix to _RPCFile to allow readline (and isatty) to function properly.

----------
priority: normal -> high
resolution: fixed ->
status: closed -> open
Added file: http://bugs.python.org/file26342/stdin_fix.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13532>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 10, 2012, 8:36 AM

Post #14 of 15 (250 views)
Permalink
[issue13532] In IDLE, sys.stdout and sys.stderr can write any pickleable object [In reply to]

Serhiy Storchaka <storchaka [at] gmail> added the comment:

>>> sys.stdin.readable()
False
>>> sys.stdout.writable()
False

I think the issue is far from a solution.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13532>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 10, 2012, 11:38 AM

Post #15 of 15 (249 views)
Permalink
[issue13532] In IDLE, sys.stdout and sys.stderr can write any pickleable object [In reply to]

Martin v. Löwis <martin [at] v> added the comment:

Folks: one issue at a time - pretty pretty please.

This issue was "In IDLE, sys.stdout and sys.stderr can write any pickleable object". Will anybody dispute that this issue is fixed?

Roger: please create a new issue for input being broken now. Your patch "shouldn't" be necessary, as __getattr__ should deal with this.

Serhiy: please create a new issue for readable and writable returning an incorrect result.

----------
resolution: -> fixed
status: open -> closed

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13532>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.