MCPcopy
hub / github.com/alex-damian/pulse / is_url

Function is_url

drive.py:14–27  ·  view source on GitHub ↗

Determine whether the given object is a valid URL string.

(obj: Any)

Source from the content-addressed store, hash-verified

12import uuid
13
14def is_url(obj: Any) -> bool:
15 """Determine whether the given object is a valid URL string."""
16 if not isinstance(obj, str) or not "://" in obj:
17 return False
18 try:
19 res = requests.compat.urlparse(obj)
20 if not res.scheme or not res.netloc or not "." in res.netloc:
21 return False
22 res = requests.compat.urlparse(requests.compat.urljoin(obj, "/"))
23 if not res.scheme or not res.netloc or not "." in res.netloc:
24 return False
25 except:
26 return False
27 return True
28
29
30def open_url(url: str, cache_dir: str = None, num_attempts: int = 10, verbose: bool = True, return_path: bool = False) -> Any:

Callers 1

open_urlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected