Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix some possible encoding issues for non-utf8 systems. #23022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions doc/sphinxext/redirect_from.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
This creates in the build directory a file ``build/html/topic/old-page.html``
that contains a relative refresh::

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The meta tag should be in the head tag, not top-level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oopsie. I don't claim any understanding of the html standard; do you know the correct syntax to make this interact with the other meta tag?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're independent, it just needs to be moved down, but also could be charset instead of a content-type: #23030

<html>
<head>
<meta http-equiv="refresh" content="0; url=new-page.html">
Expand All @@ -38,7 +39,9 @@
logger = logging.getLogger(__name__)


HTML_TEMPLATE = """<html>
HTML_TEMPLATE = """\
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<html>
<head>
<meta http-equiv="refresh" content="0; url={v}">
</head>
Expand Down Expand Up @@ -115,4 +118,4 @@ def _generate_redirects(app, exception):
else:
logger.info(f'making refresh html file: {k} redirect to {v}')
p.parent.mkdir(parents=True, exist_ok=True)
p.write_text(html)
p.write_text(html, encoding='utf-8')
2 changes: 1 addition & 1 deletion lib/matplotlib/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _check_for_pgf(texsystem):
\typeout{pgfversion=\pgfversion}
\makeatletter
\@@end
""")
""", encoding="utf-8")
try:
subprocess.check_call(
[texsystem, "-halt-on-error", str(tex_path)], cwd=tmpdir,
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/tests/test_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,8 @@ def test_failing_ffmpeg(tmpdir, monkeypatch, anim):
with tmpdir.as_cwd():
monkeypatch.setenv("PATH", ".:" + os.environ["PATH"])
exe_path = Path(str(tmpdir), "ffmpeg")
exe_path.write_text("#!/bin/sh\n"
"[[ $@ -eq 0 ]]\n")
os.chmod(str(exe_path), 0o755)
exe_path.write_bytes(b"#!/bin/sh\n[[ $@ -eq 0 ]]\n")
os.chmod(exe_path, 0o755)
with pytest.raises(subprocess.CalledProcessError):
anim.save("test.mpeg")

Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/tests/test_sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def plot_directive_file(num):
assert filecmp.cmp(range_6, plot_file(17))

# Modify the included plot
contents = (source_dir / 'included_plot_21.rst').read_text()
contents = contents.replace('plt.plot(range(6))', 'plt.plot(range(4))')
(source_dir / 'included_plot_21.rst').write_text(contents)
contents = (source_dir / 'included_plot_21.rst').read_bytes()
contents = contents.replace(b'plt.plot(range(6))', b'plt.plot(range(4))')
(source_dir / 'included_plot_21.rst').write_bytes(contents)
# Build the pages again and check that the modified file was updated
modification_times = [plot_directive_file(i).stat().st_mtime
for i in (1, 2, 3, 5)]
Expand Down
5 changes: 3 additions & 2 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ def do_custom_build(self, env):
sln_path = base_path / vc / "freetype.sln"
# https://developercommunity.visualstudio.com/comments/190992/view.html
(sln_path.parent / "Directory.Build.props").write_text(
"<?xml version='1.0' encoding='utf-8'?>"
"<Project>"
"<PropertyGroup>"
# WindowsTargetPlatformVersion must be given on a single line.
Expand All @@ -676,8 +677,8 @@ def do_custom_build(self, env):
"::GetLatestSDKTargetPlatformVersion('Windows', '10.0')"
")</WindowsTargetPlatformVersion>"
"</PropertyGroup>"
"</Project>"
)
"</Project>",
encoding="utf-8")
# It is not a trivial task to determine PlatformToolset to plug it
# into msbuild command, and Directory.Build.props will not override
# the value in the project file.
Expand Down
6 changes: 4 additions & 2 deletions tools/run_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
from tempfile import TemporaryDirectory
import time
import tokenize


_preamble = """\
Expand Down Expand Up @@ -73,8 +74,9 @@ def main():
cwd.mkdir(parents=True)
else:
cwd = stack.enter_context(TemporaryDirectory())
Path(cwd, relpath.name).write_text(
_preamble + (root / relpath).read_text())
with tokenize.open(root / relpath) as src:
Path(cwd, relpath.name).write_text(
_preamble + src.read(), encoding="utf-8")
for backend in args.backend or [None]:
env = {**os.environ}
if backend is not None:
Expand Down