Check if a path is a URL. Args: path: Path to check Returns: True if the path is a URL, False otherwise
(path: str)
| 125 | return deleted_count |
| 126 | |
| 127 | async def is_url(path: str) -> bool: |
| 128 | """ |
| 129 | Check if a path is a URL. |
| 130 | |
| 131 | Args: |
| 132 | path: Path to check |
| 133 | |
| 134 | Returns: |
| 135 | True if the path is a URL, False otherwise |
| 136 | """ |
| 137 | if not path: |
| 138 | return False |
| 139 | |
| 140 | try: |
| 141 | result = urlparse(path) |
| 142 | # A URL must have both a scheme (http, https) and a network location (domain) |
| 143 | valid_scheme = result.scheme in ['http', 'https', 'ftp', 'ftps'] |
| 144 | has_netloc = bool(result.netloc) |
| 145 | |
| 146 | # Additional check: local file paths may be parsed as URLs on some systems |
| 147 | # Make sure it's not a Windows drive letter (like C:\) |
| 148 | not_windows_path = not (len(result.scheme) == 1 and result.scheme.isalpha() and path[1:3] == ':\\') |
| 149 | |
| 150 | # Make sure it's not a relative file path |
| 151 | not_relative_path = not os.path.exists(path) |
| 152 | |
| 153 | return valid_scheme and has_netloc and not_windows_path and not_relative_path |
| 154 | except Exception: |
| 155 | return False |
| 156 | |
| 157 | async def fetch_url(url: str) -> tuple[str, str | None]: |
| 158 | """ |
no outgoing calls
no test coverage detected