Fix pep2rss to specify output encoding #634
Conversation
| @@ -69,5 +69,5 @@ def pep_creation_dt(full_path): | |||
| lastBuildDate = datetime.datetime.now(), | |||
| items = items) | |||
|
|
|||
| with open(RSS_PATH, 'w') as fp: | |||
| with open(RSS_PATH, 'w', encoding="utf-8") as fp: | |||
zware
Apr 27, 2018
Member
This looks dangerous; if it's run on Python 2 (which is quite possible; the shebang is /usr/bin/env python), this will fail. We should do from io import open at the top.
This looks dangerous; if it's run on Python 2 (which is quite possible; the shebang is /usr/bin/env python), this will fail. We should do from io import open at the top.
Harmon758
Apr 27, 2018
Author
Contributor
Ah, I overlooked this.
I've gone ahead and changed it to codecs.open for consistency and because rss.to_xml() returns str and not unicode (which would have to be converted to not raise a TypeError in Python 2 when using fp.write with io.open).
This does cause line endings to output as '\n' instead of the platform-specific representation, but since line endings are supposed to be normalized to '\n' when processing XML anyway, I don't think this is of significance.
Ah, I overlooked this.
I've gone ahead and changed it to codecs.open for consistency and because rss.to_xml() returns str and not unicode (which would have to be converted to not raise a TypeError in Python 2 when using fp.write with io.open).
This does cause line endings to output as '\n' instead of the platform-specific representation, but since line endings are supposed to be normalized to '\n' when processing XML anyway, I don't think this is of significance.
|
Perhaps this is a separate issue, but I've noticed that the RSS feed generated specifies "iso-8859-1" as the encoding in the XML declaration. However, changing Line 75 in 499a7c2 to fp.write(rss.to_xml(encoding="utf-8"))results in
in Python 2. This can be fixed by manually converting to fp.write(unicode(rss.to_xml(encoding="utf-8"), "utf-8"))but I'm not sure of the best way to make this compatible with Python 3, beyond manually checking |
|
Does it even need to support Python 2? |
|
Changing the shebang would be simpler :) |
|
But wouldn't help on systems lacking Python 3 support, whose users might be
disappointed to see this project end-of-life before the end of next year ...
Steve Holden
…On Fri, Apr 27, 2018 at 9:30 PM, Zachary Ware ***@***.***> wrote:
Changing the shebang would be simpler :)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#634 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAGbYKBz7QVKwbu_3KiYCuVEj2yYfF83ks5ts3_ogaJpZM4TpqM3>
.
|
|
@holdenweb who is being disappointed from not generating the RSS feed for the PEPs using Python 2? I'm with @zware and the shebang should simply be changed and we should just rely on Python 3. |
|
Sorry, brainfart, continue to ignore me.
Steve Holden
…On Mon, Apr 30, 2018 at 8:07 PM, Brett Cannon ***@***.***> wrote:
@holdenweb <https://github.com/holdenweb> who is being disappointed from
not generating the RSS feed for the PEPs using Python 2?
I'm with @zware <https://github.com/zware> and the shebang should simply
be changed and we should just rely on Python 3.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#634 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAGbYEjttqLQkZ7s1yR7r9gI9jvwqQ_5ks5tt2DrgaJpZM4TpqM3>
.
|
|
This seems stalled -- who is waiting for whom here? |
|
@gvanrossum I think @zware and I are waiting for the PR to be updated to update the shebang and use Python 3 instead of trying to support Python 2. |
|
Ah, ok, since there don't seem to be any objections, I'll go ahead and drop Python 2 support. |
|
Thanks, @Harmon758! |


Fixes #633