Thread: [Pyobjc-dev] non-default encoding raising an exception over the bridge
Brought to you by:
ronaldoussoren
From: Bob I. <bo...@re...> - 2003-11-22 03:51:15
Attachments:
smime.p7s
|
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 |
From: Ronald O. <ous...@ci...> - 2003-11-22 05:08:05
|
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(). 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. Ronald |
From: Bob I. <bo...@re...> - 2003-11-22 06:08:34
Attachments:
smime.p7s
|
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 |
From: Just v. R. <ju...@le...> - 2003-11-22 10:49:31
|
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? Strongly disagree. This leads to silent errors, possibly even data loss. You _have_ to know the encoding, and you _have_ to deal with it. If there's no way you can know the encoding, you have to explicitly tell which encoding or behavior to use. Btw. it's not so much PyObjC's behavior, but Python's default str -> unicode coercion behavior. Perhaps it's "fixable" in the bridge, but I think it's a bad idea to deviate from Python's behavior (in addition to that I find it a bad idea to begin with). Just |
From: Michael H. <mw...@py...> - 2003-11-24 11:47:07
|
Just van Rossum <ju...@le...> writes: > 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? > > Strongly disagree. This leads to silent errors, possibly even data loss. > You _have_ to know the encoding, and you _have_ to deal with it. If > there's no way you can know the encoding, you have to explicitly tell > which encoding or behavior to use. Amen. Cheers, mwh -- When physicists speak of a TOE, they don't really mean a theory of *everything*. Taken literally, "Everything" covers a lot of ground, including biology, art, decoherence and the best way to barbecue ribs. -- John Baez, sci.physics.research |