[issue23637] Warnings error with non-ascii chars.

2015-05-17 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
resolution:  - fixed
stage: patch review - resolved
status: open - closed

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



[issue23637] Warnings error with non-ascii chars.

2015-05-16 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 22e44a7ee89f by Serhiy Storchaka in branch '2.7':
Issue #23637: Showing a warning no longer fails with UnicodeErrror.
https://hg.python.org/cpython/rev/22e44a7ee89f

--
nosy: +python-dev

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



[issue23637] Warnings error with non-ascii chars.

2015-05-13 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

One of the worst things in Python 2 is that all can work on author's machine in 
ASCII-only environment, but then unhelpfully fail on user machine with 
non-ASCII data. Especially when needed a combination of few conditions for the 
fail. This issue is about one of such cases. And even worse, it makes the 
program fail with unfriendly error message during an attempt to output possible 
helpful warning. It is very desirable to me to solve it.

What would you say about this Benjamin?

--

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



[issue23637] Warnings error with non-ascii chars.

2015-03-26 Thread STINNER Victor

STINNER Victor added the comment:

 Only thing required to make this work is add u in front of the message so 
 it is unicode.

The warnings module works with non-ASCII characters if you only use bytes 
strings. I'm not sure that we should enhance it to support the unicode type in 
some fields, and bytes fields in other fields.

This issue was already fixed in Python 3 with the global switch to Unicode by 
default for all strings.

I would prefer to not fix this issue.

Since it looks to a new feature, it's also not a good practice to add new 
features in minor python versions (2.7.x).

--
nosy: +haypo

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



[issue23637] Warnings error with non-ascii chars.

2015-03-26 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The problem is that the warnings module works with unicode message almost all 
time except rare circumstances. So for sure this feature is used in many 
programs and it works for authors and most of users. An exception can be 
considered as a bug.

--

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



[issue23637] Warnings error with non-ascii chars.

2015-03-24 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
assignee:  - serhiy.storchaka

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



[issue23637] Warnings error with non-ascii chars.

2015-03-13 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The problem is not only with the file.write(). If one of arguments is unicode 
(even if it doesn't contain non-ascii characters) and other argument is 
non-ascii string, we get this error.

 warnings.showwarning(u'', DeprecationWarning, 'filè.py', 10)
Traceback (most recent call last):
  File stdin, line 1, in module
  File /home/serhiy/py/cpython-2.7/Lib/warnings.py, line 33, in _show_warning
file.write(formatwarning(message, category, filename, lineno, line))
  File /home/serhiy/py/cpython-2.7/Lib/warnings.py, line 42, in formatwarning
s =  %s:%s: %s: %s\n % (filename, lineno, category.__name__, message)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3: ordinal 
not in range(128)

Non-ascii file names are rare, and unicode warnings are rare, that is why this 
bug was not fixed before. I think it is worth to fix. It is better to output 
modified warning (e.g. backslashescaped) than fail without clear diagnostic.

--
nosy: +serhiy.storchaka
resolution: not a bug - 
stage: resolved - 
status: closed - open

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



[issue23637] Warnings error with non-ascii chars.

2015-03-13 Thread Ezio Melotti

Ezio Melotti added the comment:

I think that the problem is actually with the file.write() in _show_warning().
If any of the arguments of formatwarning() are unicode, the result will be 
unicode, and if file (default sys.stderr) is opened in binary mode, Python 
will try to encode the unicode result with the ASCII codec and fail with a 
UnicodeEncodeError:

 warnings.showwarning(u'你好', DeprecationWarning, 'foo.py', 10)
foo.py:10: DeprecationWarning: 你好
 with open('err.log', 'wb') as f:
... warnings.showwarning(u'你好', DeprecationWarning, 'foo.py', 10, file=f)
... 
Traceback (most recent call last):
  File stdin, line 2, in module
  File /usr/lib/python2.7/warnings.py, line 30, in _show_warning
file.write(formatwarning(message, category, filename, lineno, line))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 31-32: 
ordinal not in range(128)

--
nosy: +ezio.melotti
resolution:  - not a bug
stage:  - resolved
status: open - closed
type: crash - behavior

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



[issue23637] Warnings error with non-ascii chars.

2015-03-13 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is a patch that tries to coerce non-ascii filename and line to unicode 
using appropriate encoding if it is needed and possible. If it is not possible, 
the warning just gets lost, as in the case of IO error.

--
keywords: +patch
stage:  - patch review
Added file: http://bugs.python.org/file38475/warnings_unicode.patch

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



[issue23637] Warnings error with non-ascii chars.

2015-03-12 Thread R. David Murray

R. David Murray added the comment:

Can you provide a complete failure example?  If message is unicode, the format 
string should (in python2) be auto-promoted to unicode.

--
nosy: +r.david.murray

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



[issue23637] Warnings error with non-ascii chars.

2015-03-11 Thread Lukáš Němec

New submission from Lukáš Němec:

File /usr/lib/python2.7/warnings.py, line 29, in _show_warning
file.write(formatwarning(message, category, filename, lineno, line))
  File /usr/lib/python2.7/warnings.py, line 38, in formatwarning
s =  %s:%s: %s: %s\n % (filename, lineno, category.__name__, message)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in position 
42: ordinal not in range(128)

Only thing required to make this work is add u in front of the message so it 
is unicode. This will work for all ascii characters and all non-ascii should 
pass unicode anyway.

--
components: Library (Lib)
messages: 237850
nosy: Lukáš.Němec
priority: normal
severity: normal
status: open
title: Warnings error with non-ascii chars.
type: crash
versions: Python 2.7

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