@@ -38,10 +38,7 @@ def generate_example_rst(app):
38
38
continue
39
39
40
40
fullpath = os .path .join (root ,fname )
41
- if sys .version_info [0 ] >= 3 :
42
- contents = io .open (fullpath , encoding = 'utf8' ).read ()
43
- else :
44
- contents = io .open (fullpath ).read ()
41
+ contents = io .open (fullpath , encoding = 'utf8' ).read ()
45
42
# indent
46
43
relpath = os .path .split (root )[- 1 ]
47
44
datad .setdefault (relpath , []).append ((fullpath , fname , contents ))
@@ -126,34 +123,31 @@ def generate_example_rst(app):
126
123
) and
127
124
not noplot_regex .search (contents ))
128
125
if not do_plot :
129
- fhstatic = open (outputfile , 'w' )
126
+ fhstatic = io . open (outputfile , 'w' , encoding = 'utf-8 ' )
130
127
fhstatic .write (contents )
131
128
fhstatic .close ()
132
129
133
130
if not out_of_date (fullpath , outrstfile ):
134
131
continue
135
132
136
- if sys .version_info [0 ] >= 3 :
137
- fh = io .open (outrstfile , 'w' , encoding = 'utf8' )
138
- else :
139
- fh = io .open (outrstfile , 'w' )
140
- fh .write ('.. _%s-%s:\n \n ' % (subdir , basename ))
133
+ fh = io .open (outrstfile , 'w' , encoding = 'utf-8' )
134
+ fh .write (u'.. _%s-%s:\n \n ' % (subdir , basename ))
141
135
title = '%s example code: %s' % (subdir , fname )
142
136
#title = '<img src=%s> %s example code: %s'%(thumbfile, subdir, fname)
143
137
144
- fh .write (title + '\n ' )
145
- fh .write ('=' * len (title ) + '\n \n ' )
138
+ fh .write (title + u '\n ' )
139
+ fh .write (u '=' * len (title ) + u '\n \n ' )
146
140
147
141
if do_plot :
148
- fh .write ("\n \n .. plot:: %s\n \n ::\n \n " % fullpath )
142
+ fh .write (u "\n \n .. plot:: %s\n \n ::\n \n " % fullpath )
149
143
else :
150
- fh .write ("[`source code <%s>`_]\n \n ::\n \n " % fname )
144
+ fh .write (u "[`source code <%s>`_]\n \n ::\n \n " % fname )
151
145
152
146
# indent the contents
153
- contents = '\n ' .join ([' %s' % row .rstrip () for row in contents .split ('\n ' )])
147
+ contents = u '\n ' .join ([u ' %s'% row .rstrip () for row in contents .split (u '\n ' )])
154
148
fh .write (contents )
155
149
156
- fh .write ('\n \n Keywords: python, matplotlib, pylab, example, codex (see :ref:`how-to-search-examples`)' )
150
+ fh .write (u '\n \n Keywords: python, matplotlib, pylab, example, codex (see :ref:`how-to-search-examples`)' )
157
151
fh .close ()
158
152
159
153
fhsubdirIndex .close ()
0 commit comments