Skip to content

Commit 472c5cd

Browse files
committed
Make the splitting logic more straightforward
1 parent 391b9bc commit 472c5cd

File tree

1 file changed

+8
-6
lines changed
  • repo2docker/contentproviders

1 file changed

+8
-6
lines changed

repo2docker/contentproviders/ckan.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import re
21
from datetime import datetime, timedelta, timezone
32
from os import path
43
from urllib.parse import urlparse
@@ -37,22 +36,25 @@ def _request(self, url, **kwargs):
3736
return self.session.get(url, **kwargs)
3837

3938
urlopen = _request
40-
url_regex = r"/dataset/[a-z0-9_\\-]*$"
4139

4240
def detect(self, source, ref=None, extra_args=None):
4341
"""Trigger this provider for things that resolve to a CKAN dataset."""
4442
parsed_url = urlparse(source)
4543
if not parsed_url.netloc:
4644
return None
4745

48-
api_url = parsed_url._replace(
49-
path=re.sub(self.url_regex, "/api/3/action/", parsed_url.path)
50-
).geturl()
46+
url_parts = parsed_url.path.split("/")
47+
if url_parts[-2] == "dataset":
48+
self.dataset_id = url_parts[-1]
49+
else:
50+
return None
51+
52+
api_url_path = "/api/3/action/"
53+
api_url = parsed_url._replace(path=api_url_path).geturl()
5154

5255
status_show_url = f"{api_url}status_show"
5356
resp = self.urlopen(status_show_url)
5457
if resp.status_code == 200:
55-
self.dataset_id = parsed_url.path.rsplit("/", maxsplit=1)[1]
5658
self.version = self._fetch_version(api_url)
5759
return {
5860
"dataset_id": self.dataset_id,

0 commit comments

Comments
 (0)