From: <jd...@us...> - 2009-08-05 15:14:44
|
Revision: 7371 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7371&view=rev Author: jdh2358 Date: 2009-08-05 15:14:35 +0000 (Wed, 05 Aug 2009) Log Message: ----------- use proper file handle to the sample data Modified Paths: -------------- trunk/matplotlib/examples/misc/sample_data_test.py trunk/matplotlib/lib/matplotlib/cbook.py Modified: trunk/matplotlib/examples/misc/sample_data_test.py =================================================================== --- trunk/matplotlib/examples/misc/sample_data_test.py 2009-08-05 15:07:41 UTC (rev 7370) +++ trunk/matplotlib/examples/misc/sample_data_test.py 2009-08-05 15:14:35 UTC (rev 7371) @@ -8,6 +8,19 @@ svn version will be cached in ~/.matplotlib/sample_data) """ +import matplotlib.mlab as mlab import matplotlib.cbook as cbook -fh = cbook.get_sample_data('testdir/subdir/testsub.csv') + +# get the file handle to the cached data and print the contents +datafile = 'testdir/subdir/testsub.csv' +fh = cbook.get_sample_data(datafile) print fh.read() + +# make sure we can read it using csv2rec +fh.seek(0) +r = mlab.csv2rec(fh) + +print mlab.rec2txt(r) + +fh.close() + Modified: trunk/matplotlib/lib/matplotlib/cbook.py =================================================================== --- trunk/matplotlib/lib/matplotlib/cbook.py 2009-08-05 15:07:41 UTC (rev 7370) +++ trunk/matplotlib/lib/matplotlib/cbook.py 2009-08-05 15:14:35 UTC (rev 7371) @@ -418,8 +418,8 @@ #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() @@ -514,12 +514,15 @@ url = baseurl + quote(fname) response = get_sample_data.opener.open(url) + + p = get_sample_data.processor + relpath = p.cache[url][0] + fname = p.in_cache_dir(relpath) + if asfileobj: - return response + return file(fname) else: - response.close() - p = get_sample_data.processor - return p.in_cache_dir(p.cache[url][0]) + return fname def flatten(seq, scalarp=is_scalar_or_string): """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |