[issue11466] getpass.getpass doesn't close tty file

2021-05-06 Thread Senthil Kumaran


Senthil Kumaran  added the comment:

This was fixed in 
https://github.com/python/cpython/commit/16dbbae2981c96c7c9b1ae81e1708d54b08c10ac

Since Python 3.4

And tests do not raise any ResourceWarning now.

```
$ ../../python -Vs
Python 3.11.0a0
$ ../../python -m unittest test_getpass.py -v
test_username_falls_back_to_pwd (test_getpass.GetpassGetuserTest) ... ok
test_username_priorities_of_env_values (test_getpass.GetpassGetuserTest) ... ok
test_username_takes_username_from_env (test_getpass.GetpassGetuserTest) ... ok
test_flushes_stream_after_prompt (test_getpass.GetpassRawinputTest) ... ok
test_raises_on_empty_input (test_getpass.GetpassRawinputTest) ... ok
test_trims_trailing_newline (test_getpass.GetpassRawinputTest) ... ok
test_uses_stderr_as_default (test_getpass.GetpassRawinputTest) ... ok
test_uses_stdin_as_default_input (test_getpass.GetpassRawinputTest) ... ok
test_uses_stdin_as_different_locale (test_getpass.GetpassRawinputTest) ... ok
test_falls_back_to_fallback_if_termios_raises (test_getpass.UnixGetpassTest) 
... ok
test_falls_back_to_stdin (test_getpass.UnixGetpassTest) ... ok
test_flushes_stream_after_input (test_getpass.UnixGetpassTest) ... ok
test_resets_termios (test_getpass.UnixGetpassTest) ... ok
test_uses_tty_directly (test_getpass.UnixGetpassTest) ... ok

--
Ran 14 tests in 0.041s

OK

```

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

___
Python tracker 

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



[issue11466] getpass.getpass doesn't close tty file

2012-07-24 Thread Anton Barkovsky

Changes by Anton Barkovsky :


Added file: http://bugs.python.org/file26499/closewarning.patch

___
Python tracker 

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



[issue11466] getpass.getpass doesn't close tty file

2012-07-24 Thread Anton Barkovsky

Changes by Anton Barkovsky :


Removed file: http://bugs.python.org/file26498/closewarning.patch

___
Python tracker 

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



[issue11466] getpass.getpass doesn't close tty file

2012-07-24 Thread Anton Barkovsky

Anton Barkovsky  added the comment:

I think I've found the root cause.

On my system (also tested in 3.2) /dev/tty is opened successfully, but wrapping 
it in io.BufferedRandom fails. By the time the exception is raised, FileIO 
object is already created, and then it immediately gets deleted.

I'm attaching a patch that closes the file explicitly in this case.
Be extra careful when reviewing though - this is the first time I'm touching 
Python's C code.

--
Added file: http://bugs.python.org/file26498/closewarning.patch

___
Python tracker 

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



[issue11466] getpass.getpass doesn't close tty file

2012-07-23 Thread Anton Barkovsky

Anton Barkovsky  added the comment:

The issue is still there. I hope someone fixes it before the release.

--
nosy: +anton.barkovsky

___
Python tracker 

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



[issue11466] getpass.getpass doesn't close tty file

2011-09-17 Thread Steffen Daode Nurpmeso

Changes by Steffen Daode Nurpmeso :


--
nosy:  -sdaoden

___
Python tracker 

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



[issue11466] getpass.getpass doesn't close tty file

2011-04-08 Thread Steffen Daode Nurpmeso

Steffen Daode Nurpmeso  added the comment:

Future Buddha to Guru..
Future Buddha to Guru..
My code is like a two-wheeled indian Bullet, royal purple.
Wouldn't you agree with that?

--

___
Python tracker 

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



[issue11466] getpass.getpass doesn't close tty file

2011-03-24 Thread Steffen Daode Nurpmeso

Steffen Daode Nurpmeso  added the comment:

