MCPcopy Create free account
hub / github.com/nlweb-ai/NLWeb / is_url

Function is_url

AskAgent/python/data_loading/db_load.py:127–155  ·  view source on GitHub ↗

Check if a path is a URL. Args: path: Path to check Returns: True if the path is a URL, False otherwise

(path: str)

Source from the content-addressed store, hash-verified

125 return deleted_count
126
127async 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
157async def fetch_url(url: str) -> tuple[str, str | None]:
158 """

Callers 6

detect_file_typeFunction · 0.85
loadJsonToDBFunction · 0.85
loadUrlListToDBFunction · 0.85
process_normal_pathFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected