def resolve_uri_contents(uri: URI, fingerprint: bool = None) -> bytes: resolvable_backends = get_resolvable_backends_for_uri(uri) if resolvable_backends: for backend in resolvable_backends: try: # type ignored to handle case if URI is returned contents: bytes = backend().fetch_uri_contents( uri) # type: ignore except CannotHandleURI: continue return contents translatable_backends = get_translatable_backends_for_uri(uri) if translatable_backends: if fingerprint: raise CannotHandleURI( "Registry URIs must point to a resolvable content-addressed URI." ) package_id = RegistryURIBackend().fetch_uri_contents(uri) return resolve_uri_contents(package_id, True) raise CannotHandleURI( f"URI: {uri} cannot be resolved by any of the available backends.")
def test_get_resolvable_backends_for_supported_uris(dummy_ipfs_backend, uri, backends): good_backends = get_resolvable_backends_for_uri(uri) assert good_backends == backends