13
13
from linkml_runtime .utils .namespaces import Namespaces
14
14
from linkml_runtime .utils .strictness import is_strict
15
15
16
+ from linkml_runtime .utils .uri_validator import validate_uri
17
+ from linkml_runtime .utils .uri_validator import validate_uri_reference
18
+ from linkml_runtime .utils .uri_validator import validate_curie
19
+
16
20
# Reference Decimal to make sure it stays in the imports
17
21
_z = Decimal (1 )
18
22
@@ -105,17 +109,21 @@ def is_valid(cls, v: Union[str, URIRef, "Curie", "URIorCURIE"]) -> bool:
105
109
if not isinstance (v , (str , URIRef , Curie , URIorCURIE )):
106
110
return False
107
111
v = str (v )
108
- if ':' in v and '://' not in v :
109
- return URIorCURIE .is_curie (v )
112
+ if validate_uri (v ):
113
+ return True
114
+ elif validate_uri_reference (v ):
115
+ return True
110
116
else :
111
- return URI . is_valid (v )
117
+ return URIorCURIE . is_curie (v )
112
118
113
119
@staticmethod
114
120
def is_absolute (v : str ) -> bool :
115
121
return bool (urlparse (v ).netloc )
116
122
117
123
@staticmethod
118
124
def is_curie (v : str , nsm : Optional [Namespaces ] = None ) -> bool :
125
+ if not validate_curie (v ):
126
+ return False
119
127
if ':' in v and '://' not in v :
120
128
ns , ln = v .split (':' , 1 )
121
129
return len (ns ) == 0 or (NCName .is_valid (ns ) and
@@ -136,13 +144,14 @@ def __init__(self, v: str) -> None:
136
144
raise ValueError (f"'{ v } ': is not a valid URI" )
137
145
super ().__init__ (v )
138
146
139
- # this is more inclusive than the W3C specification
140
- #uri_re = re.compile("^[A-Za-z]\\S*$")
141
- uri_re = re .compile ("^\\ S+$" )
142
-
143
147
@classmethod
144
148
def is_valid (cls , v : str ) -> bool :
145
- return v is not None and not URIorCURIE .is_curie (v ) and cls .uri_re .match (v )
149
+ if validate_uri (v ):
150
+ return True
151
+ elif validate_uri_reference (v ):
152
+ return True
153
+ else :
154
+ return False
146
155
147
156
148
157
class Curie (URIorCURIE ):
@@ -174,6 +183,8 @@ def ns_ln(cls, v: str) -> Optional[Tuple[str, str]]:
174
183
175
184
@classmethod
176
185
def is_valid (cls , v : str ) -> bool :
186
+ if not validate_curie (v ):
187
+ return False
177
188
pnln = cls .ns_ln (v )
178
189
#return pnln is not None and (not pnln[0] or isinstance(pnln[0], PN_PREFIX))
179
190
return pnln is not None
0 commit comments