[issue6991] logging encoding failes some situation

2009-09-25 Thread Naoki INADA
Naoki INADA added the comment: OK, I agree. Thank you for your answer. -- ___ Python tracker ___ ___ Python-bugs-list mailing list Uns

[issue6991] logging encoding failes some situation

2009-09-25 Thread Vinay Sajip
Vinay Sajip added the comment: It's not about logging - your first example (foo.py) didn't have any logging code in it. The problem is caused only when someone doesn't understand how Unicode and codecs.open works, and logging can't fix this. The rule is: If you use a stream without encoding an

[issue6991] logging encoding failes some situation

2009-09-25 Thread Naoki INADA
Naoki INADA added the comment: OK, you're right. But logging is very basic feature and used very wide modules. "All logging code should use unicode string" is right but difficult. And logging may be used for debbuging usually. So I think logging should write log as safe as possible. When log.er

[issue6991] logging encoding failes some situation

2009-09-25 Thread Vinay Sajip
Vinay Sajip added the comment: Your second example (logging_error.py) fails for the same reason - you're writing a byte-string to a stream which is expecting Unicode. The error occurs in logging only it tries encoding as UTF-8 as a last-ditch attempt - and that only happens because of an earlier

[issue6991] logging encoding failes some situation

2009-09-25 Thread Naoki INADA
Naoki INADA added the comment: Another sample. Traceback (most recent call last): File "C:\usr\Python2.6\lib\logging\__init__.py", line 790, in emit stream.write(fs % msg.encode("UTF-8")) UnicodeDecodeError: 'ascii' codec can't decode byte 0xaa in position 0: ordinal not in range(128) Th

[issue6991] logging encoding failes some situation

2009-09-25 Thread Vinay Sajip
Vinay Sajip added the comment: There seems to be a problem with your foo.py. In it, you are writing a byte-string to a stream returned from codecs.open. I don't think this is correct: you should be writing a Unicode string to that stream, which will convert to bytes using the stream's encoding,

[issue6991] logging encoding failes some situation

2009-09-25 Thread Naoki INADA
Naoki INADA added the comment: Please see and execute an attached foo.py. In Python 2.6.2, this cause following error: >python foo.py Traceback (most recent call last): File "foo.py", line 3, in f.write('\xaa') File "C:\usr\Python2.6\lib\codecs.py", line 686, in write return self.w

[issue6991] logging encoding failes some situation

2009-09-25 Thread Vinay Sajip
Vinay Sajip added the comment: Thanks, but I'm not sure I understand the reasoning. stream.write(unicode_string) should not do decode() internally, though of course it would do encode(). Can you explain a little more (with an illustrative example) what problem you are trying to solve, and attach

[issue6991] logging encoding failes some situation

2009-09-25 Thread Benjamin Peterson
Changes by Benjamin Peterson : -- assignee: -> vinay.sajip nosy: +vinay.sajip ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue6991] logging encoding failes some situation

2009-09-25 Thread Naoki INADA
Changes by Naoki INADA : -- type: -> behavior ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.pytho

[issue6991] logging encoding failes some situation

2009-09-24 Thread Naoki INADA
Changes by Naoki INADA : -- versions: +Python 3.0, Python 3.1, Python 3.2 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsu

[issue6991] logging encoding failes some situation

2009-09-24 Thread Naoki INADA
New submission from Naoki INADA : When stream is codecs.writer object, stream.write(string) does string.decode() internally and it may cause UnicodeDecodeError. Then, fallback to utf-8 is not good. I think good fallback logic is: * When message is unicode, message.encode(stream.encoding or 'asci