SourceForge logo
SourceForge logo
Menu

matplotlib-checkins

From: <dmk...@us...> - 2008年07月18日 18:59:59
Revision: 5789
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5789&view=rev
Author: dmkaplan
Date: 2008年07月18日 18:59:57 +0000 (2008年7月18日)
Log Message:
-----------
Fixing bug in is_sequence_of_strings.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2008年07月18日 14:49:09 UTC (rev 5788)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2008年07月18日 18:59:57 UTC (rev 5789)
@@ -275,6 +275,7 @@
 Returns true if *obj* is iterable and contains strings
 """
 if not iterable(obj): return False
+ if is_string_like(obj): return False
 for o in obj:
 if not is_string_like(o): return False
 return True
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <ef...@us...> - 2008年07月22日 18:00:51
Revision: 5810
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5810&view=rev
Author: efiring
Date: 2008年07月22日 18:00:49 +0000 (2008年7月22日)
Log Message:
-----------
Cleanup in delete_masked_points
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2008年07月22日 11:23:49 UTC (rev 5809)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2008年07月22日 18:00:49 UTC (rev 5810)
@@ -1187,7 +1187,7 @@
 Masks are obtained from all arguments of the correct length
 in categories 1, 2, and 4; a point is bad if masked in a masked
 array or if it is a nan or inf. No attempt is made to
- extract a mask from categories 2, 3, and 4 if *np.isfinite()*
+ extract a mask from categories 2, 3, and 4 if :meth:`np.isfinite`
 does not yield a Boolean array.
 
 All input arguments that are not passed unchanged are returned
@@ -1236,11 +1236,7 @@
 if len(igood) < nrecs:
 for i, x in enumerate(margs):
 if seqlist[i]:
- if (hasattr(x, 'get_compressed_copy')):
- compressed_x = x.get_compressed_copy(~mask)
- else:
- compressed_x = x.take(igood, axis=0)
- margs[i] = compressed_x
+ margs[i] = x.take(igood, axis=0)
 for i, x in enumerate(margs):
 if seqlist[i] and ma.isMA(x):
 margs[i] = x.filled()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <ef...@us...> - 2008年07月22日 18:05:35
Revision: 5811
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5811&view=rev
Author: efiring
Date: 2008年07月22日 18:05:32 +0000 (2008年7月22日)
Log Message:
-----------
Add deprecation warning to cbook.popd
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2008年07月22日 18:00:49 UTC (rev 5810)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2008年07月22日 18:05:32 UTC (rev 5811)
@@ -743,6 +743,8 @@
 val = popd(d, key, default)
 
 """
+ warnings.warn("Use native python dict.pop method", DeprecationWarning)
+ # warning added 2008年07月22日
 if len(args)==1:
 key = args[0]
 val = d[key]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <ef...@us...> - 2008年07月22日 18:43:43
Revision: 5812
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5812&view=rev
Author: efiring
Date: 2008年07月22日 18:43:38 +0000 (2008年7月22日)
Log Message:
-----------
Moved unmasked_index_ranges from lines.py to cbook.py
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2008年07月22日 18:05:32 UTC (rev 5811)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2008年07月22日 18:43:38 UTC (rev 5812)
@@ -1244,7 +1244,57 @@
 margs[i] = x.filled()
 return margs
 
