Normalize server URL: strip XC API endpoints and query params, preserve base path.
(url)
| 7 | |
| 8 | |
| 9 | def normalize_server_url(url): |
| 10 | """Normalize server URL: strip XC API endpoints and query params, preserve base path.""" |
| 11 | if not url: |
| 12 | return url |
| 13 | |
| 14 | from urllib.parse import urlparse, urlunparse |
| 15 | |
| 16 | parsed = urlparse(url.strip()) |
| 17 | path = parsed.path.rstrip('/') |
| 18 | |
| 19 | # XC API endpoints are always .php files; legitimate base paths never are. |
| 20 | # Stripping the trailing segment when it ends in .php handles any pasted API URL. |
| 21 | last_segment = path.rsplit('/', 1)[-1] |
| 22 | if last_segment.endswith('.php'): |
| 23 | path = path[:-(len(last_segment) + 1)] if '/' in path else '' |
| 24 | |
| 25 | return urlunparse((parsed.scheme, parsed.netloc, path, '', '', '')) |
| 26 | |
| 27 | |
| 28 | class Client: |
no outgoing calls