예제 #1
0
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
예제 #2
0
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
예제 #3
0
파일: tests.py 프로젝트: bartdag/recodoc2
 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"))
예제 #4
0
 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'))