@@ -38,10 +38,7 @@ def generate_example_rst(app):
3838 continue
3939
4040 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 ()
4542 # indent
4643 relpath = os .path .split (root )[- 1 ]
4744 datad .setdefault (relpath , []).append ((fullpath , fname , contents ))
@@ -126,34 +123,31 @@ def generate_example_rst(app):
126123 ) and
127124 not noplot_regex .search (contents ))
128125 if not do_plot :
129- fhstatic = open (outputfile , 'w' )
126+ fhstatic = io . open (outputfile , 'w' , encoding = 'utf-8 ' )
130127 fhstatic .write (contents )
131128 fhstatic .close ()
132129
133130 if not out_of_date (fullpath , outrstfile ):
134131 continue
135132
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 ))
141135 title = '%s example code: %s' % (subdir , fname )
142136 #title = '<img src=%s> %s example code: %s'%(thumbfile, subdir, fname)
143137
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 ' )
146140
147141 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 )
149143 else :
150- fh .write ("[`source code <%s>`_]\n \n ::\n \n " % fname )
144+ fh .write (u "[`source code <%s>`_]\n \n ::\n \n " % fname )
151145
152146 # 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 ' )])
154148 fh .write (contents )
155149
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`)' )
157151 fh .close ()
158152
159153 fhsubdirIndex .close ()
0 commit comments