def get_file_from(url): trial = 0 file_from = None while trial < MAX_DOWNLOAD_RETRY: try: file_from = urllib2.urlopen(url) break except Exception: # Do not wait for local url. if is_local(url): path = urlparse.urlparse(url).path try: file_from = open(path) except Exception: pass break else: trial += 1 time.sleep(1) if file_from == None: logger.info('Error happened while opening url {0}'.format(url)) raise RecoDocError('Error downloading {0}'.format(url)) elif trial > 0: print('At least it was worth it') return file_from
def test_is_local(self): self.assertTrue(uu.is_local("/foo/bar.txt")) self.assertTrue(uu.is_local("file:///foo/bar.txt")) self.assertFalse(uu.is_local("http://foo/bar.txt"))
def test_is_local(self): self.assertTrue(uu.is_local('/foo/bar.txt')) self.assertTrue(uu.is_local('file:///foo/bar.txt')) self.assertFalse(uu.is_local('http://foo/bar.txt'))