[issue22389] Generalize contextlib.redirect_stdout

2014-10-09 Thread Berker Peksag

Berker Peksag added the comment:

Here's an updated patch.

--
Added file: http://bugs.python.org/file36844/issue22389_v2.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22389
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22389] Generalize contextlib.redirect_stdout

2014-09-29 Thread John Isidore

John Isidore added the comment:

There is stdout_redirected() function [1] that allows to redirect a file object 
given as `stdout` patameter including `sys.stderr`. It works at a file 
descriptor level i.e. it supports redirecting subprocess' output too but it 
doesn't work for StringIO (no fd).

[1] 
http://stackoverflow.com/questions/4675728/redirect-stdout-to-a-file-in-python/22434262#22434262

--
nosy: +John Isidore

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22389
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22389] Generalize contextlib.redirect_stdout

2014-09-26 Thread Yury Selivanov

Yury Selivanov added the comment:

@Berker Peksag: The patch looks fine, although I would rename 'redirect_stream' 
- '_redirect_stream' or '_RedirectStream'

--
nosy: +yselivanov

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22389
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22389] Generalize contextlib.redirect_stdout

2014-09-26 Thread Yury Selivanov

Yury Selivanov added the comment:

@Berker Peksag: Also, please update the docs.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22389
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22389] Generalize contextlib.redirect_stdout

2014-09-26 Thread Berker Peksag

Berker Peksag added the comment:

Good point. Will update the patch. Thanks!

--
type:  - enhancement

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22389
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22389] Generalize contextlib.redirect_stdout

2014-09-12 Thread Raymond Hettinger

Changes by Raymond Hettinger raymond.hettin...@gmail.com:


--
assignee:  - ncoghlan
nosy: +ncoghlan

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22389
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22389] Generalize contextlib.redirect_stdout

2014-09-12 Thread Raymond Hettinger

Raymond Hettinger added the comment:

+1 on Victor's suggestion.  I don't think hypergeneralizing it is the way to 
go.  That adds too much complexity for too little benefit.

--
nosy: +rhettinger

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22389
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22389] Generalize contextlib.redirect_stdout

2014-09-12 Thread STINNER Victor

STINNER Victor added the comment:

redirect_stdout(stderr, stream) looks wrong to be: you want to redirect 
stdout or stderr?

If you want to redirect something else (ex: stdin), you can still implement the 
very simple pattern:

old_stdin = sys.stdin
try:
  sys.stdin = mock_input
  ...
finally:
  sys.stdin = old_stdin

By the way, I'm not convinced that we should add redirect_stderr.

@Barry: How many usage of this new functions do you see in the standard library?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22389
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22389] Generalize contextlib.redirect_stdout

2014-09-12 Thread Nick Coghlan

Nick Coghlan added the comment:

I'm fine with adding redirect_stderr - better to have the obvious
counterpart, rather than hypergeneralising, or having to explain why it's
missing. It's *currently* missing largely on a wait for someone to ask
basis, and Barry asked.

(Tangentially related, I should do a contextlib2 release at some point, but
my previous CI provider shut down...)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22389
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22389] Generalize contextlib.redirect_stdout

2014-09-12 Thread Berker Peksag

Berker Peksag added the comment:

Here's a simple implementation. I will add tests and update the documentation.

--
keywords: +patch
nosy: +berker.peksag
stage:  - patch review
Added file: http://bugs.python.org/file36608/issue22389.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22389
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22389] Generalize contextlib.redirect_stdout

2014-09-11 Thread Barry A. Warsaw

New submission from Barry A. Warsaw:

redirect_stdout is almost exactly what I want, except I want to redirect 
stderr!  redirect_stdout.__init__() should take a 'stream_name' argument 
(possibly keyword-only) which could be set to 'stderr'.  I propose it's 
implemented as setattr(sys, stream_name, new_target)

--
components: Library (Lib)
messages: 226774
nosy: barry
priority: normal
severity: normal
status: open
title: Generalize contextlib.redirect_stdout
versions: Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22389
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22389] Generalize contextlib.redirect_stdout

2014-09-11 Thread STINNER Victor

STINNER Victor added the comment:

Why not adding a new redirect_stderr() function?

--
nosy: +haypo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22389
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22389] Generalize contextlib.redirect_stdout

2014-09-11 Thread Barry A. Warsaw

Barry A. Warsaw added the comment:

On Sep 11, 2014, at 02:25 PM, STINNER Victor wrote:

Why not adding a new redirect_stderr() function?

With a little refactoring redirect_stdout into a subclass, that would work
too.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22389
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com