[issue25880] u'..'.encode('idna') → UnicodeError: label empty or too long

2015-12-18 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The bare UnicodeError is raised also by following codecs: utf_16, utf_32, punycode, undefined, and East-Asian multibyte codecs, and by undocumented an unused function urllib.urlparse.to_bytes(). I think it would be nice to be more specific if possible.

[issue25880] u'..'.encode('idna') → UnicodeError: label empty or too long

2015-12-18 Thread R. David Murray
R. David Murray added the comment: I wonder if we originally only had UnicodeError and it got split later but these codecs were never updated. The codecs date back to the start of unicode support in python2, I think. Adding MAL, he's likely to have an opinion on this ;) Oh, right. The more

[issue25880] u'..'.encode('idna') → UnicodeError: label empty or too long

2015-12-18 Thread Marc-Andre Lemburg
Marc-Andre Lemburg added the comment: On 18.12.2015 20:25, R. David Murray wrote: > I wonder if we originally only had UnicodeError and it got split later but > these codecs were never updated. The codecs date back to the start of > unicode support in python2, I think. UnicodeDecodeError and

[issue25880] u'..'.encode('idna') → UnicodeError: label empty or too long

2015-12-17 Thread SpaceOne
SpaceOne added the comment: It makes error handling really hard. Here is a patch: https://github.com/python/cpython/compare/master...spaceone:idna?expand=1 -- status: closed -> open ___ Python tracker

[issue25880] u'..'.encode('idna') → UnicodeError: label empty or too long

2015-12-17 Thread R. David Murray
R. David Murray added the comment: Can you explain why it makes error handling hard? I'm still not seeing the use case. I've always viewed UnicodeEncodeError vs UnicodeDecodeError as "extra" information for the consumer of the error message, not something that matters in code (I just catch

[issue25880] u'..'.encode('idna') → UnicodeError: label empty or too long

2015-12-17 Thread SpaceOne
SpaceOne added the comment: Because i need to do everywhere where I use this: try: user_input.encode(encoding) except UnicodeDecodeError: raise except (UnicodeError, UnicodeEncodeError): do_my_error_handling() instead of try: user_input.encode(encoding) except

[issue25880] u'..'.encode('idna') → UnicodeError: label empty or too long

2015-12-17 Thread SilentGhost
SilentGhost added the comment: I think what David was trying to say is that you could do try: user_input.encode(encoding) except UnicodeError: do_my_error_handling() since UnicodeError is a super class of UnicodeDecodeError and UnicodeEncodeError. -- nosy: +SilentGhost

[issue25880] u'..'.encode('idna') → UnicodeError: label empty or too long

2015-12-17 Thread SpaceOne
SpaceOne added the comment: I know that UnicodeEncodeError is a subclass of UnicodeError. The problem here is that UnicodeError would also catch UnicodeDecodeError. This is especially disturbing if you catch errors of a whole function. If you e.g. use python2.7 you might want to catch only

[issue25880] u'..'.encode('idna') → UnicodeError: label empty or too long

2015-12-16 Thread SpaceOne
SpaceOne added the comment: But why is the error UnicodeError instead of UnicodeEncodeError? -- resolution: not a bug -> status: closed -> open ___ Python tracker

[issue25880] u'..'.encode('idna') → UnicodeError: label empty or too long

2015-12-16 Thread R. David Murray
R. David Murray added the comment: Why does it matter? If you want to suggest changing it, you could propose a patch. Maybe in reading the code you'll find out why it is the way it is now. I haven't looked at that code in a while myself, so I don't remember if there is a reason or not :)

[issue25880] u'..'.encode('idna') → UnicodeError: label empty or too long

2015-12-16 Thread R. David Murray
R. David Murray added the comment: The error message is accurate. That string has empty label segments in it, which RFC 5890 defines as an error on encoding. There is no such error defined for decoding, so that doesn't raise an error. I don't see anything wrong with the error message, it

[issue25880] u'..'.encode('idna') → UnicodeError: label empty or too long

2015-12-16 Thread R. David Murray
Changes by R. David Murray : -- status: open -> closed ___ Python tracker ___ ___

[issue25880] u'..'.encode('idna') → UnicodeError: label empty or too long

2015-12-16 Thread SpaceOne
New submission from SpaceOne: Python 3.4.2 (default, Oct 8 2014, 10:45:20) >>> u'..'.encode('idna') Traceback (most recent call last): File "/usr/lib/python3.4/encodings/idna.py", line 165, in encode raise UnicodeError("label empty or too long") UnicodeError: label empty or too long The