Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Sep 16, 2024
1 parent 79242d3 commit dac67cf
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 18 deletions.
8 changes: 0 additions & 8 deletions server/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import asyncpg
import httpx
import litestar
from litestar.exceptions import ClientException
from litestar.status_codes import HTTP_400_BAD_REQUEST
from redis.asyncio import Redis
from sslog import logger

Expand Down Expand Up @@ -77,12 +75,6 @@ async def pg_pool_startup() -> None:
AuthorizedRequest = litestar.Request[None, User, Any]


class BadRequestException(ClientException):
"""Server knows the request method, but the target resource doesn't support this method."""

status_code = HTTP_400_BAD_REQUEST


patch_keys: Mapping[str, str] = {
"name": "标题",
"name_cn": "简体中文标题",
Expand Down
2 changes: 1 addition & 1 deletion server/contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from server.auth import require_user_login
from server.base import (
AuthorizedRequest,
BadRequestException,
QueueItem,
Request,
http_client,
Expand All @@ -30,6 +29,7 @@
subject_infobox_queue,
)
from server.config import TURNSTILE_SECRET_KEY, UTC
from server.errors import BadRequestException
from server.model import PatchState, SubjectPatch
from server.router import Router
from server.strings import check_invalid_input_str, contains_invalid_input_str
Expand Down
8 changes: 8 additions & 0 deletions server/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from litestar.exceptions import ClientException
from litestar.status_codes import HTTP_400_BAD_REQUEST


class BadRequestException(ClientException):
"""Server knows the request method, but the target resource doesn't support this method."""

status_code = HTTP_400_BAD_REQUEST
3 changes: 2 additions & 1 deletion server/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from litestar.response import Redirect, Template

from server.auth import require_user_login
from server.base import BadRequestException, Request, disable_cookies_opt, pg
from server.base import Request, disable_cookies_opt, pg
from server.db import fetch_users
from server.errors import BadRequestException
from server.model import PatchState, PatchType
from server.router import Router

Expand Down
2 changes: 1 addition & 1 deletion server/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
from server.auth import require_user_editor
from server.base import (
AuthorizedRequest,
BadRequestException,
User,
http_client,
pg,
session_key_back_to,
)
from server.config import UTC
from server.errors import BadRequestException
from server.model import EpisodePatch, PatchState, PatchType, SubjectPatch
from server.router import Router
from server.strings import check_invalid_input_str
Expand Down
8 changes: 1 addition & 7 deletions server/strings.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import regex
from litestar.exceptions import ClientException
from litestar.status_codes import HTTP_400_BAD_REQUEST


class BadRequestException(ClientException):
"""Server knows the request method, but the target resource doesn't support this method."""

status_code = HTTP_400_BAD_REQUEST
from server.errors import BadRequestException


# stdlib re doesn't support `\p`
Expand Down

0 comments on commit dac67cf

Please sign in to comment.