Exemplo n.º 1
0
def is_supported_content_addressed_uri(uri: URI) -> bool:
    """
    Returns a bool indicating whether provided uri is currently supported.
    Currently Py-EthPM only supports IPFS and Github blob content-addressed uris.
    """
    if not is_ipfs_uri(uri) and not is_valid_content_addressed_github_uri(uri):
        return False
    return True
Exemplo n.º 2
0
 def fetch_uri_contents(self, ipfs_uri: str) -> bytes:
     if is_ipfs_uri(ipfs_uri):
         with open(str(V2_PACKAGES_DIR / "safe-math-lib" /
                       "1.0.0.json")) as file_obj:
             contents = file_obj.read()
     else:
         with open(str(V2_PACKAGES_DIR / ipfs_uri)) as file_obj:
             contents = file_obj.read()
     return to_bytes(text=contents)
Exemplo n.º 3
0
    def from_ipfs(cls, ipfs_uri: str) -> 'Package':
        """
        Instantiate a Package object from an IPFS uri.
        TODO: Defaults to Infura gateway, needs extension
        to support other gateways and local nodes
        """
        if is_ipfs_uri(ipfs_uri):
            ipfs_path = extract_ipfs_path_from_uri(ipfs_uri)
            package_data = fetch_ipfs_package(ipfs_path)
        else:
            raise TypeError(
                "The Package.from_ipfs method only accepts a valid IPFS uri."
                "{0} is not a valid IPFS uri.".format(ipfs_uri))

        return cls(package_data)
Exemplo n.º 4
0
def test_is_ipfs_uri(value, expected):
    actual = is_ipfs_uri(value)
    assert actual is expected
Exemplo n.º 5
0
def validate_ipfs_uri(uri: str) -> None:
    """
    Raise an exception if the provided URI is not a valid IPFS URI.
    """
    if not is_ipfs_uri(uri):
        raise ValidationError(f"URI: {uri} is not a valid IPFS URI.")
Exemplo n.º 6
0
 def can_resolve_uri(self, uri: str) -> bool:
     """
     Return a bool indicating whether or not this backend
     is capable of serving the content located at the URI.
     """
     return is_ipfs_uri(uri)
Exemplo n.º 7
0
def validate_is_supported_manifest_uri(uri):
    if not is_ipfs_uri(uri) and not is_valid_content_addressed_github_uri(uri):
        raise ManifestValidationError(
            f"URI: {uri} is not a valid content-addressed URI. "
            "Currently only IPFS and Github content-addressed URIs are supported."
        )
Exemplo n.º 8
0
 def can_handle_uri(self, uri: str) -> bool:
     if is_ipfs_uri(uri):
         return True
     path = V2_PACKAGES_DIR / uri
     return path.exists()