Re: [Pyobjc-dev] non-default encoding raising an exception over the bridge
Brought to you by:
ronaldoussoren
From: Bob I. <bo...@re...> - 2003-11-22 06:08:34
|
On Nov 22, 2003, at 12:08 AM, Ronald Oussoren wrote: > > On 22 nov 2003, at 4:51, Bob Ippolito wrote: > >> I think that most of the time, people would be happier if this didn't >> raise an exception (use the unicode replace instead). If the python >> user doesn't know the encoding of the text, and it's not default >> encoding, the developer probably doesn't have anything better than >> replace to use on the string. The exception is a nuisance and can be >> hard to track down. >> >> Perhaps this could be a module level variable in objc, so that a >> person could toggle it to be strict if they wanted it that way, but >> have the default as replace? >> >> -bob > > We already have such a variable, it is called defaultencoding and can > be set using sys.setdefaultencoding(). only at the "sitecustomize" phase.. you can't change this later. I don't really care to change the encoding, just what happens if it can't encode. > This is not exactly what you ask, but IMHO better than what you > propose ("Errors should never pass silently."). > > BTW. You should convert all input to unicode instead of waiting for > problems with the implicit conversion to unicode that is performed by > PyObjC. You're more likely to know the right encoding while reading > the data. But what's better, seeing unicode replace characters in your app or trying to track down a strange exception? If the behavior stays the same, maybe it should give you a hint as to what character sequence gave you the error. -bob |