Skip to content

Commit efed80d

Browse files
committedFeb 21, 2011
update examples to use sample_data from github
1 parent 2ab8582 commit efed80d

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed
 

‎examples/misc/sample_data_demo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Grab mpl data from the ~/.matplotlib/sample_data cache if it exists, else
3-
fetch it from svn and cache it
3+
fetch it from github and cache it
44
"""
55
import matplotlib.cbook as cbook
66
import matplotlib.pyplot as plt

‎examples/misc/sample_data_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""
2-
Demonstrate how get_sample_data works with svn revisions in the data.
2+
Demonstrate how get_sample_data works with git revisions in the data.
33
4-
svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/sample_data
4+
git clone git@github.com/matplotlib/sample_data.git
55
66
and edit testdata.csv to add a new row. After committing the changes,
77
when you rerun this script you will get the updated data (and the new
8-
svn version will be cached in ~/.matplotlib/sample_data)
8+
git version will be cached in ~/.matplotlib/sample_data)
99
"""
1010

1111
import matplotlib.mlab as mlab

‎lib/matplotlib/cbook.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,13 @@ def to_filehandle(fname, flag='rU', return_opened=False):
448448
def is_scalar_or_string(val):
449449
return is_string_like(val) or not iterable(val)
450450

451-
class ViewVCCachedServer(urllib2.BaseHandler):
451+
class ViewVCCachedServer(urllib2.HTTPSHandler):
452452
"""
453453
Urllib2 handler that takes care of caching files.
454454
The file cache.pck holds the directory of files that have been cached.
455455
"""
456456
def __init__(self, cache_dir, baseurl):
457+
urllib2.HTTPSHandler.__init__(self)
457458
self.cache_dir = cache_dir
458459
self.baseurl = baseurl
459460
self.read_cache()
@@ -544,7 +545,7 @@ def cache_file(self, url, data, headers):
544545
# http_error_304 for handling 304 Not Modified responses
545546
# http_response for postprocessing requests
546547

547-
def http_request(self, req):
548+
def https_request(self, req):
548549
"""
549550
Make the request conditional if we have a cached file.
550551
"""
@@ -555,20 +556,21 @@ def http_request(self, req):
555556
req.add_header("If-Modified-Since", lastmod)
556557
return req
557558

558-
def http_error_304(self, req, fp, code, msg, hdrs):
559+
def https_error_304(self, req, fp, code, msg, hdrs):
559560
"""
560561
Read the file from the cache since the server has no newer version.
561562
"""
562563
url = req.get_full_url()
563564
fn, _, _ = self.cache[url]
564-
matplotlib.verbose.report('ViewVCCachedServer: reading data file from cache file "%s"'
565-
%fn, 'debug')
565+
matplotlib.verbose.report(
566+
'ViewVCCachedServer: reading data file from cache file "%s"' %fn,
567+
'debug')
566568
file = open(fn, 'rb')
567569
handle = urllib2.addinfourl(file, hdrs, url)
568570
handle.code = 304
569571
return handle
570572

571-
def http_response(self, req, response):
573+
def https_response(self, req, response):
572574
"""
573575
Update the cache with the returned file.
574576
"""
@@ -589,7 +591,7 @@ def http_response(self, req, response):
589591
def get_sample_data(self, fname, asfileobj=True):
590592
"""
591593
Check the cachedirectory for a sample_data file. If it does
592-
not exist, fetch it with urllib from the svn repo and
594+
not exist, fetch it with urllib from the git repo and
593595
store it in the cachedir.
594596
595597
If asfileobj is True, a file object will be returned. Else the
@@ -637,21 +639,21 @@ def get_sample_data(self, fname, asfileobj=True):
637639
def get_sample_data(fname, asfileobj=True):
638640
"""
639641
Check the cachedirectory ~/.matplotlib/sample_data for a sample_data
640-
file. If it does not exist, fetch it with urllib from the mpl svn repo
642+
file. If it does not exist, fetch it with urllib from the mpl git repo
641643
642-
http://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/sample_data/
644+
https://github.com/matplotlib/sample_data/raw/master
643645
644646
and store it in the cachedir.
645647
646648
If asfileobj is True, a file object will be returned. Else the
647649
path to the file as a string will be returned
648650
649651
To add a datafile to this directory, you need to check out
650-
sample_data from matplotlib svn::
652+
sample_data from matplotlib git::
651653
652-
svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/sample_data
654+
git clone git@github.com:matplotlib/sample_data
653655
654-
and svn add the data file you want to support. This is primarily
656+
and git add the data file you want to support. This is primarily
655657
intended for use in mpl examples that need custom data.
656658
657659
To bypass all downloading, set the rc parameter examples.download to False
@@ -670,12 +672,13 @@ def get_sample_data(fname, asfileobj=True):
670672
if myserver is None:
671673
configdir = matplotlib.get_configdir()
672674
cachedir = os.path.join(configdir, 'sample_data')
673-
baseurl = 'http://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/sample_data/'
675+
baseurl = 'https://github.com/matplotlib/sample_data/raw/master/'
674676
myserver = get_sample_data.myserver = ViewVCCachedServer(cachedir, baseurl)
675677

676678
return myserver.get_sample_data(fname, asfileobj=asfileobj)
677679

678680
get_sample_data.myserver = None
681+
679682
def flatten(seq, scalarp=is_scalar_or_string):
680683
"""
681684
this generator flattens nested containers such as

0 commit comments

Comments
 (0)