Re: Is this the right way to write a codec error handler?

2018-01-20 Thread Steven D'Aprano
On Sat, 20 Jan 2018 12:57:45 +0200, Serhiy Storchaka wrote: > Just `end` instead of `end+1`. Oops! > And it is safer to use `bytes.decode(obj[start:end], 'latin1')` or > `str(obj[start:end], 'latin1')` instead of > `obj[start:end].decode('latin1')`. Just for the case if obj has > overridden

Re: Is this the right way to write a codec error handler?

2018-01-20 Thread Serhiy Storchaka
20.01.18 10:32, Steven D'Aprano пише: I want an error handler that falls back on Latin-1 for anything which cannot be decoded. Is this the right way to write it? def latin1_fallback(exception): assert isinstance(exception, UnicodeError) start, end = exception.start, exception.end

Is this the right way to write a codec error handler?

2018-01-20 Thread Steven D'Aprano
I want an error handler that falls back on Latin-1 for anything which cannot be decoded. Is this the right way to write it? def latin1_fallback(exception): assert isinstance(exception, UnicodeError) start, end = exception.start, exception.end obj = exception.object if