| 47 | """ |
| 48 | |
| 49 | def __init__( |
| 50 | self, |
| 51 | app: Flask, |
| 52 | path: str = "/", |
| 53 | base_url: str | None = None, |
| 54 | subdomain: str | None = None, |
| 55 | url_scheme: str | None = None, |
| 56 | *args: t.Any, |
| 57 | **kwargs: t.Any, |
| 58 | ) -> None: |
| 59 | assert not (base_url or subdomain or url_scheme) or ( |
| 60 | base_url is not None |
| 61 | ) != bool(subdomain or url_scheme), ( |
| 62 | 'Cannot pass "subdomain" or "url_scheme" with "base_url".' |
| 63 | ) |
| 64 | |
| 65 | if base_url is None: |
| 66 | http_host = app.config.get("SERVER_NAME") or "localhost" |
| 67 | app_root = app.config["APPLICATION_ROOT"] |
| 68 | |
| 69 | if subdomain: |
| 70 | http_host = f"{subdomain}.{http_host}" |
| 71 | |
| 72 | if url_scheme is None: |
| 73 | url_scheme = app.config["PREFERRED_URL_SCHEME"] |
| 74 | |
| 75 | url = urlsplit(path) |
| 76 | base_url = ( |
| 77 | f"{url.scheme or url_scheme}://{url.netloc or http_host}" |
| 78 | f"/{app_root.lstrip('/')}" |
| 79 | ) |
| 80 | path = url.path |
| 81 | |
| 82 | if url.query: |
| 83 | path = f"{path}?{url.query}" |
| 84 | |
| 85 | self.app = app |
| 86 | super().__init__(path, base_url, *args, **kwargs) |
| 87 | |
| 88 | def json_dumps(self, obj: t.Any, **kwargs: t.Any) -> str: |
| 89 | """Serialize ``obj`` to a JSON-formatted string. |