MCPcopy
hub / github.com/WebODM/WebODM / parse_url

Function parse_url

coreplugins/dronedb/ddb.py:266–302  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

264 }
265
266def parse_url(url):
267
268 # Check if the url is valid
269 # Root folder of dataset: ddb://localhost:5001/admin/4uyyyaxcbvahd7qb
270 # 'test' folder of dataset: ddb://localhost:5001/admin/4uyyyaxcbvahd7qb/test
271 # using http instead of https: ddb+unsafe://localhost:5000/admin/4uyyyaxcbvahd7qb
272 # using hub url: https://localhost:5001/r/admin/4uyyyaxcbvahd7qb
273 # using hub url without /r/ http://localhost:5000/admin/4uyyyaxcbvahd7qb/test
274
275 p = urlparse(url)
276 segments = p.path.split('/')
277
278 if p.scheme not in ['ddb', 'ddb+unsafe', 'http', 'https']:
279 raise ValueError("Invalid URL scheme.")
280
281 if p.netloc == '':
282 raise ValueError("Invalid URL.")
283
284 scheme = p.scheme
285
286 # used to skip the /r/: if ddb url we have no /r/ instead if http we have it
287 if p.scheme == 'ddb':
288 scheme = 'https'
289 elif p.scheme == 'ddb+unsafe':
290 scheme = 'http'
291
292 offset = 1 if segments[1] == 'r' else 0
293
294 if (len(segments) < offset + 3):
295 raise ValueError("Invalid URL.")
296
297 return {
298 'registryUrl': scheme + '://' + p.netloc,
299 'orgSlug': segments[1 + offset],
300 'dsSlug': segments[2 + offset],
301 'folder': '/'.join(segments[3 + offset:])
302 }
303
304class DroneDBException(Exception):
305 def __init__(self, message, res=None):

Callers 2

postMethod · 0.90
verify_urlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected