Revision: 4289
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4289&view=rev
Author: mdboom
Date: 2007-11-14 11:25:46 -0800 (Wed, 14 Nov 2007)
Log Message:
-----------
Refactored a bunch of places to use "is_writable_file_like".
Modified Paths:
--------------
trunk/matplotlib/API_CHANGES
trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py
trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
trunk/matplotlib/lib/matplotlib/backends/backend_svg.py
trunk/matplotlib/lib/matplotlib/backends/backend_wx.py
trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/API_CHANGES
===================================================================
--- trunk/matplotlib/API_CHANGES 2007-11-14 19:11:54 UTC (rev 4288)
+++ trunk/matplotlib/API_CHANGES 2007-11-14 19:25:46 UTC (rev 4289)
@@ -1,4 +1,5 @@
- removed cbook.is_file_like, which appears to be broken and unused.
+ Changed cbook.is_file_like to cbook.is_writable_file_like and
+ corrected behavior.
Added ax kwarg to pyplot.colorbar and Figure.colorbar so that
one can specify the axes object from which space for the colorbar
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py 2007-11-14
19:11:54 UTC (rev 4288)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py 2007-11-14
19:25:46 UTC (rev 4289)
@@ -19,7 +19,7 @@
from matplotlib.backend_bases import RendererBase, GraphicsContextBase, \
FigureManagerBase, FigureCanvasBase, NavigationToolbar2, cursors
from matplotlib.backends.backend_gdk import RendererGDK, FigureCanvasGDK
-from matplotlib.cbook import is_string_like, enumerate
+from matplotlib.cbook import is_string_like, is_writable_file_like, enumerate
from matplotlib.colors import colorConverter
from matplotlib.figure import Figure
from matplotlib.widgets import SubplotTool
@@ -370,7 +370,7 @@
pixbuf.save(filename, format)
except gobject.GError, exc:
error_msg_gtk('Save figure failure:\n%s' % (exc,), parent=self)
- elif hasattr(filename, 'write') and callable(filename.write):
+ elif is_writable_file_like(filename):
if hasattr(pixbuf, 'save_to_callback'):
def save_callback(buf, data=None):
data.write(buf)
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2007-11-14
19:11:54 UTC (rev 4288)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2007-11-14
19:25:46 UTC (rev 4289)
@@ -24,7 +24,8 @@
from matplotlib._pylab_helpers import Gcf
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
FigureManagerBase, FigureCanvasBase
-from matplotlib.cbook import Bunch, enumerate, is_string_like, reverse_dict,
get_realpath_and_stat
+from matplotlib.cbook import Bunch, enumerate, is_string_like, reverse_dict, \
+ get_realpath_and_stat, is_writable_file_like
from matplotlib.figure import Figure
from matplotlib.font_manager import findfont, is_opentype_cff_font
from matplotlib.afm import AFM
@@ -328,7 +329,7 @@
self.passed_in_file_object = False
if is_string_like(filename):
fh = file(filename, 'wb')
- elif hasattr(filename, 'write') and callable(filename.write):
+ elif is_writable_file_like(filename):
fh = filename
self.passed_in_file_object = True
else:
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2007-11-14
19:11:54 UTC (rev 4288)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2007-11-14
19:25:46 UTC (rev 4289)
@@ -15,7 +15,8 @@
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
FigureManagerBase, FigureCanvasBase
-from matplotlib.cbook import is_string_like, izip, get_realpath_and_stat
+from matplotlib.cbook import is_string_like, izip, get_realpath_and_stat, \
+ is_writable_file_like
from matplotlib.figure import Figure
from matplotlib.font_manager import findfont, is_opentype_cff_font
@@ -1051,7 +1052,7 @@
if is_string_like(outfile):
title = outfile
tmpfile = os.path.join(gettempdir(), md5.md5(outfile).hexdigest())
- elif hasattr(outfile, 'write') and callable(outfile.write):
+ elif is_writable_file_like(outfile):
title = None
tmpfile = os.path.join(gettempdir(),
md5.md5(str(hash(outfile))).hexdigest())
passed_in_file_object = True
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_svg.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2007-11-14
19:11:54 UTC (rev 4288)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2007-11-14
19:25:46 UTC (rev 4289)
@@ -5,7 +5,7 @@
from matplotlib import verbose, __version__, rcParams
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
FigureManagerBase, FigureCanvasBase
-from matplotlib.cbook import is_string_like
+from matplotlib.cbook import is_string_like, is_writable_file_like
from matplotlib.colors import rgb2hex
from matplotlib.figure import Figure
from matplotlib.font_manager import findfont, FontProperties
@@ -461,7 +461,7 @@
def print_svg(self, filename, *args, **kwargs):
if is_string_like(filename):
fh_to_close = svgwriter = codecs.open(filename, 'w', 'utf-8')
- elif hasattr(filename, 'write') and callable(filename.write):
+ elif is_writable_file_like(filename):
svgwriter = codecs.EncodedFile(filename, 'utf-8')
fh_to_close = None
else:
@@ -472,7 +472,7 @@
if is_string_like(filename):
gzipwriter = gzip.GzipFile(filename, 'w')
fh_to_close = svgwriter = codecs.EncodedFile(gzipwriter, 'utf-8')
- elif hasattr(filename, 'write') and callable(filename.write):
+ elif is_writable_file_like(filename):
fh_to_close = gzipwriter = gzip.GzipFile(fileobj=filename,
mode='w')
svgwriter = codecs.EncodedFile(gzipwriter, 'utf-8')
else:
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_wx.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_wx.py 2007-11-14
19:11:54 UTC (rev 4288)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_wx.py 2007-11-14
19:25:46 UTC (rev 4289)
@@ -152,7 +152,7 @@
cursors
from matplotlib._pylab_helpers import Gcf
from matplotlib.artist import Artist
-from matplotlib.cbook import exception_to_str, is_string_like
+from matplotlib.cbook import exception_to_str, is_string_like,
is_writable_file_like
from matplotlib.figure import Figure
from matplotlib.text import _process_text_args, Text
from matplotlib.widgets import SubplotTool
@@ -1042,7 +1042,7 @@
# the error on a call or print_figure may not work because
# printing can be qued and called from realize
raise RuntimeError('Could not save figure to %s\n' %
(filename))
- elif hasattr(filename, 'write') and callable(filename.write):
+ elif is_writable_file_like(filename):
if not self.bitmap.ConvertToImage().SaveStream(filename, filetype):
DEBUG_MSG('print_figure() file save error', 4, self)
raise RuntimeError('Could not save figure to %s\n' %
(filename))
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py 2007-11-14 19:11:54 UTC (rev
4288)
+++ trunk/matplotlib/lib/matplotlib/cbook.py 2007-11-14 19:25:46 UTC (rev
4289)
@@ -213,6 +213,9 @@
except (TypeError, ValueError): return 0
return 1
+def is_writable_file_like(obj):
+ return hasattr(filename, 'write') and callable(filename.write)
+
def is_scalar(obj):
return is_string_like(obj) or not iterable(obj)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins