File: well_known.py

package info (click to toggle)
mautrix-python 0.20.7-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,812 kB
  • sloc: python: 19,103; makefile: 16
file content (49 lines) | stat: -rw-r--r-- 1,553 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright (c) 2022 Tulir Asokan
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from .base import MatrixResponseError


class WellKnownError(MatrixResponseError):
    """
    An error that occurred during server discovery.

    https://matrix.org/docs/spec/client_server/latest#get-well-known-matrix-client
    """

    pass


class WellKnownUnexpectedStatus(WellKnownError):
    def __init__(self, status: int) -> None:
        super().__init__(f"Unexpected status code {status} when fetching .well-known file")
        self.status = status


class WellKnownNotJSON(WellKnownError):
    def __init__(self) -> None:
        super().__init__(".well-known response was not JSON")


class WellKnownMissingHomeserver(WellKnownError):
    def __init__(self) -> None:
        super().__init__("No homeserver found in .well-known response")


class WellKnownNotURL(WellKnownError):
    def __init__(self) -> None:
        super().__init__("Homeserver base URL in .well-known response was not a valid URL")


class WellKnownUnsupportedScheme(WellKnownError):
    def __init__(self, scheme: str) -> None:
        super().__init__(f"URL in .well-known response has unsupported scheme {scheme}")


class WellKnownInvalidVersionsResponse(WellKnownError):
    def __init__(self) -> None:
        super().__init__(
            "URL in .well-known response didn't respond to versions endpoint properly"
        )