def _get_file(self): try: if self.is_local(): return default_storage.open(self.url) else: return get_privileged_opener().open(self.get_actual_url()) except: return None
def testCredentials(self): """ Test that the walker manages credentials. """ address = "http://localhost:%d/test.jpg" % (TestWebServer.getPort()) # We shouldn't be able to get the file without credentials try: urllib2.urlopen(address) ok_(False, "Should have thrown error") except urllib2.HTTPError: pass # We should be able to get it with the provided credentials try: f = get_privileged_opener().open(address) eq_(f.getcode(), 200, 'Should have been: "200 OK"') except urllib2.HTTPError: ok_(False, "Should not have thrown error")
def testCredentials(self): ''' Test that the walker manages credentials. ''' address = 'http://localhost:%d/test.jpg' % \ (TestWebServer.getPort()) # We shouldn't be able to get the file without credentials try: urllib2.urlopen(address) ok_(False, 'Should have thrown error') except urllib2.HTTPError: pass # We should be able to get it with the provided credentials try: f = get_privileged_opener().open(address) eq_(f.getcode(), 200, 'Should have been: "200 OK"') except urllib2.HTTPError: ok_(False, 'Should not have thrown error')
def check_file_transferred(datafile, destination, target_url): """ Check that a datafile has been successfully transfered to a remote storage location """ # If the remote is capable, get it to send us the checksums and / or # file length for its copy of the file try: # Fetch the remote's metadata for the file m = destination.provider.get_metadata(target_url) if _check_attribute(m, datafile.sha512sum, 'sha512sum') or \ _check_attribute(m, datafile.md5sum, 'md5sum') or \ (destination.trust_length and \ _check_attribute(m, datafile.length, 'length')) : return raise MigrationError('Not enough metadata for verification') except NotImplementedError: pass except HTTPError as e: # Bad request means that the remote didn't recognize the query if e.code != 400: raise if destination.trust_length : try: length = destination.provider.get_length(target_url) if _check_attribute2(length, datafile.length, 'length'): return except NotImplementedError: pass # (Deferred import to avoid prematurely triggering DB init) from tardis.tardis_portal.models import generate_file_checksums # Fetch back the remote file and verify it locally. f = get_privileged_opener().open(target_url) md5sum, sha512sum, size, x = generate_file_checksums(f, None) if _check_attribute2(sha512sum, datafile.sha512sum, 'sha512sum') or \ _check_attribute2(md5sum, datafile.md5sum, 'md5sum'): return raise MigrationError('Not enough metadata for file verification')
def getter(): return get_privileged_opener().open(theUrl)