Revision: 7973
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7973&view=rev
Author:   mdboom
Date:     2009-11-18 16:30:16 +0000 (Wed, 18 Nov 2009)

Log Message:
-----------
Fix plot directive so it handles source files in various encodings.

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py

Modified: trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py 2009-11-18 
16:19:21 UTC (rev 7972)
+++ trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py 2009-11-18 
16:30:16 UTC (rev 7973)
@@ -38,7 +38,9 @@
 
 Additionally, if the `:include-source:` option is provided, the
 literal source will be displayed inline in the text, (as well as a
-link to the source in HTML).
+link to the source in HTML).  If this source file is in a non-UTF8 or
+non-ASCII encoding, the encoding must be specified using the
+`:encoding:` option.
 
 The set of file formats to generate can be specified with the
 `plot_formats` configuration variable.
@@ -331,14 +333,21 @@
     # Now start generating the lines of output
     lines = []
 
+    if plot_code is None:
+        shutil.copyfile(plot_path, os.path.join(destdir, fname))
+
     if options.has_key('include-source'):
         if plot_code is None:
-            fd = open(plot_path, 'r')
-            plot_code = fd.read()
-            fd.close()
-        lines.extend(['::', ''])
-        lines.extend(['    %s' % row.rstrip()
-                      for row in plot_code.split('\n')])
+            lines.extend(
+                ['.. include:: %s' % os.path.join(setup.app.builder.srcdir, 
plot_path),
+                 '    :literal:'])
+            if options.has_key('encoding'):
+                lines.append('    :encoding: %s' % options['encoding'])
+                del options['encoding']
+        else:
+            lines.extend(['::', ''])
+            lines.extend(['    %s' % row.rstrip()
+                          for row in plot_code.split('\n')])
         lines.append('')
         del options['include-source']
     else:
@@ -348,8 +357,6 @@
         options = ['%s:%s: %s' % (template_content_indent, key, val)
                    for key, val in options.items()]
         options = "\n".join(options)
-        if plot_code is None:
-            shutil.copyfile(plot_path, os.path.join(destdir, fname))
 
         for i in range(num_figs):
             if num_figs == 1:
@@ -425,7 +432,8 @@
                'scale': directives.nonnegative_int,
                'align': align,
                'class': directives.class_option,
-               'include-source': directives.flag }
+               'include-source': directives.flag,
+               'encoding': directives.encoding }
 
     app.add_directive('plot', plot_directive, True, (0, 2, 0), **options)
     app.add_config_value(


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to