diff --git a/GPy/util/datasets.py b/GPy/util/datasets.py index fdba0ac5..b4a26636 100644 --- a/GPy/util/datasets.py +++ b/GPy/util/datasets.py @@ -3,7 +3,6 @@ import numpy as np import GPy import scipy.io import cPickle as pickle -import urllib as url import zipfile import tarfile import datetime @@ -15,7 +14,7 @@ except ImportError: ipython_available=False -import sys, urllib +import sys, urllib2 def reporthook(a,b,c): # ',' at the end of the line is important! @@ -82,7 +81,18 @@ def download_url(url, store_directory, save_name = None, messages = True, suffix print "Downloading ", url, "->", os.path.join(store_directory, file) if not os.path.exists(dir_name): os.makedirs(dir_name) - urllib.urlretrieve(url+suffix, save_name, reporthook) + try: + response = urllib2.urlopen(url+suffix) + except urllib2.URLError, e: + if not hasattr(e, "code"): + raise + response = e + if response.code == 404: + raise ValueError('Url ' + url + suffix + ' 404 not found.') + with open(save_name, 'wb') as f: + f.write(response.read()) + + #urllib.urlretrieve(url+suffix, save_name, reporthook) def authorize_download(dataset_name=None): """Check with the user that the are happy with terms and conditions for the data set.""" diff --git a/GPy/util/mocap.py b/GPy/util/mocap.py index 78f00955..58662cf9 100644 --- a/GPy/util/mocap.py +++ b/GPy/util/mocap.py @@ -67,14 +67,14 @@ class tree: for i in range(len(self.vertices)): if self.vertices[i].id == id: return i - raise Error, 'Reverse look up of id failed.' + raise ValueError('Reverse look up of id failed.') def get_index_by_name(self, name): """Give the index associated with a given vertex name.""" for i in range(len(self.vertices)): if self.vertices[i].name == name: return i - raise Error, 'Reverse look up of name failed.' + raise ValueError('Reverse look up of name failed.') def order_vertices(self): """Order vertices in the graph such that parents always have a lower index than children.""" @@ -433,6 +433,8 @@ class acclaim_skeleton(skeleton): lin = self.read_line(fid) while lin != ':DEGREES': lin = self.read_line(fid) + if lin == '': + raise ValueError('Could not find :DEGREES in ' + fid.name) counter = 0 lin = self.read_line(fid) @@ -443,9 +445,9 @@ class acclaim_skeleton(skeleton): if frame_no: counter += 1 if counter != frame_no: - raise Error, 'Unexpected frame number.' + raise ValueError('Unexpected frame number.') else: - raise Error, 'Single bone name ...' + raise ValueError('Single bone name ...') else: ind = self.get_index_by_name(parts[0]) bones[ind].append(np.array([float(channel) for channel in parts[1:]])) @@ -573,7 +575,7 @@ class acclaim_skeleton(skeleton): return lin = self.read_line(fid) else: - raise Error, 'Unrecognised file format' + raise ValueError('Unrecognised file format') self.finalize() def read_units(self, fid):