response.pyi
  1  import datetime
  2  from io import BytesIO
  3  from json import JSONEncoder
  4  from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Type, Union, overload
  5  
  6  from django.core.handlers.wsgi import WSGIRequest
  7  from django.http.cookie import SimpleCookie
  8  from django.test.client import Client
  9  
 10  from django.template import Context, Template
 11  from django.urls import ResolverMatch
 12  
 13  class BadHeaderError(ValueError): ...
 14  
 15  class HttpResponseBase(Iterable[Any]):
 16      status_code: int = ...
 17      cookies: SimpleCookie = ...
 18      reason_phrase: str = ...
 19      charset: str = ...
 20      closed: bool = ...
 21      def __init__(
 22          self,
 23          content_type: Optional[str] = ...,
 24          status: Optional[int] = ...,
 25          reason: Optional[str] = ...,
 26          charset: Optional[str] = ...,
 27      ) -> None: ...
 28      def serialize_headers(self) -> bytes: ...
 29      def __setitem__(self, header: Union[str, bytes], value: Union[str, bytes, int]) -> None: ...
 30      def __delitem__(self, header: Union[str, bytes]) -> None: ...
 31      def __getitem__(self, header: Union[str, bytes]) -> str: ...
 32      def has_header(self, header: str) -> bool: ...
 33      def items(self) -> Iterable[Tuple[str, str]]: ...
 34      @overload
 35      def get(self, header: Union[str, bytes], alternate: Optional[str]) -> str: ...
 36      @overload
 37      def get(self, header: Union[str, bytes]) -> Optional[str]: ...
 38      def set_cookie(
 39          self,
 40          key: str,
 41          value: str = ...,
 42          max_age: Optional[int] = ...,
 43          expires: Optional[Union[str, datetime.datetime]] = ...,
 44          path: str = ...,
 45          domain: Optional[str] = ...,
 46          secure: bool = ...,
 47          httponly: bool = ...,
 48          samesite: str = ...,
 49      ) -> None: ...
 50      def setdefault(self, key: str, value: str) -> None: ...
 51      def set_signed_cookie(self, key: str, value: str, salt: str = ..., **kwargs: Any) -> None: ...
 52      def delete_cookie(self, key: str, path: str = ..., domain: Optional[str] = ...) -> None: ...
 53      def make_bytes(self, value: object) -> bytes: ...
 54      def close(self) -> None: ...
 55      def write(self, content: Union[str, bytes]) -> None: ...
 56      def flush(self) -> None: ...
 57      def tell(self) -> int: ...
 58      def readable(self) -> bool: ...
 59      def seekable(self) -> bool: ...
 60      def writable(self) -> bool: ...
 61      def writelines(self, lines: Iterable[object]): ...
 62      def __iter__(self) -> Iterator[Any]: ...
 63  
 64  class HttpResponse(HttpResponseBase):
 65      content: Any
 66      csrf_cookie_set: bool
 67      redirect_chain: List[Tuple[str, int]]
 68      sameorigin: bool
 69      test_server_port: str
 70      test_was_secure_request: bool
 71      xframe_options_exempt: bool
 72      streaming: bool = ...
 73      def __init__(self, content: object = ..., *args: Any, **kwargs: Any) -> None: ...
 74      def serialize(self) -> bytes: ...
 75      @property
 76      def url(self) -> str: ...
 77      # Attributes assigned by monkey-patching in test client ClientHandler.__call__()
 78      wsgi_request: WSGIRequest
 79      # Attributes assigned by monkey-patching in test client Client.request()
 80      client: Client
 81      request: Dict[str, Any]
 82      templates: List[Template]
 83      context: Context
 84      resolver_match: ResolverMatch
 85      def json(self) -> Any: ...
 86  
 87  class StreamingHttpResponse(HttpResponseBase):
 88      content: Any
 89      streaming_content: Iterator[Any]
 90      def __init__(self, streaming_content: Iterable[Any] = ..., *args: Any, **kwargs: Any) -> None: ...
 91      def getvalue(self) -> Any: ...
 92  
 93  class FileResponse(StreamingHttpResponse):
 94      client: Client
 95      context: None
 96      file_to_stream: Optional[BytesIO]
 97      request: Dict[str, str]
 98      resolver_match: ResolverMatch
 99      templates: List[Any]
100      wsgi_request: WSGIRequest
101      block_size: int = ...
102      as_attachment: bool = ...
103      filename: str = ...
104      def __init__(self, *args: Any, as_attachment: bool = ..., filename: str = ..., **kwargs: Any) -> None: ...
105      def set_headers(self, filelike: BytesIO) -> None: ...
106      def json(self) -> Dict[str, Any]: ...
107  
108  class HttpResponseRedirectBase(HttpResponse):
109      allowed_schemes: List[str] = ...
110      def __init__(self, redirect_to: str, *args: Any, **kwargs: Any) -> None: ...
111  
112  class HttpResponseRedirect(HttpResponseRedirectBase): ...
113  class HttpResponsePermanentRedirect(HttpResponseRedirectBase): ...
114  
115  class HttpResponseNotModified(HttpResponse):
116      def __init__(self, *args: Any, **kwargs: Any) -> None: ...
117  
118  class HttpResponseBadRequest(HttpResponse): ...
119  class HttpResponseNotFound(HttpResponse): ...
120  class HttpResponseForbidden(HttpResponse): ...
121  
122  class HttpResponseNotAllowed(HttpResponse):
123      def __init__(self, permitted_methods: Iterable[str], *args: Any, **kwargs: Any) -> None: ...
124  
125  class HttpResponseGone(HttpResponse): ...
126  class HttpResponseServerError(HttpResponse): ...
127  class Http404(Exception): ...
128  
129  class JsonResponse(HttpResponse):
130      def __init__(
131          self,
132          data: Any,
133          encoder: Type[JSONEncoder] = ...,
134          safe: bool = ...,
135          json_dumps_params: Optional[Dict[str, Any]] = ...,
136          **kwargs: Any
137      ) -> None: ...