Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid uri shadowing #280

Merged
merged 8 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions linkml_runtime/utils/metamodelcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
from linkml_runtime.utils.namespaces import Namespaces
from linkml_runtime.utils.strictness import is_strict

from linkml_runtime.utils.uri_validator import validate_uri
from linkml_runtime.utils.uri_validator import validate_uri_reference
from linkml_runtime.utils.uri_validator import validate_curie

# Reference Decimal to make sure it stays in the imports
_z = Decimal(1)

Expand Down Expand Up @@ -105,17 +109,21 @@ def is_valid(cls, v: Union[str, URIRef, "Curie", "URIorCURIE"]) -> bool:
if not isinstance(v, (str, URIRef, Curie, URIorCURIE)):
return False
v = str(v)
if ':' in v and '://' not in v:
return URIorCURIE.is_curie(v)
if validate_uri(v):
return True
elif validate_uri_reference(v):
return True
else:
return URI.is_valid(v)
return URIorCURIE.is_curie(v)

@staticmethod
def is_absolute(v: str) -> bool:
return bool(urlparse(v).netloc)

@staticmethod
def is_curie(v: str, nsm: Optional[Namespaces] = None) -> bool:
if not validate_curie(v):
return False
if ':' in v and '://' not in v:
ns, ln = v.split(':', 1)
return len(ns) == 0 or (NCName.is_valid(ns) and
Expand All @@ -136,13 +144,14 @@ def __init__(self, v: str) -> None:
raise ValueError(f"'{v}': is not a valid URI")
super().__init__(v)

# this is more inclusive than the W3C specification
#uri_re = re.compile("^[A-Za-z]\\S*$")
uri_re = re.compile("^\\S+$")

@classmethod
def is_valid(cls, v: str) -> bool:
return v is not None and not URIorCURIE.is_curie(v) and cls.uri_re.match(v)
if validate_uri(v):
return True
elif validate_uri_reference(v):
return True
else:
return False


class Curie(URIorCURIE):
Expand Down Expand Up @@ -174,6 +183,8 @@ def ns_ln(cls, v: str) -> Optional[Tuple[str, str]]:

@classmethod
def is_valid(cls, v: str) -> bool:
if not validate_curie(v):
return False
pnln = cls.ns_ln(v)
#return pnln is not None and (not pnln[0] or isinstance(pnln[0], PN_PREFIX))
return pnln is not None
Expand Down
Loading