Skip to content

Commit 9a8ed26

Browse files
committed
Merge pull request #7436 from Kojoley/fix-doc-gallery-cache-unicode-error
DOC: Fixed Unicode error in gallery template cache
1 parent 46c0ead commit 9a8ed26

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

doc/sphinxext/gen_gallery.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: UTF-8 -*-
2+
import codecs
23
import os
34
import re
45
import glob
@@ -143,16 +144,14 @@ def gen_gallery(app, doctree):
143144
gallery_path = os.path.join(app.builder.srcdir,
144145
'_templates', 'gallery.html')
145146
if os.path.exists(gallery_path):
146-
fh = open(gallery_path, 'r')
147-
regenerate = fh.read() != content
148-
fh.close()
147+
with codecs.open(gallery_path, 'r', encoding='utf-8') as fh:
148+
regenerate = fh.read() != content
149149
else:
150150
regenerate = True
151151

152152
if regenerate:
153-
fh = open(gallery_path, 'w')
154-
fh.write(content)
155-
fh.close()
153+
with codecs.open(gallery_path, 'w', encoding='utf-8') as fh:
154+
fh.write(content)
156155

157156
for key in app.builder.status_iterator(
158157
iter(thumbnails.keys()), "generating thumbnails... ",

0 commit comments

Comments
 (0)