{"action":"created","issue":{"url":"https://api.github.com/repos/Drekin/win-unicode-console/issues/24","labels_url":"https://api.github.com/repos/Drekin/win-unicode-console/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/Drekin/win-unicode-console/issues/24/comments","events_url":"https://api.github.com/repos/Drekin/win-unicode-console/issues/24/events","html_url":"https://github.com/Drekin/win-unicode-console/issues/24","id":121472490,"number":24,"title":"getpass warns that echo free input is not available","user":{"login":"anthrotype","id":6939968,"avatar_url":"https://avatars.githubusercontent.com/u/6939968?v=3","gravatar_id":"","url":"https://api.github.com/users/anthrotype","html_url":"https://github.com/anthrotype","followers_url":"https://api.github.com/users/anthrotype/followers","following_url":"https://api.github.com/users/anthrotype/following{/other_user}","gists_url":"https://api.github.com/users/anthrotype/gists{/gist_id}","starred_url":"https://api.github.com/users/anthrotype/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anthrotype/subscriptions","organizations_url":"https://api.github.com/users/anthrotype/orgs","repos_url":"https://api.github.com/users/anthrotype/repos","events_url":"https://api.github.com/users/anthrotype/events{/privacy}","received_events_url":"https://api.github.com/users/anthrotype/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-10T12:28:11Z","updated_at":"2015-12-10T18:51:55Z","closed_at":null,"body":"when `win_unicode_console` is enabled, and use `getpass.getpass()` I get:\r\n\r\n```\r\nC:\\Python27\\lib\\getpass.py:92: GetPassWarning: Can not control echo on the terminal.\r\n  return fallback_getpass(prompt, stream)\r\nWarning: Password input may be echoed.\r\nPassword: password\r\n```\r\n\r\nFor now I resorted to disabling it immediately before I call `getpass` and reenabling it afterwards:\r\n```python\r\ndef prompt_password():\r\n    if HAS_WIN_UNICODE_CONSOLE:\r\n        win_unicode_console.disable()\r\n    password = getpass.getpass()\r\n    if HAS_WIN_UNICODE_CONSOLE:\r\n        win_unicode_console.enable()\r\n    return password\r\n```\r\n\r\nDo you know any better workaround or fix?\r\n\r\nAlso, what is the preferred way to check from code if `win_unicode_console` has been previously enabled? It would be nice if there was a function returning a bool which tells whether win_unicode_console is already enabled or not. My global \r\n`HAS_WIN_UNICODE_CONSOLE` in the code above is True whenever `win_unicode_console` can be imported, but that doesn't mean it is also enabled. I don't want to re-enable it if it wasn't before running getpass.\r\n\r\nThanks!\r\n\r\nCosimo\r\n"},"comment":{"url":"https://api.github.com/repos/Drekin/win-unicode-console/issues/comments/163715785","html_url":"https://github.com/Drekin/win-unicode-console/issues/24#issuecomment-163715785","issue_url":"https://api.github.com/repos/Drekin/win-unicode-console/issues/24","id":163715785,"user":{"login":"Drekin","id":7892803,"avatar_url":"https://avatars.githubusercontent.com/u/7892803?v=3","gravatar_id":"","url":"https://api.github.com/users/Drekin","html_url":"https://github.com/Drekin","followers_url":"https://api.github.com/users/Drekin/followers","following_url":"https://api.github.com/users/Drekin/following{/other_user}","gists_url":"https://api.github.com/users/Drekin/gists{/gist_id}","starred_url":"https://api.github.com/users/Drekin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Drekin/subscriptions","organizations_url":"https://api.github.com/users/Drekin/orgs","repos_url":"https://api.github.com/users/Drekin/repos","events_url":"https://api.github.com/users/Drekin/events{/privacy}","received_events_url":"https://api.github.com/users/Drekin/received_events","type":"User","site_admin":false},"created_at":"2015-12-10T18:51:55Z","updated_at":"2015-12-10T18:51:55Z","body":"The problem with `getpass` is the test here: https://hg.python.org/cpython/file/tip/Lib/getpass.py#l100. I'll ask why that test looks like this. A workaround is to temporarily change `sys.stdin` to the original value:\r\n```python\r\nfrom contextlib import _RedirectStream\r\nimport getpass\r\n\r\nclass redirect_stdin(_RedirectStream):\r\n    \"\"\"Context manager for temporarily redirecting stdin to another file.\"\"\"\r\n    \r\n    _stream = \"stdin\"\r\n\r\ndef prompt_password():\r\n    with redirect_stdin(sys.__stdin__):\r\n        return getpass.getpass()\r\n```\r\nNote it is not needed to mention `win_unicode_console` and that is a good thing. Application of `win_unicode_console` should be transparent and ordinary code shouldn't explicitly mention it. Also, it is not possible to signal whether `win_unicode_console` is enabled or not since enabling it may apply various fixes depending on Python version, platform version, and an explicit demand. There is no single “enabled” state.\r\n\r\n"}}