Determine whether the given object is a valid URL string.
(obj: Any)
| 12 | import uuid |
| 13 | |
| 14 | def 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 | |
| 30 | def open_url(url: str, cache_dir: str = None, num_attempts: int = 10, verbose: bool = True, return_path: bool = False) -> Any: |