News for hackers. Stuff that matters.
Re:Mercurial’s journey to and reflections on Python 3 by xorcist on Monday January 13, 2020 @05:35PM (#22039502)
But that's not what frustrates people with the transition. It's that they suddenly get encoding issues where there should have been no encoding to begin with!
Re:Mercurial’s journey to and reflections on Python 3 by cbsmith on Monday January 13, 2020 @06:02PM (#22039731)
No observed encoding issues.
Re:Mercurial’s journey to and reflections on Python 3 by CJefferson on Monday January 13, 2020 @06:55PM (#22040166)
When I treated headers as bytes, there wasn't an "encoding".

What I often want to do when reading user data is not treat it as a "encoded string", but just as a stream of bytes. Most data I work with (HTML files, output of other programs) can't be treated as anything but bytes, because people put junk in files / output of programs.

Re:Mercurial’s journey to and reflections on Python 3 by cbsmith on Monday January 13, 2020 @07:12PM (#22040308)
> When I treated headers as bytes, there wasn't an "encoding".

If you are representing strings as bytes, you are intrinsically using an encoding.

> What I often want to do when reading user data is not treat it as a "encoded string", but just as a stream of bytes. Most data I work with (HTML files, output of other programs) can't be treated as anything but bytes, because people put junk in files / output of programs.

Yes, it makes a mockery of the notion that "human readable data is easy". In many cases, you don't want to work with the actual strings in the data anyway, so bytes is the right thing to do.

But yes, this strategy largely avoids encoding issues... until it doesn't.

Re:Mercurial’s journey to and reflections on Python 3 by Dylan16807 on Tuesday January 14, 2020 @03:22AM (#22042861)
> If you are representing strings as bytes, you are intrinsically using an encoding.

It's just binary data that might resemble a string. No encoding necessary.

Re:Mercurial’s journey to and reflections on Python 3 by fiedzia on Tuesday January 14, 2020 @06:07AM (#22043692)
This is false more often than not. Many programs taking user input will treat it as string, assuming specific encoding or compatibility with screen output/some api, at least in some code paths. For example if you print an error message when you can't open some file, you are very likely to assume its encoded in a way terminal can handle, so its no longer "just binary data".
Re:Mercurial’s journey to and reflections on Python 3 by CJefferson on Tuesday January 14, 2020 @05:40PM (#22049988)
Yes, I have to worry about how to make a "best effort" to show it to users, but in all internal code paths it must stay as "just binary data", else I lose information. This is exactly how chrome and Firefox handle headers internally.
Re:Mercurial’s journey to and reflections on Python 3 by cbsmith on Wednesday January 15, 2020 @12:57PM (#22056518)
It might resemble a particular encoding of a string... and the way you got that string to that particular sequence of bytes is by... encoding it.
Re:Mercurial’s journey to and reflections on Python 3 by Dylan16807 on Wednesday January 15, 2020 @06:11PM (#22059855)
> and the way you got that string to that particular sequence of bytes

No I didn't. Those bytes came from an external source. My primary job is to preserve the exact sequence, whether I can make sense of it or not.

Re:Mercurial’s journey to and reflections on Python 3 by cbsmith on Thursday January 16, 2020 @03:52AM (#22062748)
In that context, you aren't using strings. You are using bytes. HTML without interpreting it as strings isn't really HTML, nor is it a string. It's just a blob that is passing through.
Re:Mercurial’s journey to and reflections on Python 3 by takeda on Tuesday January 14, 2020 @12:51PM (#22047248)
> When I treated headers as bytes, there wasn't an "encoding".

oh, actually there was (either us-ascii or more likely iso-8859-1) the bytes are just values 0-255 what these values mean is the encoding. You're confused because the encoding was implicit, rather than explicit.

It would perhaps be clearer to see it if you for example had to chose if you use ASCII or legacy EBCDIC encoding.