Merge lp:~ryorke/bzr/140563-optparse-barfs-on-unicode into lp:bzr
| Status: | Merged |
|---|---|
| Approved by: | Martin Packman on 2010-11-04 |
| Approved revision: | 5517 |
| Merged at revision: | 5529 |
| Proposed branch: | lp:~ryorke/bzr/140563-optparse-barfs-on-unicode |
| Merge into: | lp:bzr |
| Diff against target: |
52 lines (+20/-1) 3 files modified
bzrlib/commands.py (+7/-1) bzrlib/tests/blackbox/test_exceptions.py (+11/-0) doc/en/release-notes/bzr-2.3.txt (+2/-0) |
| To merge this branch: | bzr merge lp:~ryorke/bzr/140563-optparse-barfs-on-unicode |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Martin Packman (community) | 2010-10-24 | Approve on 2010-11-04 | |
|
Review via email:
|
|||
Commit Message
Trap UnicodeError from optparse parsing.
Description of the Change
This change is for bug 140563.
optparse can't handle non-ASCII option names. This commit doesn't try to fix
that, but, as suggested in the bug discussion, reports an error that might
give the user a better idea of what the problem is.
A test has been added to blackbox.
right place, though running this test with different encodings doesn't really
make sense.
There's a patch that puportedly fixes optparse; see
http://
I don't know how Python development works, but I can't imagine it'll be
backported to older versions (<2.7), so we may be stuck with this for a while.
| Rory Yorke (ryorke) wrote : | # |
OK, so after some tests, I have:
| Platform | test_nonascii_
|------
| Lin py24 | fail | ERROR: no such option: -ä |
| Lin py25-26 | pass | ERROR: Only ASCII permitted in option names |
| Win py24 | error | ERROR: no such option: -ä |
| Win py27 | pass* | ERROR: Only ASCII permitted in option names |
On Windows/Python 2.7, four of the five tests are skipped; each one's for a
different user encoding. This seems to be unrelated to command options, but
is something to do with a path:
Unable to represent path u'\u0422\
"cp437 " (even though it is valid in filesystem encoding "mbcs"))
On Windows/Python 2.4, the test errors out spectacularly with a
UnicodeEncodeError (assume this is what you referred to).
I'm not sure what to do. One possibility is allowing either error form ("only
ascii" and "no such option"); in this case the test passes everywhere.
I don't understand your suggestion. What's the "nix path"?
| Martin Packman (gz) wrote : | # |
Sorry Rory, looked at this in rather a rush and drew the wrong conclusion. Well done for investigating and finding out the problem was me being weird and running Python 2.4 and not me being weird and running windows.
> On Windows/Python 2.7, four of the five tests are skipped; each one's for a
> different user encoding. This seems to be unrelated to command options, but
> is something to do with a path:
This is something else I should have mentioned, you don't really want to put your test there, as you don't need the weird locale fiddling. How about bzrlib.
> On Windows/Python 2.4, the test errors out spectacularly with a
> UnicodeEncodeError (assume this is what you referred to).
Yep.
> I'm not sure what to do. One possibility is allowing either error form ("only
> ascii" and "no such option"); in this case the test passes everywhere.
Well, you could either skip or just check the different output on `sys.version_info < (2, 5)` as that's where the optparse bug seems to have been introduced.
> I don't understand your suggestion. What's the "nix path"?
Rather moot now, but I was wondering if the decode step could be moved after the optparse step on posix systems as the command line is 8 bit natively there whereas it's 16 bit natively on modern windows systems.
- 5516. By Rory Yorke on 2010-10-29
-
Added comment on try-except around pargse_args(), w/ pointer to Python bug.
- 5517. By Rory Yorke on 2010-10-29
-
Moved test to bb.test_exceptions, and test differently for Python 2.4.
In Python 2.4, optparse doesn't raise a bug if fed non-ASCII option
names; check for that case separately. This change is needed to prevent
bzr selftest breaking on Windows with Python 2.4.
| Martin Packman (gz) wrote : | # |
Thanks Rory, this looks solid now. As you've got the important stuff down, also start thinking about trivial things like PEP 8, spaces around equals signs and commas and such like.
| John A Meinel (jameinel) wrote : | # |
sent to pqm by email

Nitpick, I'd like a comment by that try/except explaining the optparse problem we're working around and linking the upstream bug.
I get different behaviour on windows. Rather than throwing, it mangles the bytes. This breaks your test, and then the whole run as the fix for bug 633216 hasn't landed.
Suggests you could perhaps give optparse bytes on the nix path, then decode what you get back instead?