summaryrefslogtreecommitdiff
path: root/venv/lib/python3.11/site-packages/litestar/exceptions
diff options
context:
space:
mode:
authorcyfraeviolae <cyfraeviolae>2024-04-03 03:10:44 -0400
committercyfraeviolae <cyfraeviolae>2024-04-03 03:10:44 -0400
commit6d7ba58f880be618ade07f8ea080fe8c4bf8a896 (patch)
treeb1c931051ffcebd2bd9d61d98d6233ffa289bbce /venv/lib/python3.11/site-packages/litestar/exceptions
parent4f884c9abc32990b4061a1bb6997b4b37e58ea0b (diff)
venv
Diffstat (limited to 'venv/lib/python3.11/site-packages/litestar/exceptions')
-rw-r--r--venv/lib/python3.11/site-packages/litestar/exceptions/__init__.py42
-rw-r--r--venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/__init__.cpython-311.pycbin0 -> 1358 bytes
-rw-r--r--venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/base_exceptions.cpython-311.pycbin0 -> 4054 bytes
-rw-r--r--venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/dto_exceptions.cpython-311.pycbin0 -> 916 bytes
-rw-r--r--venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/http_exceptions.cpython-311.pycbin0 -> 7746 bytes
-rw-r--r--venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/websocket_exceptions.cpython-311.pycbin0 -> 2405 bytes
-rw-r--r--venv/lib/python3.11/site-packages/litestar/exceptions/base_exceptions.py57
-rw-r--r--venv/lib/python3.11/site-packages/litestar/exceptions/dto_exceptions.py13
-rw-r--r--venv/lib/python3.11/site-packages/litestar/exceptions/http_exceptions.py154
-rw-r--r--venv/lib/python3.11/site-packages/litestar/exceptions/websocket_exceptions.py40
10 files changed, 306 insertions, 0 deletions
diff --git a/venv/lib/python3.11/site-packages/litestar/exceptions/__init__.py b/venv/lib/python3.11/site-packages/litestar/exceptions/__init__.py
new file mode 100644
index 0000000..09065c8
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/litestar/exceptions/__init__.py
@@ -0,0 +1,42 @@
+from .base_exceptions import LitestarException, LitestarWarning, MissingDependencyException, SerializationException
+from .dto_exceptions import DTOFactoryException, InvalidAnnotationException
+from .http_exceptions import (
+ ClientException,
+ HTTPException,
+ ImproperlyConfiguredException,
+ InternalServerException,
+ MethodNotAllowedException,
+ NoRouteMatchFoundException,
+ NotAuthorizedException,
+ NotFoundException,
+ PermissionDeniedException,
+ ServiceUnavailableException,
+ TemplateNotFoundException,
+ TooManyRequestsException,
+ ValidationException,
+)
+from .websocket_exceptions import WebSocketDisconnect, WebSocketException
+
+__all__ = (
+ "ClientException",
+ "DTOFactoryException",
+ "HTTPException",
+ "ImproperlyConfiguredException",
+ "InternalServerException",
+ "InvalidAnnotationException",
+ "LitestarException",
+ "LitestarWarning",
+ "MethodNotAllowedException",
+ "MissingDependencyException",
+ "NoRouteMatchFoundException",
+ "NotAuthorizedException",
+ "NotFoundException",
+ "PermissionDeniedException",
+ "SerializationException",
+ "ServiceUnavailableException",
+ "TemplateNotFoundException",
+ "TooManyRequestsException",
+ "ValidationException",
+ "WebSocketDisconnect",
+ "WebSocketException",
+)
diff --git a/venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/__init__.cpython-311.pyc b/venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/__init__.cpython-311.pyc
new file mode 100644
index 0000000..1538618
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/__init__.cpython-311.pyc
Binary files differ
diff --git a/venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/base_exceptions.cpython-311.pyc b/venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/base_exceptions.cpython-311.pyc
new file mode 100644
index 0000000..efd605d
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/base_exceptions.cpython-311.pyc
Binary files differ
diff --git a/venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/dto_exceptions.cpython-311.pyc b/venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/dto_exceptions.cpython-311.pyc
new file mode 100644
index 0000000..24633ee
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/dto_exceptions.cpython-311.pyc
Binary files differ
diff --git a/venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/http_exceptions.cpython-311.pyc b/venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/http_exceptions.cpython-311.pyc
new file mode 100644
index 0000000..76176d4
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/http_exceptions.cpython-311.pyc
Binary files differ
diff --git a/venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/websocket_exceptions.cpython-311.pyc b/venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/websocket_exceptions.cpython-311.pyc
new file mode 100644
index 0000000..90c2ce2
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/litestar/exceptions/__pycache__/websocket_exceptions.cpython-311.pyc
Binary files differ
diff --git a/venv/lib/python3.11/site-packages/litestar/exceptions/base_exceptions.py b/venv/lib/python3.11/site-packages/litestar/exceptions/base_exceptions.py
new file mode 100644
index 0000000..bbd4040
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/litestar/exceptions/base_exceptions.py
@@ -0,0 +1,57 @@
+from __future__ import annotations
+
+from typing import Any
+
+__all__ = ("MissingDependencyException", "SerializationException", "LitestarException", "LitestarWarning")
+
+
+class LitestarException(Exception):
+ """Base exception class from which all Litestar exceptions inherit."""
+
+ detail: str
+
+ def __init__(self, *args: Any, detail: str = "") -> None:
+ """Initialize ``LitestarException``.
+
+ Args:
+ *args: args are converted to :class:`str` before passing to :class:`Exception`
+ detail: detail of the exception.
+ """
+ str_args = [str(arg) for arg in args if arg]
+ if not detail:
+ if str_args:
+ detail, *str_args = str_args
+ elif hasattr(self, "detail"):
+ detail = self.detail
+ self.detail = detail
+ super().__init__(*str_args)
+
+ def __repr__(self) -> str:
+ if self.detail:
+ return f"{self.__class__.__name__} - {self.detail}"
+ return self.__class__.__name__
+
+ def __str__(self) -> str:
+ return " ".join((*self.args, self.detail)).strip()
+
+
+class MissingDependencyException(LitestarException, ImportError):
+ """Missing optional dependency.
+
+ This exception is raised only when a module depends on a dependency that has not been installed.
+ """
+
+ def __init__(self, package: str, install_package: str | None = None, extra: str | None = None) -> None:
+ super().__init__(
+ f"Package {package!r} is not installed but required. You can install it by running "
+ f"'pip install litestar[{extra or install_package or package}]' to install litestar with the required extra "
+ f"or 'pip install {install_package or package}' to install the package separately"
+ )
+
+
+class SerializationException(LitestarException):
+ """Encoding or decoding of an object failed."""
+
+
+class LitestarWarning(UserWarning):
+ """Base class for Litestar warnings"""
diff --git a/venv/lib/python3.11/site-packages/litestar/exceptions/dto_exceptions.py b/venv/lib/python3.11/site-packages/litestar/exceptions/dto_exceptions.py
new file mode 100644
index 0000000..037e3c6
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/litestar/exceptions/dto_exceptions.py
@@ -0,0 +1,13 @@
+from __future__ import annotations
+
+from litestar.exceptions import LitestarException
+
+__all__ = ("DTOFactoryException", "InvalidAnnotationException")
+
+
+class DTOFactoryException(LitestarException):
+ """Base DTO exception type."""
+
+
+class InvalidAnnotationException(DTOFactoryException):
+ """Unexpected DTO type argument."""
diff --git a/venv/lib/python3.11/site-packages/litestar/exceptions/http_exceptions.py b/venv/lib/python3.11/site-packages/litestar/exceptions/http_exceptions.py
new file mode 100644
index 0000000..bd384c3
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/litestar/exceptions/http_exceptions.py
@@ -0,0 +1,154 @@
+from __future__ import annotations
+
+from http import HTTPStatus
+from typing import Any
+
+from litestar.exceptions.base_exceptions import LitestarException
+from litestar.status_codes import (
+ HTTP_400_BAD_REQUEST,
+ HTTP_401_UNAUTHORIZED,
+ HTTP_403_FORBIDDEN,
+ HTTP_404_NOT_FOUND,
+ HTTP_405_METHOD_NOT_ALLOWED,
+ HTTP_429_TOO_MANY_REQUESTS,
+ HTTP_500_INTERNAL_SERVER_ERROR,
+ HTTP_503_SERVICE_UNAVAILABLE,
+)
+
+__all__ = (
+ "ClientException",
+ "HTTPException",
+ "ImproperlyConfiguredException",
+ "InternalServerException",
+ "MethodNotAllowedException",
+ "NoRouteMatchFoundException",
+ "NotAuthorizedException",
+ "NotFoundException",
+ "PermissionDeniedException",
+ "ServiceUnavailableException",
+ "TemplateNotFoundException",
+ "TooManyRequestsException",
+ "ValidationException",
+)
+
+
+class HTTPException(LitestarException):
+ """Base exception for HTTP error responses.
+
+ These exceptions carry information to construct an HTTP response.
+ """
+
+ status_code: int = HTTP_500_INTERNAL_SERVER_ERROR
+ """Exception status code."""
+ detail: str
+ """Exception details or message."""
+ headers: dict[str, str] | None
+ """Headers to attach to the response."""
+ extra: dict[str, Any] | list[Any] | None
+ """An extra mapping to attach to the exception."""
+
+ def __init__(
+ self,
+ *args: Any,
+ detail: str = "",
+ status_code: int | None = None,
+ headers: dict[str, str] | None = None,
+ extra: dict[str, Any] | list[Any] | None = None,
+ ) -> None:
+ """Initialize ``HTTPException``.
+
+ Set ``detail`` and ``args`` if not provided.
+
+ Args:
+ *args: if ``detail`` kwarg not provided, first arg should be error detail.
+ detail: Exception details or message. Will default to args[0] if not provided.
+ status_code: Exception HTTP status code.
+ headers: Headers to set on the response.
+ extra: An extra mapping to attach to the exception.
+ """
+ super().__init__(*args, detail=detail)
+ self.status_code = status_code or self.status_code
+ self.extra = extra
+ self.headers = headers
+ if not self.detail:
+ self.detail = HTTPStatus(self.status_code).phrase
+ self.args = (f"{self.status_code}: {self.detail}", *self.args)
+
+ def __repr__(self) -> str:
+ return f"{self.status_code} - {self.__class__.__name__} - {self.detail}"
+
+ def __str__(self) -> str:
+ return " ".join(self.args).strip()
+
+
+class ImproperlyConfiguredException(HTTPException, ValueError):
+ """Application has improper configuration."""
+
+
+class ClientException(HTTPException):
+ """Client error."""
+
+ status_code: int = HTTP_400_BAD_REQUEST
+
+
+class ValidationException(ClientException, ValueError):
+ """Client data validation error."""
+
+
+class NotAuthorizedException(ClientException):
+ """Request lacks valid authentication credentials for the requested resource."""
+
+ status_code = HTTP_401_UNAUTHORIZED
+
+
+class PermissionDeniedException(ClientException):
+ """Request understood, but not authorized."""
+
+ status_code = HTTP_403_FORBIDDEN
+
+
+class NotFoundException(ClientException, ValueError):
+ """Cannot find the requested resource."""
+
+ status_code = HTTP_404_NOT_FOUND
+
+
+class MethodNotAllowedException(ClientException):
+ """Server knows the request method, but the target resource doesn't support this method."""
+
+ status_code = HTTP_405_METHOD_NOT_ALLOWED
+
+
+class TooManyRequestsException(ClientException):
+ """Request limits have been exceeded."""
+
+ status_code = HTTP_429_TOO_MANY_REQUESTS
+
+
+class InternalServerException(HTTPException):
+ """Server encountered an unexpected condition that prevented it from fulfilling the request."""
+
+ status_code: int = HTTP_500_INTERNAL_SERVER_ERROR
+
+
+class ServiceUnavailableException(InternalServerException):
+ """Server is not ready to handle the request."""
+
+ status_code = HTTP_503_SERVICE_UNAVAILABLE
+
+
+class NoRouteMatchFoundException(InternalServerException):
+ """A route with the given name could not be found."""
+
+
+class TemplateNotFoundException(InternalServerException):
+ """Referenced template could not be found."""
+
+ def __init__(self, *args: Any, template_name: str) -> None:
+ """Initialize ``TemplateNotFoundException``.
+
+ Args:
+ *args (Any): Passed through to ``super().__init__()`` - should not include ``detail``.
+ template_name (str): Name of template that could not be found.
+ """
+ super().__init__(*args, detail=f"Template {template_name} not found.")
diff --git a/venv/lib/python3.11/site-packages/litestar/exceptions/websocket_exceptions.py b/venv/lib/python3.11/site-packages/litestar/exceptions/websocket_exceptions.py
new file mode 100644
index 0000000..2fed9ca
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/litestar/exceptions/websocket_exceptions.py
@@ -0,0 +1,40 @@
+from typing import Any
+
+from litestar.exceptions.base_exceptions import LitestarException
+from litestar.status_codes import WS_1000_NORMAL_CLOSURE
+
+__all__ = ("WebSocketDisconnect", "WebSocketException")
+
+
+class WebSocketException(LitestarException):
+ """Exception class for websocket related events."""
+
+ code: int
+ """Exception code. For custom exceptions, this should be a number in the 4000+ range. Other codes can be found in
+ ``litestar.status_code`` with the ``WS_`` prefix.
+ """
+
+ def __init__(self, *args: Any, detail: str, code: int = 4500) -> None:
+ """Initialize ``WebSocketException``.
+
+ Args:
+ *args: Any exception args.
+ detail: Exception details.
+ code: Exception code. Should be a number in the >= 1000.
+ """
+ super().__init__(*args, detail=detail)
+ self.code = code
+
+
+class WebSocketDisconnect(WebSocketException):
+ """Exception class for websocket disconnect events."""
+
+ def __init__(self, *args: Any, detail: str, code: int = WS_1000_NORMAL_CLOSURE) -> None:
+ """Initialize ``WebSocketDisconnect``.
+
+ Args:
+ *args: Any exception args.
+ detail: Exception details.
+ code: Exception code. Should be a number in the >= 1000.
+ """
+ super().__init__(*args, detail=detail, code=code)