Skip to content

Commit 196636f

Browse files
committed
Fix py2/3 unicode differences
1 parent 222e742 commit 196636f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

doc/sphinxext/gen_rst.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ def generate_example_rst(app):
3838
continue
3939

4040
fullpath = os.path.join(root,fname)
41-
contents = io.open(fullpath, encoding='utf8').read()
41+
if sys.version_info[0] >= 3:
42+
contents = io.open(fullpath, encoding='utf8').read()
43+
else:
44+
contents = io.open(fullpath).read()
4245
# indent
4346
relpath = os.path.split(root)[-1]
4447
datad.setdefault(relpath, []).append((fullpath, fname, contents))
@@ -130,7 +133,10 @@ def generate_example_rst(app):
130133
if not out_of_date(fullpath, outrstfile):
131134
continue
132135

133-
fh = io.open(outrstfile, 'w', encoding='utf8')
136+
if sys.version_info[0] >= 3:
137+
fh = io.open(outrstfile, 'w', encoding='utf8')
138+
else:
139+
fh = io.open(outrstfile, 'w')
134140
fh.write('.. _%s-%s:\n\n'%(subdir, basename))
135141
title = '%s example code: %s'%(subdir, fname)
136142
#title = '<img src=%s> %s example code: %s'%(thumbfile, subdir, fname)

0 commit comments

Comments
 (0)