On Thu, Mar 24, 2011 at 02:34:34PM +, Senthil Kumaran wrote:
> assignee:  -> orsenthil

Here is yet another patch which only passes valid streams into 
_user_input(), so that this does not need to take care about that 
at all. 
Would you please review that instead of all the others ;/? 
(It's identical to .5. beside that.) 
Thanks for looking at this issue!

--
Added file: http://bugs.python.org/file21371/11466.6.patch

___
Python tracker 

___diff --git a/Lib/getpass.py b/Lib/getpass.py
--- a/Lib/getpass.py
+++ b/Lib/getpass.py
@@ -38,27 +38,26 @@
 
 Always restores terminal settings before returning.
 """
-fd = None
-tty = None
-try:
-# Always try reading and writing directly on the tty first.
-fd = os.open('/dev/tty', os.O_RDWR|os.O_NOCTTY)
-tty = os.fdopen(fd, 'w+', 1)
-input = tty
-if not stream:
-stream = tty
-except EnvironmentError as e:
-# If that fails, see if stdin can be controlled.
+tty, exinst, passwd = None, None, None
+# Something to break off if an error happens
+while 1:
 try:
-fd = sys.stdin.fileno()
-except (AttributeError, ValueError):
-passwd = fallback_getpass(prompt, stream)
-input = sys.stdin
-if not stream:
-stream = sys.stderr
+# Always try reading and writing directly on the tty first.
+fd = os.open('/dev/tty', os.O_RDWR|os.O_NOCTTY)
+input = tty = os.fdopen(fd, 'w+', 1)
+if not stream:
+stream = tty
+except EnvironmentError:
+# If that fails, see if stdin can be controlled;
+# use generic fallback implementation as last resort
+try:
+fd = sys.stdin.fileno()
+except:
+break
+input = sys.stdin
+if not stream:
+stream = sys.stderr
 
-if fd is not None:
-passwd = None
 try:
 old = termios.tcgetattr(fd) # a copy to save
 new = old[:]
@@ -68,21 +67,29 @@
 tcsetattr_flags |= termios.TCSASOFT
 try:
 termios.tcsetattr(fd, tcsetattr_flags, new)
-passwd = _raw_input(prompt, stream, input=input)
+passwd = _user_input(prompt, stream, input, echooff=True)
+except Exception as e:
+exinst = e
 finally:
 termios.tcsetattr(fd, tcsetattr_flags, old)
-stream.flush()  # issue7208
-except termios.error as e:
+stream.flush() # issue7208 (7246)
+except Exception as e:
 if passwd is not None:
-# _raw_input succeeded.  The final tcsetattr failed.  Reraise
-# instead of leaving the terminal in an unknown state.
-raise
-# We can't control the tty or stdin.  Give up and use normal IO.
-# fallback_getpass() raises an appropriate warning.
-del input, tty  # clean up unused file objects before blocking
-passwd = fallback_getpass(prompt, stream)
+# _user_input succeeded, but the final tcsetattr failed.
+# Reraise the termios.error instead of leaving the terminal
+# in an unknown state.
+exinst = e
+break
 
-stream.write('\n')
+if not exinst and passwd is None:
+# We can't control the tty or stdin. Give up and use normal IO.
+# fallback_getpass() raises an appropriate warning.
+passwd = fallback_getpass(prompt, stream)
+
+if tty:
+tty.close()
+if exinst:
+raise exinst
 return passwd
 
 
@@ -115,21 +122,19 @@
 if not stream:
 stream = sys.stderr
 print("Warning: Password input may be echoed.", file=stream)
-return _raw_input(prompt, stream)
+return _user_input(prompt, stream, sys.stdin, echooff=False)
 
 
-def _raw_input(prompt="", stream=None, input=None):
+def _user_input(prompt, stream, input, echooff=False):
 # This doesn't save the string in the GNU readline history.
-if not stream:
-stream = sys.stderr
-if not input:
-input = sys.stdin
 prompt = str(prompt)
 if prompt:
 stream.write(prompt)
 stream.flush()
 # NOTE: The Python C API calls flockfile() (and unlock) during readline.
 line = input.readline()
+if echooff:
+stream.write('\n')
 if not line:
 raise EOFError
 if line[-1] == '\n':
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11466] getpass.getpass doesn't close tty file

2011-03-24 Thread Senthil Kumaran

Changes by Senthil Kumaran :


--
assignee:  -> orsenthil
nosy: +orsenthil

___
Python tracker 

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



[issue11466] getpass.getpass doesn't close tty file

2011-03-19 Thread Steffen Daode Nurpmeso

Steffen Daode Nurpmeso  added the comment:

On Sat, Mar 19, 2011 at 01:29:28PM +, Éric Araujo wrote:
> It’s a private function, if that makes the patch smaller let’s change it.

The promised 11466.5.patch.  It:

- Fixes #11466 resource warning.
- Fixes bogus newline which would have been written before 
  in case the fallback implementation needs to be used.
  + _raw_input() has been renamed to _user_input() because that 
is what it actually does (wether it's raw depends on caller). 
It will now encapsulate the complete user prompting, 
thus including the mentioned final newline.
- Allows patch-in of #11236 patch without any further 
  adjustments (i.e. no additional catch of another resource 
  warning necessary).
- It cleans up the control flow and the comments a bit which 
  i think was the reason that the first two items above could 
  actually become introduced in the code at all.

But - it's even larger than 11466.4.patch!

--
Added file: http://bugs.python.org/file21297/11466.5.patch

___
Python tracker 

___diff --git a/Lib/getpass.py b/Lib/getpass.py
--- a/Lib/getpass.py
+++ b/Lib/getpass.py
@@ -38,27 +38,25 @@
 
 Always restores terminal settings before returning.
 """
-fd = None
-tty = None
-try:
-# Always try reading and writing directly on the tty first.
-fd = os.open('/dev/tty', os.O_RDWR|os.O_NOCTTY)
-tty = os.fdopen(fd, 'w+', 1)
-input = tty
-if not stream:
-stream = tty
-except EnvironmentError as e:
-# If that fails, see if stdin can be controlled.
+tty, exinst, passwd = None, None, None
+# Something to break off if an error happens
+while 1:
 try:
-fd = sys.stdin.fileno()
-except (AttributeError, ValueError):
-passwd = fallback_getpass(prompt, stream)
-input = sys.stdin
-if not stream:
-stream = sys.stderr
+# Always try reading and writing directly on the tty first.
+fd = os.open('/dev/tty', os.O_RDWR|os.O_NOCTTY)
+input = tty = os.fdopen(fd, 'w+', 1)
+if not stream:
+stream = tty
+except EnvironmentError:
+# If that fails, see if stdin can be controlled;
+# use generic fallback implementation as last resort
+try:
+fd = sys.stdin.fileno()
+except:
+break
+if not stream:
+stream = sys.stderr
 
-if fd is not None:
-passwd = None
 try:
 old = termios.tcgetattr(fd) # a copy to save
 new = old[:]
@@ -68,21 +66,29 @@
 tcsetattr_flags |= termios.TCSASOFT
 try:
 termios.tcsetattr(fd, tcsetattr_flags, new)
-passwd = _raw_input(prompt, stream, input=input)
+passwd = _user_input(prompt, stream, input=input, echooff=True)
+except Exception as e:
+exinst = e
 finally:
 termios.tcsetattr(fd, tcsetattr_flags, old)
-stream.flush()  # issue7208
-except termios.error as e:
+stream.flush() # issue7208 (7246)
+except Exception as e:
 if passwd is not None:
-# _raw_input succeeded.  The final tcsetattr failed.  Reraise
-# instead of leaving the terminal in an unknown state.
-raise
-# We can't control the tty or stdin.  Give up and use normal IO.
-# fallback_getpass() raises an appropriate warning.
-del input, tty  # clean up unused file objects before blocking
-passwd = fallback_getpass(prompt, stream)
+# _user_input succeeded, but the final tcsetattr failed.
+# Reraise the termios.error instead of leaving the terminal
+# in an unknown state.
+exinst = e
+break
 
-stream.write('\n')
+if not exinst and passwd is None:
+# We can't control the tty or stdin. Give up and use normal IO.
+# fallback_getpass() raises an appropriate warning.
+passwd = fallback_getpass(prompt, stream)
+
+if tty:
+tty.close()
+if exinst:
+raise exinst
 return passwd
 
 
@@ -115,10 +121,10 @@
 if not stream:
 stream = sys.stderr
 print("Warning: Password input may be echoed.", file=stream)
-return _raw_input(prompt, stream)
+return _user_input(prompt, stream, input=None, echooff=False)
 
 
-def _raw_input(prompt="", stream=None, input=None):
+def _user_input(prompt, stream, input=None, echooff=False):
 # This doesn't save the string in the GNU readline history.
 if not stream:
 stream = sys.stderr
@@ -130,6 +136,8 @

[issue11466] getpass.getpass doesn't close tty file

2011-03-19 Thread Steffen Daode Nurpmeso

Steffen Daode Nurpmeso  added the comment:

On Sat, Mar 19, 2011 at 01:29:28PM +, Éric Araujo wrote:
> It’s a private function, it that makes the patch smaller let’s change it.

You get a new patch from me tomorrow evening at the latest

--

___
Python tracker 

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



[issue11466] getpass.getpass doesn't close tty file

2011-03-19 Thread Éric Araujo

Éric Araujo  added the comment:

> About security: i think that you, Éric, have referred to this
> when you've said "your patch is not uncontroversial".

No, I was only referring to the fact that one unrelated change was present in a 
patch while it was still being discussed in another issue (“This new patch 
(11466.2.patch) also includes the #11236 patch”).

> it would be easier if _raw_input() would take a terminal_setup=False argument
> and encapsulate echoing of a final newline

It’s a private function, it that makes the patch smaller let’s change it.  The 
current patch looks rather complicated just to close a file object.

--

___
Python tracker 

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



[issue11466] getpass.getpass doesn't close tty file

2011-03-14 Thread Steffen Daode Nurpmeso

Steffen Daode Nurpmeso  added the comment:

Hello, Éric and Gregory, this patch also addresses the problem 
that 'one newline too much' may be written in case of errors. 
The problem is already present in the unpatched code, 
and i admit that 11466.3.patch doesn't fix it.

All of this is written under the assumption that i may touch only 
unix_getpass(), not the rest of this file; it would be easier if 
_raw_input() would take a terminal_setup=False argument and 
encapsulate echoing of a final newline ...

About security: i think that you, Éric, have referred to this 
when you've said "your patch is not uncontroversial". 
There is http://mail.python.org/pipermail/python-dev/2003-December/040579.html, 
and, after looking into OpenBSD:lib/libc/gen/readpassphrase.c, 
i must admit that it would possibly be much better to use a native 
getpass(3) implementation if one is available.

(OpenBSD's getpass() *does not* set ISIG, it just takes care about 
signals and re-kill(2)s them as necessary; it restarts the entire 
getpass() cycle if it's TSTP/TTIN/TTOU and re-kill(2) returns.  
But this belongs to #11236, i guess.)

The mail on #dev is more than seven years old, however, and still 
this getpass.getpass() uses it's naive (compared to OpenBSD, say) 
approach.  And that does not get worse with my patch in the end.

I also want to note that getpass.getpass() may throw IOError 
undocumented, with and without 11466.4.patch applied; 
it does so cleanly upon a49bda5ff3d5. 
And finally i am thankful for all the feedback i can get.

--
Added file: http://bugs.python.org/file21113/11466.4.patch

___
Python tracker 

___diff --git a/Lib/getpass.py b/Lib/getpass.py
--- a/Lib/getpass.py
+++ b/Lib/getpass.py
@@ -38,27 +38,28 @@
 
 Always restores terminal settings before returning.
 """
-fd = None
 tty = None
-try:
-# Always try reading and writing directly on the tty first.
-fd = os.open('/dev/tty', os.O_RDWR|os.O_NOCTTY)
-tty = os.fdopen(fd, 'w+', 1)
-input = tty
-if not stream:
-stream = tty
-except EnvironmentError as e:
-# If that fails, see if stdin can be controlled.
+exinst = None
+passwd = None
+# Something to break off if an error happens
+while 1:
 try:
-fd = sys.stdin.fileno()
-except (AttributeError, ValueError):
-passwd = fallback_getpass(prompt, stream)
-input = sys.stdin
-if not stream:
-stream = sys.stderr
+# Always try reading and writing directly on the tty first.
+fd = os.open('/dev/tty', os.O_RDWR|os.O_NOCTTY)
+input = tty = os.fdopen(fd, 'w+', 1)
+if not stream:
+stream = tty
+except EnvironmentError:
+# If that fails, see if stdin can be controlled,
+# otherwise use generic fallback implementation
+try:
+fd = sys.stdin.fileno()
+except:
+break
+if not stream:
+stream = sys.stderr
+input = sys.stdin
 
-if fd is not None:
-passwd = None
 try:
 old = termios.tcgetattr(fd) # a copy to save
 new = old[:]
@@ -69,20 +70,28 @@
 try:
 termios.tcsetattr(fd, tcsetattr_flags, new)
 passwd = _raw_input(prompt, stream, input=input)
+except Exception as e:
+exinst = e
 finally:
+stream.write('\n')
 termios.tcsetattr(fd, tcsetattr_flags, old)
-stream.flush()  # issue7208
-except termios.error as e:
+stream.flush() # issue7208 (7246)
+except Exception as e:
 if passwd is not None:
 # _raw_input succeeded.  The final tcsetattr failed.  Reraise
 # instead of leaving the terminal in an unknown state.
-raise
-# We can't control the tty or stdin.  Give up and use normal IO.
-# fallback_getpass() raises an appropriate warning.
-del input, tty  # clean up unused file objects before blocking
-passwd = fallback_getpass(prompt, stream)
+exinst = e # e == termios.error
+break
 
-stream.write('\n')
+if not exinst and passwd is None:
+# We can't control the tty or stdin. Give up and use normal IO.
+# fallback_getpass() raises an appropriate warning.
+passwd = fallback_getpass(prompt, stream)
+
+if tty:
+tty.close()
+if exinst:
+raise exinst
 return passwd
 
 
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11466] getpass.getpass doesn't close tty file

2011-03-12 Thread Steffen Daode Nurpmeso

Steffen Daode Nurpmeso  added the comment:

This patch makes getpass.getpass() comply with the documented 
behaviour and fixes #11466. 
It will require no further adjustments for #11236 (except what 
valhallasw's patch does, of course). 
It applies cleanly to:

16:32 ~/src/cpython $ hg identify
ee259a4f3eee tip

--
Added file: http://bugs.python.org/file21093/11466.3.patch

___
Python tracker 

___diff --git a/Lib/getpass.py b/Lib/getpass.py
--- a/Lib/getpass.py
+++ b/Lib/getpass.py
@@ -38,27 +38,28 @@
 
 Always restores terminal settings before returning.
 """
-fd = None
 tty = None
-try:
-# Always try reading and writing directly on the tty first.
-fd = os.open('/dev/tty', os.O_RDWR|os.O_NOCTTY)
-tty = os.fdopen(fd, 'w+', 1)
-input = tty
-if not stream:
-stream = tty
-except EnvironmentError as e:
-# If that fails, see if stdin can be controlled.
+exinst = None
+passwd = None
+# Something to break off if an error happens
+while 1:
 try:
-fd = sys.stdin.fileno()
-except (AttributeError, ValueError):
-passwd = fallback_getpass(prompt, stream)
-input = sys.stdin
-if not stream:
-stream = sys.stderr
+# Always try reading and writing directly on the tty first.
+fd = os.open('/dev/tty', os.O_RDWR|os.O_NOCTTY)
+input = tty = os.fdopen(fd, 'w+', 1)
+if not stream:
+stream = tty
+except EnvironmentError as e:
+# If that fails, see if stdin can be controlled.
+try:
+fd = sys.stdin.fileno()
+except:
+# We need to use the generic fallback implementation
+break
+if not stream:
+stream = sys.stderr
+input = sys.stdin
 
-if fd is not None:
-passwd = None
 try:
 old = termios.tcgetattr(fd) # a copy to save
 new = old[:]
@@ -69,20 +70,28 @@
 try:
 termios.tcsetattr(fd, tcsetattr_flags, new)
 passwd = _raw_input(prompt, stream, input=input)
-finally:
-termios.tcsetattr(fd, tcsetattr_flags, old)
-stream.flush()  # issue7208
+except Exception as e:
+exinst = e
+termios.tcsetattr(fd, tcsetattr_flags, old)
 except termios.error as e:
 if passwd is not None:
 # _raw_input succeeded.  The final tcsetattr failed.  Reraise
 # instead of leaving the terminal in an unknown state.
-raise
-# We can't control the tty or stdin.  Give up and use normal IO.
-# fallback_getpass() raises an appropriate warning.
-del input, tty  # clean up unused file objects before blocking
-passwd = fallback_getpass(prompt, stream)
+exinst = e
+break
 
-stream.write('\n')
+if not exinst and passwd is None:
+# We can't control the tty or stdin. Give up and use normal IO.
+# fallback_getpass() raises an appropriate warning.
+passwd = fallback_getpass(prompt, stream)
+
+if stream:
+stream.write('\n')
+stream.flush() # issue7208, 7246
+if tty:
+tty.close()
+if exinst:
+raise exinst
 return passwd
 
 
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11466] getpass.getpass doesn't close tty file

2011-03-11 Thread Steffen Daode Nurpmeso

Steffen Daode Nurpmeso  added the comment:

On Fri, Mar 11, 2011 at 09:51:32PM +, Éric Araujo wrote:
> If you can write a patch that cleans up the code and closes the 
> files without being too hard to review

I'll try to do so tomorrow.

--

___
Python tracker 

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



[issue11466] getpass.getpass doesn't close tty file

2011-03-11 Thread Éric Araujo

Éric Araujo  added the comment:

If you can write a patch that cleans up the code and closes the files without 
being too hard to review, it could get committed soon.  Then you could adapt 
your patch on the other bug and defend it.

--

___
Python tracker 

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



[issue11466] getpass.getpass doesn't close tty file

2011-03-11 Thread Steffen Daode Nurpmeso

Steffen Daode Nurpmeso  added the comment:

On Fri, Mar 11, 2011 at 09:20:14PM +, Éric Araujo wrote:
> your patch is not uncontroversial.

The code is very ugly, but i think that somewhat reflects 
the code flow of the entire function. 
At least a bit. 
I've forced all mis-uses i could imagine and the patch you see was 
the only solution to avoid the ResourceWarning for all of them. 
Do you disagree in avoiding that warning, or have i missed an 
error??

(But maybe this entire function should be cleaned up a bit to get 
rid of these interlocked try: blocks, which would make it easier 
to write the newline and also close the stream.)

> -1 on the second patch: there’s another issue for that

Well, ok about that.
However, msg128824 seems to indicate that you are willing to 
accept that termios.ISIG shall not be set. 
If you want to treat this as two commits then of course one of the 
patches (for #11236 and #11466) needs to be adjusted after the 
other has been patched in.

So, what is your suggestion? 
Shall i write a patch for #11236 which assumes that 
getpass_fdclose.patch has been integrated yet?

--

___
Python tracker 

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



[issue11466] getpass.getpass doesn't close tty file

2011-03-11 Thread Éric Araujo

Éric Araujo  added the comment:

Sorry, accidentally removed the first patch.

-1 on the second patch: there’s another issue for that, and your patch is not 
uncontroversial.

--
Added file: http://bugs.python.org/file21089/getpass_fdclose.patch

___
Python tracker 

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



[issue11466] getpass.getpass doesn't close tty file

2011-03-11 Thread Éric Araujo

Changes by Éric Araujo :


Removed file: http://bugs.python.org/file21079/getpass_fdclose.patch

___
Python tracker 

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



[issue11466] getpass.getpass doesn't close tty file

2011-03-11 Thread Steffen Daode Nurpmeso

Steffen Daode Nurpmeso  added the comment:

This new patch (11466.2.patch) also includes the #11236 patch, 
because if ^C would work as expected then that would not close the 
fd either. 
It's identical to the first patch beside that.

--
Added file: http://bugs.python.org/file21081/11466.2.patch

___
Python tracker 

___diff --git a/Lib/getpass.py b/Lib/getpass.py
--- a/Lib/getpass.py
+++ b/Lib/getpass.py
@@ -62,20 +62,30 @@
 try:
 old = termios.tcgetattr(fd) # a copy to save
 new = old[:]
-new[3] &= ~(termios.ECHO|termios.ISIG)  # 3 == 'lflags'
+new[3] &= ~termios.ECHO  # 3 == 'lflags'
 tcsetattr_flags = termios.TCSAFLUSH
+do_close = False
 if hasattr(termios, 'TCSASOFT'):
 tcsetattr_flags |= termios.TCSASOFT
 try:
 termios.tcsetattr(fd, tcsetattr_flags, new)
 passwd = _raw_input(prompt, stream, input=input)
+except (EOFError, KeyboardInterrupt):
+do_close = True
+raise
 finally:
 termios.tcsetattr(fd, tcsetattr_flags, old)
-stream.flush()  # issue7208
+if do_close:
+stream.write('\n')
+stream.close()
+else:
+stream.flush()  # issue7208
 except termios.error as e:
 if passwd is not None:
 # _raw_input succeeded.  The final tcsetattr failed.  Reraise
 # instead of leaving the terminal in an unknown state.
+stream.write('\n')
+stream.close()
 raise
 # We can't control the tty or stdin.  Give up and use normal IO.
 # fallback_getpass() raises an appropriate warning.
@@ -83,6 +93,8 @@
 passwd = fallback_getpass(prompt, stream)
 
 stream.write('\n')
+if tty is not None:
+stream.close()
 return passwd
 
 
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11466] getpass.getpass doesn't close tty file

2011-03-11 Thread Antoine Pitrou

Changes by Antoine Pitrou :


--
nosy: +gregory.p.smith

___
Python tracker 

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



[issue11466] getpass.getpass doesn't close tty file

2011-03-11 Thread Steffen Daode Nurpmeso

New submission from Steffen Daode Nurpmeso :

Here is a patch which cures the following 

ResourceWarning: unclosed file <_io.TextIOWrapper name=3 mode='w+'
encoding='UTF-8'>

(This only fixes the bug, not the rest of this code...)
I did not try it out, but according to some hg cat's this also
applies to at least v3.2.

--
components: Library (Lib)
files: getpass_fdclose.patch
keywords: patch
messages: 130560
nosy: eric.araujo, sdaoden
priority: normal
severity: normal
status: open
title: getpass.getpass doesn't close tty file
type: behavior
versions: Python 3.3
Added file: http://bugs.python.org/file21079/getpass_fdclose.patch

___
Python tracker 

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