+def unmasked_index_ranges(mask, compressed = True):
+ '''
+ Find index ranges where *mask* is *False*.
 
+ *mask* will be flattened if it is not already 1-D.
+
+ Returns Nx2 :class:`numpy.ndarray` with each row the start and stop
+ indices for slices of the compressed :class:`numpy.ndarray`
+ corresponding to each of *N* uninterrupted runs of unmasked
+ values. If optional argument *compressed* is *False*, it returns
+ the start and stop indices into the original :class:`numpy.ndarray`,
+ not the compressed :class:`numpy.ndarray`. Returns *None* if there
+ are no unmasked values.
+
+ Example::
+
+ y = ma.array(np.arange(5), mask = [0,0,1,0,0])
+ ii = unmasked_index_ranges(ma.getmaskarray(y))
+ # returns array [[0,2,] [2,4,]]
+
+ y.compressed()[ii[1,0]:ii[1,1]]
+ # returns array [3,4,]
+
+ ii = unmasked_index_ranges(ma.getmaskarray(y), compressed=False)
+ # returns array [[0, 2], [3, 5]]
+
+ y.filled()[ii[1,0]:ii[1,1]]
+ # returns array [3,4,]
+
+ Prior to the transforms refactoring, this was used to support
+ masked arrays in Line2D.
+
+ '''
+ mask = mask.reshape(mask.size)
+ m = np.concatenate(((1,), mask, (1,)))
+ indices = np.arange(len(mask) + 1)
+ mdif = m[1:] - m[:-1]
+ i0 = np.compress(mdif == -1, indices)
+ i1 = np.compress(mdif == 1, indices)
+ assert len(i0) == len(i1)
+ if len(i1) == 0:
+ return None # Maybe this should be np.zeros((0,2), dtype=int)
+ if not compressed:
+ return np.concatenate((i0[:, np.newaxis], i1[:, np.newaxis]), axis=1)
+ seglengths = i1 - i0
+ breakpoints = np.cumsum(seglengths)
+ ic0 = np.concatenate(((0,), breakpoints[:-1]))
+ ic1 = breakpoints
+ return np.concatenate((ic0[:, np.newaxis], ic1[:, np.newaxis]), axis=1)
+
+
 # a dict to cross-map linestyle arguments
 _linestyles = [('-', 'solid'),
 ('--', 'dashed'),
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <jd...@us...> - 2008年07月23日 13:16:30
Revision: 5822
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5822&view=rev
Author: jdh2358
Date: 2008年07月23日 13:16:28 +0000 (2008年7月23日)
Log Message:
-----------
fixed is_scalar -- good catch david
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2008年07月23日 12:34:26 UTC (rev 5821)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2008年07月23日 13:16:28 UTC (rev 5822)
@@ -287,7 +287,7 @@
 
 def is_scalar(obj):
 'return true if *obj* is not string like and is not iterable'
- return is_string_like(obj) or not iterable(obj)
+ return not is_string_like(obj) or not iterable(obj)
 
 def is_numlike(obj):
 'return true if *obj* looks like a number'
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <dmk...@us...> - 2008年07月23日 14:18:45
Revision: 5824
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5824&view=rev
Author: dmkaplan
Date: 2008年07月23日 14:18:41 +0000 (2008年7月23日)
Log Message:
-----------
Fix to is_scalar plus additional functions in cbook.py:
less_simple_linear_interpolation
isvector
vector_lengths
distances_along_curve
path_length
is_closed_polygon
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2008年07月23日 13:28:32 UTC (rev 5823)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2008年07月23日 14:18:41 UTC (rev 5824)
@@ -287,7 +287,7 @@
 
 def is_scalar(obj):
 'return true if *obj* is not string like and is not iterable'
- return not is_string_like(obj) or not iterable(obj)
+ return not is_string_like(obj) and not iterable(obj)
 
 def is_numlike(obj):
 'return true if *obj* looks like a number'
@@ -1156,6 +1156,46 @@
 
 return result
 
+def less_simple_linear_interpolation( x, y, xi, extrap=False ):
+ """
+ This function provides simple (but somewhat less so than
+ simple_linear_interpolation) linear interpolation. This is very
+ inefficient linear interpolation meant to be used only for a small
+ number of points in relatively non-intensive use cases.
+
+ Call signature::
+
+ yi = less_simple_linear_interpolation(x,y,xi)
+ """
+ if is_scalar(xi): xi = [xi]
+
+ x = np.asarray(x)
+ y = np.asarray(y)
+ xi = np.asarray(xi)
+
+ s = list(y.shape)
+ s[0] = len(xi)
+ yi = np.tile( np.nan, s )
+
+ for ii,xx in enumerate(xi):
+ bb = x == xx
+ if np.any(bb):
+ jj, = np.nonzero(bb)
+ yi[ii] = y[jj[0]]
+ elif xx<x[0]:
+ if extrap:
+ yi[ii] = y[0]
+ elif xx>x[-1]:
+ if extrap:
+ yi[ii] = y[-1]
+ else:
+ jj, = np.nonzero(x<xx)
+ jj = max(jj)
+
+ yi[ii] = y[jj] + (xx-x[jj])/(x[jj+1]-x[jj]) * (y[jj+1]-y[jj])
+
+ return yi
+
 def recursive_remove(path):
 if os.path.isdir(path):
 for fname in glob.glob(os.path.join(path, '*')) + glob.glob(os.path.join(path, '.*')):
@@ -1294,7 +1334,76 @@
 ic1 = breakpoints
 return np.concatenate((ic0[:, np.newaxis], ic1[:, np.newaxis]), axis=1)
 
+def isvector(X):
+ """
+ Like the Matlab (TM) function with the same name, returns true if
+ the supplied numpy array or matrix looks like a vector, meaning it
+ has a one non-singleton axis (i.e., it can have multiple axes, but
+ all must have length 1, except for one of them).
 
+ If you just want to see if the array has 1 axis, use X.ndim==1
+
+ Call signature::
+ isvector(X)
+ """
+ return np.prod(X.shape)==np.max(X.shape)
+
+def vector_lengths( X, P=2., axis=None ):
+ """
+ Finds the length of a set of vectors in n dimensions. This is
+ like the mlab.norm function for vectors, but has the ability to
+ work over a particular axis of the supplied array or matrix.
+
+ Call signature::
+
+ vector_lengths( X, P=2., axis=None )
+
+ Computes (sum((x_i)^P))^(1/P) for each {x_i} being the elements of X along
+ the given axis. If *axis* is *None*, compute over all elements of X.
+ """
+ X = np.asarray(X)
+ return (np.sum(X**(P),axis=axis))**(1./P)
+
+def distances_along_curve( X ):
+ """
+ Computes the distance between a set of successive points in N dimensions.
+
+ Call signature::
+
+ distances_along_curve(X)
+
+ where X is an MxN array or matrix. The distances between successive rows
+ is computed. Distance is the standard Euclidean distance.
+ """
+ X = np.diff( X, axis=0 )
+ return vector_lengths(X,axis=1)
+
+def path_length(X):
+ """
+ Computes the distance travelled along a polygonal curve in N dimensions.
+
+ Call signature::
+
+ path_length(X)
+
+ where X is an MxN array or matrix. Returns an array of length M consisting
+ of the distance along the curve at each point (i.e., the rows of X).
+ """
+ X = distances_along_curve(X)
+ return np.concatenate( (np.zeros(1), np.cumsum(X)) )
+
+def is_closed_polygon(X):
+ """
+ Tests whether first and last object in a sequence are the same. These are
+ presumably coordinates on a polygonal curve, in which case this function
+ tests if that curve is closed.
+
+ Call signature::
+
+ is_closed_polygon(X)
+ """
+ return np.all(X[0] == X[-1])
+
 # a dict to cross-map linestyle arguments
 _linestyles = [('-', 'solid'),
 ('--', 'dashed'),
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <dmk...@us...> - 2008年07月24日 08:06:50
Revision: 5829
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5829&view=rev
Author: dmkaplan
Date: 2008年07月24日 08:06:45 +0000 (2008年7月24日)
Log Message:
-----------
Slight documentation changes.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2008年07月24日 07:59:18 UTC (rev 5828)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2008年07月24日 08:06:45 UTC (rev 5829)
@@ -1159,10 +1159,15 @@
 def less_simple_linear_interpolation( x, y, xi, extrap=False ):
 """
 This function provides simple (but somewhat less so than
- simple_linear_interpolation) linear interpolation. This is very
- inefficient linear interpolation meant to be used only for a small
- number of points in relatively non-intensive use cases.
+ simple_linear_interpolation) linear interpolation.
+ simple_linear_interpolation will give a list of point between a
+ start and an end, while this does true linear interpolation at an
+ arbitrary set of points.
 
+ This is very inefficient linear interpolation meant to be used
+ only for a small number of points in relatively non-intensive use
+ cases.
+
 Call signature::
 
 yi = less_simple_linear_interpolation(x,y,xi)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <mme...@us...> - 2008年08月21日 15:29:16
Revision: 6046
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6046&view=rev
Author: mmetz_bn
Date: 2008年08月21日 15:29:12 +0000 (2008年8月21日)
Log Message:
-----------
import warnings; close bug # 2053683
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2008年08月19日 11:58:23 UTC (rev 6045)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2008年08月21日 15:29:12 UTC (rev 6046)
@@ -5,6 +5,7 @@
 from __future__ import generators
 import re, os, errno, sys, StringIO, traceback, locale, threading, types
 import time, datetime
+import warnings
 import numpy as np
 import numpy.ma as ma
 from weakref import ref
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <ef...@us...> - 2008年09月28日 03:07:13
Revision: 6128
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6128&view=rev
Author: efiring
Date: 2008年09月28日 03:07:04 +0000 (2008年9月28日)
Log Message:
-----------
fixed cbook.flatten so its docstring example works
Previously, flatten(('a','b')) triggered infinite recursion.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2008年09月28日 00:44:08 UTC (rev 6127)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2008年09月28日 03:07:04 UTC (rev 6128)
@@ -318,7 +318,10 @@
 return fh, opened
 return fh
 
-def flatten(seq, scalarp=is_scalar):
+def is_scalar_or_string(val):
+ return is_string_like(val) or not iterable(val)
+
+def flatten(seq, scalarp=is_scalar_or_string):
 """
 this generator flattens nested containers such as
 
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <ef...@us...> - 2008年10月22日 19:37:58
Revision: 6299
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6299&view=rev
Author: efiring
Date: 2008年10月22日 19:37:46 +0000 (2008年10月22日)
Log Message:
-----------
whitespace deletion in cbook.py
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2008年10月22日 19:28:14 UTC (rev 6298)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2008年10月22日 19:37:46 UTC (rev 6299)
@@ -477,9 +477,9 @@
 make directory *newdir* recursively, and set *mode*. Equivalent to ::
 
 > mkdir -p NEWDIR
- > chmod MODE NEWDIR 
+ > chmod MODE NEWDIR
 """
- try: 
+ try:
 if not os.path.exists(newdir):
 parts = os.path.split(newdir)
 for i in range(1, len(parts)+1):
@@ -1325,7 +1325,7 @@
 This function has been moved to matplotlib.mlab -- please import
 it from there
 """
- # deprecated from cbook in 0.98.4 
+ # deprecated from cbook in 0.98.4
 warnings.warn('less_simple_linear_interpolation has been moved to matplotlib.mlab -- please import it from there', DeprecationWarning)
 import matplotlib.mlab as mlab
 return mlab.less_simple_linear_interpolation( x, y, xi, extrap=extrap )
@@ -1335,7 +1335,7 @@
 This function has been moved to matplotlib.mlab -- please import
 it from there
 """
- # deprecated from cbook in 0.98.4 
+ # deprecated from cbook in 0.98.4
 warnings.warn('isvector has been moved to matplotlib.mlab -- please import it from there', DeprecationWarning)
 import matplotlib.mlab as mlab
 return mlab.isvector( x, y, xi, extrap=extrap )
@@ -1345,7 +1345,7 @@
 This function has been moved to matplotlib.mlab -- please import
 it from there
 """
- # deprecated from cbook in 0.98.4 
+ # deprecated from cbook in 0.98.4
 warnings.warn('vector_lengths has been moved to matplotlib.mlab -- please import it from there', DeprecationWarning)
 import matplotlib.mlab as mlab
 return mlab.vector_lengths( X, P=2., axis=axis )
@@ -1355,7 +1355,7 @@
 This function has been moved to matplotlib.mlab -- please import
 it from there
 """
- # deprecated from cbook in 0.98.4 
+ # deprecated from cbook in 0.98.4
 warnings.warn('distances_along_curve has been moved to matplotlib.mlab -- please import it from there', DeprecationWarning)
 import matplotlib.mlab as mlab
 return mlab.distances_along_curve( X )
@@ -1365,7 +1365,7 @@
 This function has been moved to matplotlib.mlab -- please import
 it from there
 """
- # deprecated from cbook in 0.98.4 
+ # deprecated from cbook in 0.98.4
 warnings.warn('path_length has been moved to matplotlib.mlab -- please import it from there', DeprecationWarning)
 import matplotlib.mlab as mlab
 return mlab.path_length(X)
@@ -1375,7 +1375,7 @@
 This function has been moved to matplotlib.mlab -- please import
 it from there
 """
- # deprecated from cbook in 0.98.4 
+ # deprecated from cbook in 0.98.4
 warnings.warn('is_closed_polygon has been moved to matplotlib.mlab -- please import it from there', DeprecationWarning)
 import matplotlib.mlab as mlab
 return mlab.is_closed_polygon(X)
@@ -1385,7 +1385,7 @@
 This function has been moved to matplotlib.mlab -- please import
 it from there
 """
- # deprecated from cbook in 0.98.4 
+ # deprecated from cbook in 0.98.4
 warnings.warn('quad2cubic has been moved to matplotlib.mlab -- please import it from there', DeprecationWarning)
 import matplotlib.mlab as mlab
 return mlab.quad2cubic(q0x, q0y, q1x, q1y, q2x, q2y)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <ry...@us...> - 2008年11月10日 18:59:21
Revision: 6385
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6385&view=rev
Author: ryanmay
Date: 2008年11月10日 18:59:18 +0000 (2008年11月10日)
Log Message:
-----------
Make iterable() and is_string_like() return True/False instead of 1/0.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2008年11月09日 14:11:16 UTC (rev 6384)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2008年11月10日 18:59:18 UTC (rev 6385)
@@ -261,16 +261,16 @@
 def iterable(obj):
 'return true if *obj* is iterable'
 try: len(obj)
- except: return 0
- return 1
+ except: return False
+ return True
 
 
 def is_string_like(obj):
 'return true if *obj* looks like a string'
- if hasattr(obj, 'shape'): return 0
+ if hasattr(obj, 'shape'): return False
 try: obj + ''
- except (TypeError, ValueError): return 0
- return 1
+ except (TypeError, ValueError): return False
+ return True
 
 def is_sequence_of_strings(obj):
 """
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <jd...@us...> - 2009年01月28日 20:39:21
Revision: 6845
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6845&view=rev
Author: jdh2358
Date: 2009年01月28日 20:39:18 +0000 (2009年1月28日)
Log Message:
-----------
changed the default file handle to open in universal mode
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2009年01月28日 17:55:07 UTC (rev 6844)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2009年01月28日 20:39:18 UTC (rev 6845)
@@ -302,7 +302,7 @@
 except TypeError: return False
 else: return True
 
-def to_filehandle(fname, flag='r', return_opened=False):
+def to_filehandle(fname, flag='rU', return_opened=False):
 """
 *fname* can be a filename or a file handle. Support for gzipped
 files is automatic, if the filename ends in .gz. *flag* is a
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <js...@us...> - 2009年01月29日 16:16:22
Revision: 6846
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6846&view=rev
Author: jswhit
Date: 2009年01月29日 16:16:14 +0000 (2009年1月29日)
Log Message:
-----------
make default mode 'r' for gzipped files, since 'rU' apparently is not 
supported in the gzip module (at least in python 2.5.2)
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2009年01月28日 20:39:18 UTC (rev 6845)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2009年01月29日 16:16:14 UTC (rev 6846)
@@ -311,6 +311,8 @@
 if is_string_like(fname):
 if fname.endswith('.gz'):
 import gzip
+ # universal newline mode doesn't work for gzipped files.
+ if flag == 'rU': flag = 'r'
 fh = gzip.open(fname, flag)
 else:
 fh = file(fname, flag)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <js...@us...> - 2009年01月29日 19:59:26
Revision: 6852
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6852&view=rev
Author: jswhit
Date: 2009年01月29日 19:59:22 +0000 (2009年1月29日)
Log Message:
-----------
get rid of 'U' in mode flag for gzipped files.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2009年01月29日 18:12:56 UTC (rev 6851)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2009年01月29日 19:59:22 UTC (rev 6852)
@@ -311,8 +311,8 @@
 if is_string_like(fname):
 if fname.endswith('.gz'):
 import gzip
- # universal newline mode doesn't work for gzipped files.
- if flag == 'rU': flag = 'r'
+ # get rid of 'U' in flag for gzipped files.
+ flag = flag.replace('U','')
 fh = gzip.open(fname, flag)
 else:
 fh = file(fname, flag)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <jd...@us...> - 2009年06月07日 14:11:32
Revision: 7192
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7192&view=rev
Author: jdh2358
Date: 2009年06月07日 13:55:10 +0000 (2009年6月07日)
Log Message:
-----------
add support for bz2 files per sf support request 2794556
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2009年06月07日 13:46:10 UTC (rev 7191)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2009年06月07日 13:55:10 UTC (rev 7192)
@@ -314,6 +314,11 @@
 # get rid of 'U' in flag for gzipped files.
 flag = flag.replace('U','')
 fh = gzip.open(fname, flag)
+ elif fname.endswith('.bz2'):
+ # get rid of 'U' in flag for bz2 files
+ flag = flag.replace('U','')
+ import bz2
+ fh = bz2.BZ2File(fname, flag)
 else:
 fh = file(fname, flag)
 opened = True
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <jd...@us...> - 2009年08月05日 14:44:26
Revision: 7367
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7367&view=rev
Author: jdh2358
Date: 2009年08月05日 14:44:18 +0000 (2009年8月05日)
Log Message:
-----------
make urllib quote python2.4 compliant
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2009年08月05日 14:39:36 UTC (rev 7366)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2009年08月05日 14:44:18 UTC (rev 7367)
@@ -488,8 +488,16 @@
 get_sample_data.processor = _CacheProcessor(cachedir)
 get_sample_data.opener = urllib2.build_opener(get_sample_data.processor)
 
+
+ # quote is not in python2.4, so check for it and get it from
+ # urllib if it is not available
+ quote = getattr(urllib2, 'quote', None)
+ if quote is None:
+ import urllib
+ quote = urllib.quote
+
 url = 'http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/sample_data/' + \
- urllib2.quote(fname)
+ quote(fname)
 response = get_sample_data.opener.open(url)
 if asfileobj:
 return response
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <jd...@us...> - 2009年08月05日 15:07:48
Revision: 7370
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7370&view=rev
Author: jdh2358
Date: 2009年08月05日 15:07:41 +0000 (2009年8月05日)
Log Message:
-----------
add support for nested dirs in sample_data
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2009年08月05日 15:02:12 UTC (rev 7369)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2009年08月05日 15:07:41 UTC (rev 7370)
@@ -356,8 +356,14 @@
 self.remove_stale_files()
 
 def in_cache_dir(self, fn):
- return os.path.join(self.cache_dir, fn)
+ # make sure the datadir exists
+ reldir, filename = os.path.split(fn)
+ datadir = os.path.join(self.cache_dir, reldir)
+ if not os.path.exists(datadir):
+ os.makedirs(datadir)
 
+ return os.path.join(datadir, filename)
+
 def read_cache(self):
 """
 Read the cache file from the cache directory.
@@ -386,7 +392,11 @@
 listed = set([fn for (_, (fn, _, _)) in self.cache.items()])
 for path in os.listdir(self.cache_dir):
 if path not in listed and path != 'cache.pck':
- os.remove(os.path.join(self.cache_dir, path))
+ thisfile = os.path.join(self.cache_dir, path)
+ if not os.path.isdir(thisfile):
+ matplotlib.verbose.report('_CacheProcessor:remove_stale_files: removing %s'%thisfile,
+ level='debug')
+ os.remove(thisfile)
 
 def write_cache(self):
 """
@@ -402,12 +412,14 @@
 Store a received file in the cache directory.
 """
 # Pick a filename
- rightmost = url.rstrip('/').split('/')[-1]
- fn = rightmost
- while os.path.exists(self.in_cache_dir(fn)):
- fn = rightmost + '.' + str(random.randint(0,9999999))
+ fn = url[len(self.baseurl):]
+ fullpath = self.in_cache_dir(fn)
 
- # Write out the data
+ #while os.path.exists(self.in_cache_dir(fn)):
+ # fn = rightmost + '.' + str(random.randint(0,9999999))
+
+ 
+ 
 f = open(self.in_cache_dir(fn), 'wb')
 f.write(data)
 f.close()
@@ -438,7 +450,9 @@
 """
 url = req.get_full_url()
 fn, _, _ = self.cache[url]
- file = open(self.in_cache_dir(fn), 'rb')
+ cachefile = self.in_cache_dir(fn)
+ matplotlib.verbose.report('_CacheProcessor: reading data file from cache file "%s"'%cachefile)
+ file = open(cachefile, 'rb')
 handle = urllib2.addinfourl(file, hdrs, url)
 handle.code = 304
 return handle
@@ -480,13 +494,14 @@
 intended for use in mpl examples that need custom data
 """
 
+ baseurl ='http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/sample_data/'
 if not hasattr(get_sample_data, 'opener'):
 configdir = matplotlib.get_configdir()
 cachedir = os.path.join(configdir, 'sample_data')
 if not os.path.exists(cachedir):
 os.mkdir(cachedir)
 # Store the cache processor and url opener as attributes of this function
- get_sample_data.processor = _CacheProcessor(cachedir)
+ get_sample_data.processor = _CacheProcessor(cachedir, baseurl)
 get_sample_data.opener = urllib2.build_opener(get_sample_data.processor)
 
 
@@ -497,8 +512,7 @@
 import urllib
 quote = urllib.quote
 
- url = 'http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/sample_data/' + \
- quote(fname)
+ url = baseurl + quote(fname)
 response = get_sample_data.opener.open(url)
 if asfileobj:
 return response
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <jo...@us...> - 2009年08月15日 20:00:23
Revision: 7493
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7493&view=rev
Author: jouni
Date: 2009年08月15日 20:00:09 +0000 (2009年8月15日)
Log Message:
-----------
get_sample_data improvements: remove old files from subdirectories and
not only the top-level directory; try to handle the disconnected use case;
use the perhaps more stable svnroot URL instead of the viewvc one
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2009年08月15日 18:37:25 UTC (rev 7492)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2009年08月15日 20:00:09 UTC (rev 7493)
@@ -355,7 +355,7 @@
 class ViewVCCachedServer(urllib2.BaseHandler):
 """
 Urllib2 handler that takes care of caching files.
- The file cache.pck holds the directory of files to be cached.
+ The file cache.pck holds the directory of files that have been cached.
 """
 def __init__(self, cache_dir, baseurl):
 self.cache_dir = cache_dir
@@ -386,9 +386,14 @@
 cache = cPickle.load(f)
 f.close()
 
+ # Earlier versions did not have the full paths in cache.pck
+ for url, (fn, x, y) in cache.items():
+ if not os.path.isabs(fn):
+ cache[url] = (self.in_cache_dir(fn), x, y)
+ 
 # If any files are deleted, drop them from the cache
 for url, (fn, _, _) in cache.items():
- if not os.path.exists(self.in_cache_dir(fn)):
+ if not os.path.exists(fn):
 del cache[url]
 
 self.cache = cache
@@ -398,15 +403,21 @@
 Remove files from the cache directory that are not listed in
 cache.pck.
 """
- listed = set([fn for (_, (fn, _, _)) in self.cache.items()])
- for path in os.listdir(self.cache_dir):
- if path not in listed and path != 'cache.pck':
- thisfile = os.path.join(self.cache_dir, path)
- if not os.path.isdir(thisfile):
- matplotlib.verbose.report('ViewVCCachedServer:remove_stale_files: removing %s'%thisfile,
- level='debug')
- os.remove(thisfile)
+ # TODO: remove empty subdirectories
+ listed = set(fn for (_, (fn, _, _)) in self.cache.items())
+ existing = reduce(set.union,
+ (set(os.path.join(dirpath, fn) for fn in filenames)
+ for (dirpath, _, filenames) in os.walk(self.cache_dir)))
+ matplotlib.verbose.report(
+ 'ViewVCCachedServer: files listed in cache.pck: %s' % listed, 'debug')
+ matplotlib.verbose.report(
+ 'ViewVCCachedServer: files in cache directory: %s' % existing, 'debug')
 
+ for path in existing - listed - set([self.in_cache_dir('cache.pck')]):
+ matplotlib.verbose.report('ViewVCCachedServer:remove_stale_files: removing %s'%path,
+ level='debug')
+ os.remove(path)
+
 def write_cache(self):
 """
 Write the cache data structure into the cache directory.
@@ -424,17 +435,12 @@
 fn = url[len(self.baseurl):]
 fullpath = self.in_cache_dir(fn)
 
- #while os.path.exists(self.in_cache_dir(fn)):
- # fn = rightmost + '.' + str(random.randint(0,9999999))
-
-
-
- f = open(self.in_cache_dir(fn), 'wb')
+ f = open(fullpath, 'wb')
 f.write(data)
 f.close()
 
 # Update the cache
- self.cache[url] = (fn, headers.get('ETag'), headers.get('Last-Modified'))
+ self.cache[url] = (fullpath, headers.get('ETag'), headers.get('Last-Modified'))
 self.write_cache()
 
 # These urllib2 entry points are used:
@@ -459,9 +465,9 @@
 """
 url = req.get_full_url()
 fn, _, _ = self.cache[url]
- cachefile = self.in_cache_dir(fn)
- matplotlib.verbose.report('ViewVCCachedServer: reading data file from cache file "%s"'%cachefile)
- file = open(cachefile, 'rb')
+ matplotlib.verbose.report('ViewVCCachedServer: reading data file from cache file "%s"'
+ %fn, 'debug')
+ file = open(fn, 'rb')
 handle = urllib2.addinfourl(file, hdrs, url)
 handle.code = 304
 return handle
@@ -470,6 +476,8 @@
 """
 Update the cache with the returned file.
 """
+ matplotlib.verbose.report('ViewVCCachedServer: received response %d: %s'
+ % (response.code, response.msg), 'debug')
 if response.code != 200:
 return response
 else:
@@ -489,11 +497,11 @@
 store it in the cachedir.
 
 If asfileobj is True, a file object will be returned. Else the
- path to the file as a string will be returned
-
+ path to the file as a string will be returned.
 """
+ # TODO: time out if the connection takes forever
+ # (may not be possible with urllib2 only - spawn a helper process?)
 
-
 # quote is not in python2.4, so check for it and get it from
 # urllib if it is not available
 quote = getattr(urllib2, 'quote', None)
@@ -501,13 +509,25 @@
 import urllib
 quote = urllib.quote
 
+ # retrieve the URL for the side effect of refreshing the cache
 url = self.baseurl + quote(fname)
- response = self.opener.open(url)
+ error = 'unknown error'
+ matplotlib.verbose.report('ViewVCCachedServer: retrieving %s'
+ % url, 'debug')
+ try:
+ response = self.opener.open(url)
+ except urllib2.URLError, e:
+ # could be a missing network connection
+ error = str(e)
 
+ cached = self.cache.get(url)
+ if cached is None:
+ msg = 'file %s not in cache; received %s when trying to retrieve' \
+ % (fname, error)
+ raise KeyError(msg)
+ 
+ fname = cached[0]
 
- relpath = self.cache[url][0]
- fname = self.in_cache_dir(relpath)
-
 if asfileobj:
 return file(fname)
 else:
@@ -519,7 +539,7 @@
 Check the cachedirectory ~/.matplotlib/sample_data for a sample_data
 file. If it does not exist, fetch it with urllib from the mpl svn repo
 
- http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/sample_data/
+ http://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/sample_data/
 
 and store it in the cachedir.
 
@@ -539,7 +559,7 @@
 if myserver is None:
 configdir = matplotlib.get_configdir()
 cachedir = os.path.join(configdir, 'sample_data')
- baseurl = 'http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/sample_data/'
+ baseurl = 'http://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/sample_data/'
 myserver = get_sample_data.myserver = ViewVCCachedServer(cachedir, baseurl)
 
 return myserver.get_sample_data(fname, asfileobj=asfileobj)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <as...@us...> - 2009年08月30日 04:44:15
Revision: 7593
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7593&view=rev
Author: astraw
Date: 2009年08月30日 04:44:03 +0000 (2009年8月30日)
Log Message:
-----------
fix typo
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2009年08月30日 04:43:54 UTC (rev 7592)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2009年08月30日 04:44:03 UTC (rev 7593)
@@ -910,7 +910,7 @@
 
 def get_recursive_filelist(args):
 """
- Recurs all the files and dirs in *args* ignoring symbolic links
+ Recurse all the files and dirs in *args* ignoring symbolic links
 and return the files as a list of strings
 """
 files = []
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <md...@us...> - 2010年05月28日 17:42:12
Revision: 8341
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8341&view=rev
Author: mdboom
Date: 2010年05月28日 17:42:05 +0000 (2010年5月28日)
Log Message:
-----------
Fix memory leak caused by never disconnecting callbacks.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2010年05月28日 16:56:45 UTC (rev 8340)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2010年05月28日 17:42:05 UTC (rev 8341)
@@ -13,6 +13,7 @@
 import os.path
 import random
 import urllib2
+import new
 
 import matplotlib
 
@@ -124,12 +125,87 @@
 callbacks.disconnect(ideat) # disconnect oneat
 callbacks.process('eat', 456) # nothing will be called
 
+ In practice, one should always disconnect all callbacks when they
+ are no longer needed to avoid dangling references (and thus memory
+ leaks). However, real code in matplotlib rarely does so, and due
+ to its design, it is rather difficult to place this kind of code.
+ To get around this, and prevent this class of memory leaks, we
+ instead store weak references to bound methods only, so when the
+ destination object needs to die, the CallbackRegistry won't keep
+ it alive. The Python stdlib weakref module can not create weak
+ references to bound methods directly, so we need to create a proxy
+ object to handle weak references to bound methods (or regular free
+ functions). This technique was shared by Peter Parente on his
+ `"Mindtrove" blog
+ <http://mindtrove.info/articles/python-weak-references/>`_.
 """
+ class BoundMethodProxy(object):
+ '''
+ Our own proxy object which enables weak references to bound and unbound
+ methods and arbitrary callables. Pulls information about the function,
+ class, and instance out of a bound method. Stores a weak reference to the
+ instance to support garbage collection.
+
+ @organization: IBM Corporation
+ @copyright: Copyright (c) 2005, 2006 IBM Corporation
+ @license: The BSD License
+
+ Minor bugfixes by Michael Droettboom
+ '''
+ def __init__(self, cb):
+ try:
+ try:
+ self.inst = ref(cb.im_self)
+ except TypeError:
+ self.inst = None
+ self.func = cb.im_func
+ self.klass = cb.im_class
+ except AttributeError:
+ self.inst = None
+ self.func = cb
+ self.klass = None
+
+ def __call__(self, *args, **kwargs):
+ '''
+ Proxy for a call to the weak referenced object. Take
+ arbitrary params to pass to the callable.
+
+ Raises `ReferenceError`: When the weak reference refers to
+ a dead object
+ '''
+ if self.inst is not None and self.inst() is None:
+ raise ReferenceError
+ elif self.inst is not None:
+ # build a new instance method with a strong reference to the instance
+ mtd = new.instancemethod(self.func, self.inst(), self.klass)
+ else:
+ # not a bound method, just return the func
+ mtd = self.func
+ # invoke the callable and return the result
+ return mtd(*args, **kwargs)
+
+ def __eq__(self, other):
+ '''
+ Compare the held function and instance with that held by
+ another proxy.
+ '''
+ try:
+ if self.inst is None:
+ return self.func == other.func and other.inst is None
+ else:
+ return self.func == other.func and self.inst() == other.inst()
+ except Exception:
+ return False
+
+ def __ne__(self, other):
+ '''
+ Inverse of __eq__.
+ '''
+ return not self.__eq__(other)
+
 def __init__(self, signals):
 '*signals* is a sequence of valid signals'
 self.signals = set(signals)
- # callbacks is a dict mapping the signal to a dictionary
- # mapping callback id to the callback function
 self.callbacks = dict([(s, dict()) for s in signals])
 self._cid = 0
 
@@ -146,8 +222,15 @@
 func will be called
 """
 self._check_signal(s)
- self._cid +=1
- self.callbacks[s][self._cid] = func
+ proxy = self.BoundMethodProxy(func)
+ for cid, callback in self.callbacks[s].items():
+ # Clean out dead references
+ if callback.inst is not None and callback.inst() is None:
+ del self.callbacks[s][cid]
+ elif callback == proxy:
+ return cid
+ self._cid += 1
+ self.callbacks[s][self._cid] = proxy
 return self._cid
 
 def disconnect(self, cid):
@@ -155,9 +238,12 @@
 disconnect the callback registered with callback id *cid*
 """
 for eventname, callbackd in self.callbacks.items():
- try: del callbackd[cid]
- except KeyError: continue
- else: return
+ try:
+ del callbackd[cid]
+ except KeyError:
+ continue
+ else:
+ return
 
 def process(self, s, *args, **kwargs):
 """
@@ -165,8 +251,12 @@
 callbacks on *s* will be called with *\*args* and *\*\*kwargs*
 """
 self._check_signal(s)
- for func in self.callbacks[s].values():
- func(*args, **kwargs)
+ for cid, proxy in self.callbacks[s].items():
+ # Clean out dead references
+ if proxy.inst is not None and proxy.inst() is None:
+ del self.callbacks[s][cid]
+ else:
+ proxy(*args, **kwargs)
 
 
 class Scheduler(threading.Thread):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <ef...@us...> - 2010年06月11日 08:34:30
Revision: 8413
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8413&view=rev
Author: efiring
Date: 2010年06月11日 08:34:24 +0000 (2010年6月11日)
Log Message:
-----------
[3013559] cbook.get_sample_data: open image file in binary mode. Patch by C. Gohlke.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2010年06月11日 08:09:25 UTC (rev 8412)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2010年06月11日 08:34:24 UTC (rev 8413)
@@ -619,7 +619,11 @@
 fname = cached[0]
 
 if asfileobj:
- return file(fname)
+ if os.path.splitext(fname)[-1].lower() in ('.csv', '.xrc', '.txt'):
+ mode = 'r'
+ else:
+ mode = 'rb'
+ return open(fname, mode)
 else:
 return fname
 
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <ef...@us...> - 2010年06月14日 02:54:05
Revision: 8433
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8433&view=rev
Author: efiring
Date: 2010年06月14日 02:53:59 +0000 (2010年6月14日)
Log Message:
-----------
cbook: handle empty string returned by locale.getpreferredencoding
Reported by Huziy Oleksandr.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2010年06月14日 02:33:37 UTC (rev 8432)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2010年06月14日 02:53:59 UTC (rev 8433)
@@ -23,11 +23,14 @@
 # On some systems, locale.getpreferredencoding returns None,
 # which can break unicode; and the sage project reports that
 # some systems have incorrect locale specifications, e.g.,
-# an encoding instead of a valid locale name.
+# an encoding instead of a valid locale name. Another
+# pathological case that has been reported is an empty string.
 
 try:
- preferredencoding = locale.getpreferredencoding()
-except (ValueError, ImportError):
+ preferredencoding = locale.getpreferredencoding().strip()
+ if not preferredencoding:
+ preferredencoding = None
+except (ValueError, ImportError, AttributeError):
 preferredencoding = None
 
 def unicode_safe(s):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
From: <ef...@us...> - 2011年02月08日 04:42:23
Revision: 8958
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8958&view=rev
Author: efiring
Date: 2011年02月08日 04:42:17 +0000 (2011年2月08日)
Log Message:
-----------
cbook.report_memory: restore compatibility with earlier subprocess versions
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py	2011年02月07日 22:49:09 UTC (rev 8957)
+++ trunk/matplotlib/lib/matplotlib/cbook.py	2011年02月08日 04:42:17 UTC (rev 8958)
@@ -1233,7 +1233,7 @@
 
 def report_memory(i=0): # argument may go away
 'return the memory consumed by process'
- from subprocess import Popen, PIPE, check_output
+ from subprocess import Popen, PIPE
 pid = os.getpid()
 if sys.platform=='sunos5':
 a2 = Popen('ps -p %d -o osz' % pid, shell=True,
@@ -1248,7 +1248,13 @@
 stdout=PIPE).stdout.readlines()
 mem = int(a2[1].split()[0])
 elif sys.platform.startswith('win'):
- a2 = check_output(["tasklist", "/nh", "/fi", "pid eq %d" % pid])
+ try:
+ a2 = Popen(["tasklist", "/nh", "/fi", "pid eq %d" % pid],
+ stdout=PIPE).stdout.read()
+ except OSError:
+ raise NotImplementedError(
+ "report_memory works on Windows only if "
+ "the 'tasklist' program is found")
 mem = int(a2.strip().split()[-2].replace(',',''))
 else:
 raise NotImplementedError(
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /