File: errors.py

package info (click to toggle)
python-authlib 1.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,016 kB
  • sloc: python: 26,998; makefile: 53; sh: 14
file content (40 lines) | stat: -rw-r--r-- 1,085 bytes parent folder | download | duplicates (2)
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
import importlib.metadata

from werkzeug.exceptions import HTTPException

_version = importlib.metadata.version("werkzeug").split(".")[0]

if _version in ("0", "1"):

    class _HTTPException(HTTPException):
        def __init__(self, code, body, headers, response=None):
            super().__init__(None, response)
            self.code = code

            self.body = body
            self.headers = headers

        def get_body(self, environ=None):
            return self.body

        def get_headers(self, environ=None):
            return self.headers
else:

    class _HTTPException(HTTPException):
        def __init__(self, code, body, headers, response=None):
            super().__init__(None, response)
            self.code = code

            self.body = body
            self.headers = headers

        def get_body(self, environ=None, scope=None):
            return self.body

        def get_headers(self, environ=None, scope=None):
            return self.headers


def raise_http_exception(status, body, headers):
    raise _HTTPException(status, body, headers)