snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
100
zerver/lib/request.py
Normal file
100
zerver/lib/request.py
Normal file
@@ -0,0 +1,100 @@
|
||||
from collections import defaultdict
|
||||
from collections.abc import MutableMapping
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any, Optional
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.utils.translation import gettext as _
|
||||
from typing_extensions import override
|
||||
|
||||
from zerver.lib import rate_limiter
|
||||
from zerver.lib.exceptions import ErrorCode, JsonableError
|
||||
from zerver.lib.notes import BaseNotes
|
||||
from zerver.models import Client, Realm
|
||||
|
||||
if settings.ZILENCER_ENABLED:
|
||||
from zilencer.models import RemoteZulipServer
|
||||
|
||||
|
||||
@dataclass
|
||||
class RequestNotes(BaseNotes[HttpRequest, "RequestNotes"]):
|
||||
"""This class contains extra metadata that Zulip associated with a
|
||||
Django HttpRequest object. See the docstring for BaseNotes for
|
||||
details on how it works.
|
||||
|
||||
Note that most Optional fields will be definitely not None once
|
||||
middleware has run. In the future, we may want to express that in
|
||||
the types by having different types EarlyRequestNotes and
|
||||
post-middleware RequestNotes types, but for now we have a lot
|
||||
of `assert request_notes.foo is not None` when accessing them.
|
||||
"""
|
||||
|
||||
client: Client | None = None
|
||||
client_name: str | None = None
|
||||
client_version: str | None = None
|
||||
log_data: MutableMapping[str, Any] | None = None
|
||||
requester_for_logs: str | None = None
|
||||
# We use realm_cached to indicate whether the realm is cached or not.
|
||||
# Because the default value of realm is None, which can indicate "unset"
|
||||
# and "nonexistence" at the same time.
|
||||
realm: Realm | None = None
|
||||
has_fetched_realm: bool = False
|
||||
set_language: str | None = None
|
||||
ratelimits_applied: list[rate_limiter.RateLimitResult] = field(default_factory=list)
|
||||
query: str | None = None
|
||||
error_format: str | None = None
|
||||
saved_response: HttpResponse | None = None
|
||||
tornado_handler_id: int | None = None
|
||||
processed_parameters: set[str] = field(default_factory=set)
|
||||
remote_server: Optional["RemoteZulipServer"] = None
|
||||
is_webhook_view: bool = False
|
||||
|
||||
@classmethod
|
||||
@override
|
||||
def init_notes(cls) -> "RequestNotes":
|
||||
return RequestNotes()
|
||||
|
||||
|
||||
class RequestConfusingParamsError(JsonableError):
|
||||
code = ErrorCode.REQUEST_CONFUSING_VAR
|
||||
data_fields = ["var_name1", "var_name2"]
|
||||
|
||||
def __init__(self, var_name1: str, var_name2: str) -> None:
|
||||
self.var_name1: str = var_name1
|
||||
self.var_name2: str = var_name2
|
||||
|
||||
@staticmethod
|
||||
@override
|
||||
def msg_format() -> str:
|
||||
return _("Can't decide between '{var_name1}' and '{var_name2}' arguments")
|
||||
|
||||
|
||||
class RequestVariableMissingError(JsonableError):
|
||||
code = ErrorCode.REQUEST_VARIABLE_MISSING
|
||||
data_fields = ["var_name"]
|
||||
|
||||
def __init__(self, var_name: str) -> None:
|
||||
self.var_name: str = var_name
|
||||
|
||||
@staticmethod
|
||||
@override
|
||||
def msg_format() -> str:
|
||||
return _("Missing '{var_name}' argument")
|
||||
|
||||
|
||||
class RequestVariableConversionError(JsonableError):
|
||||
code = ErrorCode.REQUEST_VARIABLE_INVALID
|
||||
data_fields = ["var_name", "bad_value"]
|
||||
|
||||
def __init__(self, var_name: str, bad_value: Any) -> None:
|
||||
self.var_name: str = var_name
|
||||
self.bad_value = bad_value
|
||||
|
||||
@staticmethod
|
||||
@override
|
||||
def msg_format() -> str:
|
||||
return _("Bad value for '{var_name}': {bad_value}")
|
||||
|
||||
|
||||
arguments_map: dict[str, list[str]] = defaultdict(list)
|
||||
Reference in New Issue
Block a user