Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e084e97f
Commit
e084e97f
authored
Apr 13, 2014
by
R David Murray
Browse files
Options
Browse Files
Download
Plain Diff
Mierge #21169: fix getpass to use replace error handler on UnicodeEncodeError.
parents
fc8e9883
d5aa487c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
2 deletions
+19
-2
Lib/getpass.py
Lib/getpass.py
+6
-1
Lib/test/test_getpass.py
Lib/test/test_getpass.py
+9
-1
Misc/NEWS
Misc/NEWS
+4
-0
No files found.
Lib/getpass.py
View file @
e084e97f
...
...
@@ -135,6 +135,11 @@ def _raw_input(prompt="", stream=None, input=None):
input
=
sys
.
stdin
prompt
=
str
(
prompt
)
if
prompt
:
try
:
stream
.
write
(
prompt
)
except
UnicodeEncodeError
:
prompt
=
prompt
.
encode
(
stream
.
encoding
,
'replace'
)
prompt
=
prompt
.
decode
(
stream
.
encoding
)
stream
.
write
(
prompt
)
stream
.
flush
()
# NOTE: The Python C API calls flockfile() (and unlock) during readline.
...
...
Lib/test/test_getpass.py
View file @
e084e97f
import
getpass
import
os
import
unittest
from
io
import
BytesIO
,
StringIO
from
io
import
BytesIO
,
StringIO
,
TextIOWrapper
from
unittest
import
mock
from
test
import
support
...
...
@@ -69,6 +69,14 @@ class GetpassRawinputTest(unittest.TestCase):
getpass
.
_raw_input
(
stream
=
StringIO
())
mock_input
.
readline
.
assert_called_once_with
()
@
mock
.
patch
(
'sys.stdin'
)
def
test_uses_stdin_as_different_locale
(
self
,
mock_input
):
stream
=
TextIOWrapper
(
BytesIO
(),
encoding
=
"ascii"
)
mock_input
.
readline
.
return_value
=
"Hasło: "
getpass
.
_raw_input
(
prompt
=
"Hasło: "
,
stream
=
stream
)
mock_input
.
readline
.
assert_called_once_with
()
def
test_raises_on_empty_input
(
self
):
input
=
StringIO
(
''
)
self
.
assertRaises
(
EOFError
,
getpass
.
_raw_input
,
input
=
input
)
...
...
Misc/NEWS
View file @
e084e97f
...
...
@@ -34,6 +34,10 @@ Core and Builtins
Library
-------
- Issue #21169: getpass now handles non-ascii characters that the
input stream encoding cannot encode by re-encoding using the
replace error handler.
- Issue #21171: Fixed undocumented filter API of the rot13 codec.
Patch by Berker Peksag.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment