-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue 326 unicode decode error #374
Merged
carljm
merged 5 commits into
pypa:develop
from
msabramo:fix-issue-326-UnicodeDecodeError
Feb 7, 2012
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
412daad
Modify console_to_str to handle non-ASCII (UTF-8) input.
msabramo b154c82
Modify Logger.log so that it can output UTF-8 encoded messages.
msabramo 1db8285
Revise b154c82 so that it works with Python 2
msabramo a790180
Add a test (test_install_package_that_emits_unicode) for https://gith…
msabramo efe4495
Encapsulate `write`/`buffer` Python 2 vs. Python 3 check into a utili…
msabramo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
# -*- coding: utf-8 -*- | |||
|
|||
from distutils.core import setup | |||
import sys | |||
|
|||
class FakeError(Exception): | |||
pass | |||
|
|||
if sys.argv[1] == 'install': | |||
if hasattr(sys.stdout, 'buffer'): | |||
sys.stdout.buffer.write('\nThis package prints out UTF-8 stuff like:\n'.encode('utf-8')) | |||
sys.stdout.buffer.write('* return type of ‘main’ is not ‘int’\n'.encode('utf-8')) | |||
sys.stdout.buffer.write('* Björk Guðmundsdóttir [ˈpjœr̥k ˈkvʏðmʏntsˌtoʊhtɪr]'.encode('utf-8')) | |||
else: | |||
pass | |||
sys.stdout.write('\nThis package prints out UTF-8 stuff like:\n') | |||
sys.stdout.write('* return type of \xe2\x80\x98main\xe2\x80\x99 is not \xe2\x80\x98int\xe2\x80\x99\n') | |||
sys.stdout.write('* Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir [\xcb\x88pj\xc5\x93r\xcc\xa5k \xcb\x88kv\xca\x8f\xc3\xb0m\xca\x8fnts\xcb\x8cto\xca\x8aht\xc9\xaar]\n') | |||
|
|||
raise FakeError('this package designed to fail on install') | |||
|
|||
setup(name='broken', | |||
version='0.2broken', | |||
py_modules=['broken'], | |||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
import os | |||
from tests.test_pip import here, reset_env, run_pip | |||
|
|||
|
|||
def test_install_package_that_emits_unicode(): | |||
""" | |||
Install a package with a setup.py that emits UTF-8 output and then fails. | |||
This works fine in Python 2, but fails in Python 3 with: | |||
|
|||
Traceback (most recent call last): | |||
... | |||
File "/Users/marc/python/virtualenvs/py3.1-phpserialize/lib/python3.2/site-packages/pip-1.0.2-py3.2.egg/pip/__init__.py", line 230, in call_subprocess | |||
line = console_to_str(stdout.readline()) | |||
File "/Users/marc/python/virtualenvs/py3.1-phpserialize/lib/python3.2/site-packages/pip-1.0.2-py3.2.egg/pip/backwardcompat.py", line 60, in console_to_str | |||
return s.decode(console_encoding) | |||
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 17: ordinal not in range(128) | |||
|
|||
Refs https://github.com/pypa/pip/issues/326 | |||
""" | |||
|
|||
env = reset_env() | |||
to_install = os.path.abspath(os.path.join(here, 'packages', 'BrokenEmitsUTF8')) | |||
result = run_pip('install', to_install, expect_error=True) | |||
assert '__main__.FakeError: this package designed to fail on install' in result.stdout | |||
assert 'UnicodeDecodeError' not in result.stdout |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, let's encapsulate this into pip.backwardcompat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Er, never mind, given the context here (setup.py of a fake package), better leave it as is, not a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, left this as-is.