Beispiel #1
0
def resolve_install_uri(args: Namespace) -> ResolvedInstallURI:
    registry_backend = RegistryURIBackend()
    etherscan_backend = EtherscanURIBackend()
    if etherscan_backend.can_translate_uri(args.uri):
        manifest_uri = etherscan_backend.fetch_uri_contents(
            args.uri, args.package_name, args.package_version)
        registry_address = None
    elif registry_backend.can_translate_uri(args.uri):
        registry_address, _, _, _, _, _ = parse_registry_uri(args.uri)
        manifest_uri = registry_backend.fetch_uri_contents(args.uri)
    else:
        manifest_uri = args.uri
        registry_address = None
    return ResolvedInstallURI(manifest_uri, registry_address)
Beispiel #2
0
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:
                contents = backend().fetch_uri_contents(uri)
            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)  # type: ignore

    raise CannotHandleURI(
        f"URI: {uri} cannot be resolved by any of the available backends.")
def backend():
    return RegistryURIBackend()