[merge] Unicode Exception fixes
John Arbash Meinel
john at arbash-meinel.com
Mon Aug 21 21:22:09 BST 2006
Aaron Bentley wrote:
> John Arbash Meinel wrote:
>>> There are a few bugs listed, which occur because of how we raise errors
>>> with Unicode strings.
>>> - cmd = str(argv.pop(0))
>>> + cmd = argv.pop(0)
>>> + try:
>>> + cmd = cmd.encode('ascii')
>>> + except UnicodeError:
>>> + raise errors.UnicodeCommand(cmd)
>
> Do we actually want a specific error here? I would think we should
> continue, and let get_cmd_object raise "unknown command" as usual. No
> need to complain about the fact that it's unicode; the fact that it's
> unknown is enough.
I could go either way. But raising an explicit error helps people
realize that we don't support unicode command names.
This could also be done on the register_command() side.
At the very least this gives a nicer traceback.
>
>
>>> --- bzrlib/errors.py
>>> +++ bzrlib/errors.py
>>> @@ -126,7 +126,12 @@
>>>
>>> def __str__(self):
>>> try:
>>> - return self.__doc__ % self.__dict__
>>> + # __str__() should always return a 'str' object
>>> + # never a 'unicode' object.
>>> + s = self.__doc__ % self.__dict__
>>> + if isinstance(s, unicode):
>>> + return s.encode('utf8')
>>> + return s
>>> except (NameError, ValueError, KeyError), e:
>>> return 'Unprintable exception %s: %s' \
>>> % (self.__class__.__name__, str(e))
>
> I think this is going too far; a string may be unicode while still being
> convertible-to-ascii. In any case, we may well be able to print errors
> in unicode, which would be preferable.
>
> How about:
You forget that utf-8 is a strict superset of ascii. All ascii
characters are unchanged in utf-8. So your proposal actually always
gives the same result, only you have to catch yet another exception.
s.encode('ascii') == s.encode('utf8') will always be true unless the
first one raises a UnicodeError.
John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060821/c9ce7d04/attachment.pgp
More information about the bazaar
mailing list