(
base_url: Optional[str], given_url: str
)
| 246 | |
| 247 | |
| 248 | def resolve_base_url( |
| 249 | base_url: Optional[str], given_url: str |
| 250 | ) -> Tuple[str, Optional[str]]: |
| 251 | try: |
| 252 | url = nodelike_urlparse( |
| 253 | urljoin(base_url if base_url is not None else "", given_url) |
| 254 | ) |
| 255 | resolved = urlunparse(url) |
| 256 | # Schema and domain are case-insensitive. |
| 257 | hostname_port = ( |
| 258 | url.hostname or "" |
| 259 | ) # can't use parsed.netloc because it includes userinfo (username:password) |
| 260 | if url.port: |
| 261 | hostname_port += f":{url.port}" |
| 262 | case_insensitive_prefix = f"{url.scheme}://{hostname_port}" |
| 263 | return resolved, case_insensitive_prefix |
| 264 | except Exception: |
| 265 | return given_url, None |
| 266 | |
| 267 | |
| 268 | def nodelike_urlparse(url: str) -> ParseResult: |
no test coverage detected