Skip to content

Commit 42fe72a

Browse files
committed
Update utils.py
1 parent 5bf0bcf commit 42fe72a

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

src/bioregistry/app/utils.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ def _search(manager_: Manager, q: str) -> list[tuple[str, str]]:
8181
return sorted(results)
8282

8383

84-
def _autocomplete(manager_: Manager, q: str, url_prefix: str | None = None) -> Mapping[str, Any]:
84+
def _autocomplete(manager_: Manager, q: str, base_url: str | None = None) -> Mapping[str, Any]:
8585
r"""Run the autocomplete algorithm.
8686
8787
:param manager_: A manager
8888
:param q: The query string
89-
:param url_prefix:
89+
:param base_url:
9090
The explicit URL prefix. If not used, relative paths are generated. Introduced to
9191
solve https://github.com/biopragmatics/bioregistry/issues/596.
9292
:return: A dictionary with the autocomplete results.
@@ -102,6 +102,9 @@ def _autocomplete(manager_: Manager, q: str, url_prefix: str | None = None) -> M
102102
>>> _autocomplete(manager, "chebi")
103103
{'query': 'chebi', 'results': [('chebi', ''), ('chebi', 'chebiid'), ('goche', 'gochebi')], 'success': True, 'reason': 'matched prefix', 'url': '/chebi'}
104104
105+
>>> _autocomplete(manager, "http://purl.allotrope.org/ontologies/equipment#AFE_")
106+
{'query': 'http://purl.allotrope.org/ontologies/equipment#AFE_', 'results': [('allotrope.equiment', '')], 'success': True, 'reason': 'matched prefix', 'url': '/allotrope.equiment'}
107+
105108
Not matching the pattern:
106109
107110
>>> _autocomplete(manager, "chebi:NOPE")
@@ -112,15 +115,18 @@ def _autocomplete(manager_: Manager, q: str, url_prefix: str | None = None) -> M
112115
>>> _autocomplete(manager, "chebi:1234")
113116
{'query': 'chebi:1234', 'prefix': 'chebi', 'pattern': '^\\d+$', 'identifier': '1234', 'success': True, 'reason': 'passed validation', 'url': '/chebi:1234'}
114117
"""
115-
if url_prefix is None:
116-
url_prefix = ""
117-
url_prefix = url_prefix.rstrip().rstrip("/")
118+
if base_url is None:
119+
base_url = ""
120+
base_url = base_url.rstrip().rstrip("/")
121+
122+
if q.startswith("https://") or q.startswith("http://"):
123+
raise NotImplementedError
118124

119125
if ":" not in q:
120126
url: str | None
121127
if q in manager_.registry:
122128
reason = "matched prefix"
123-
url = f"{url_prefix}/{q}"
129+
url = f"{base_url}/{q}"
124130
else:
125131
reason = "searched prefix"
126132
url = None
@@ -146,12 +152,12 @@ def _autocomplete(manager_: Manager, q: str, url_prefix: str | None = None) -> M
146152
success = True
147153
reason = "no pattern"
148154
norm_id = resource.standardize_identifier(identifier)
149-
url = f"{url_prefix}/{resource.get_curie(norm_id)}"
155+
url = f"{base_url}/{resource.get_curie(norm_id)}"
150156
elif resource.is_standardizable_identifier(identifier):
151157
success = True
152158
reason = "passed validation"
153159
norm_id = resource.standardize_identifier(identifier)
154-
url = f"{url_prefix}/{resource.get_curie(norm_id)}"
160+
url = f"{base_url}/{resource.get_curie(norm_id)}"
155161
else:
156162
success = False
157163
reason = "failed validation"

0 commit comments

Comments
 (0)