Files
django-stubs/django-stubs/http/response.pyi
2019-01-06 21:00:01 +03:00

154 lines
5.3 KiB
Python

# Stubs for django.http.response (Python 3.5)
import datetime
from io import BytesIO
from json import JSONEncoder
from typing import Any, Dict, Iterable, Iterator, List, Optional, overload, Tuple, Type, Union
import six
from django.core.handlers.wsgi import WSGIRequest
from django.http.cookie import SimpleCookie
from django.test.client import Client
from django.template import Context, Template
from django.urls import ResolverMatch
class BadHeaderError(ValueError): ...
class HttpResponseBase(six.Iterator):
status_code = ... # type: int
cookies = ... # type: SimpleCookie
closed = ... # type: bool
reason_phrase = ... # type: str
charset = ... # type: str
def __init__(
self, content_type: str = None, status: int = None, reason: str = None, charset: str = None
) -> None: ...
def serialize_headers(self) -> bytes: ...
def __bytes__(self) -> bytes: ...
def __setitem__(self, header: str, value: Union[str, bytes]) -> None: ...
def __delitem__(self, header: str) -> None: ...
def __getitem__(self, header: str) -> str: ...
def has_header(self, header: str) -> bool: ...
def __contains__(self, item: object) -> bool: ...
def items(self) -> Iterable[Tuple[str, str]]: ...
@overload
def get(self, header: str, alternate: str) -> str: ...
@overload
def get(self, header: str) -> Optional[str]: ...
def set_cookie(
self,
key: str,
value: str = "",
max_age: int = None,
expires: Union[str, datetime.datetime] = None,
path: str = "",
domain: str = None,
secure: bool = False,
httponly: bool = False,
) -> None: ...
def setdefault(self, key: str, value: str) -> None: ...
def set_signed_cookie(self, key: str, value: str, salt: str = "", **kwargs: Any) -> None: ...
def delete_cookie(self, key: str, path: str = "", domain: str = None) -> None: ...
def make_bytes(self, value: object) -> bytes: ...
def close(self) -> None: ...
def write(self, content: object) -> None: ...
def flush(self) -> None: ...
def tell(self) -> int: ...
def readable(self) -> bool: ...
def seekable(self) -> bool: ...
def writable(self) -> bool: ...
def writelines(self, lines: Iterable[object]) -> None: ...
class HttpResponse(HttpResponseBase):
client: Client
closed: bool
context: Optional[Context]
csrf_cookie_set: bool
redirect_chain: List[Tuple[str, int]]
request: Dict[str, Any]
resolver_match: ResolverMatch
sameorigin: bool
status_code: int
templates: List[Template]
test_server_port: str
test_was_secure_request: bool
wsgi_request: WSGIRequest
xframe_options_exempt: bool
streaming: bool = ...
def __init__(self, content: object = ..., *args: Any, **kwargs: Any) -> None: ...
def serialize(self) -> bytes: ...
@property
def content(self) -> bytes: ...
@content.setter
def content(self, value: Any) -> None: ...
def __iter__(self) -> Iterator[bytes]: ...
def tell(self) -> int: ...
def getvalue(self) -> bytes: ...
def writable(self) -> bool: ...
@property
def url(self) -> str: ...
def json(self) -> Dict[str, Any]: ...
class StreamingHttpResponse(HttpResponseBase):
def __init__(self, streaming_content: Iterable[bytes] = ..., *args: Any, **kwargs: Any) -> None: ...
@property
def content(self) -> bytes: ...
@content.setter
def content(self, value: Any) -> None: ...
@property
def streaming_content(self) -> Iterator[bytes]: ...
@streaming_content.setter
def streaming_content(self, value: Iterable[bytes]) -> None: ...
def __iter__(self) -> Iterator[bytes]: ...
def getvalue(self) -> bytes: ...
class FileResponse(StreamingHttpResponse):
client: Client
closed: bool
context: None
file_to_stream: Optional[BytesIO]
request: Dict[str, str]
resolver_match: ResolverMatch
templates: List[Any]
wsgi_request: WSGIRequest
block_size: int = ...
as_attachment: bool = ...
filename: str = ...
def __init__(self, *args: Any, as_attachment: bool = ..., filename: str = ..., **kwargs: Any) -> None: ...
def set_headers(self, filelike: BytesIO) -> None: ...
def json(self) -> Dict[str, Any]: ...
class HttpResponseRedirectBase(HttpResponse):
allowed_schemes = ... # type: List[str]
def __init__(self, redirect_to: str, *args: Any, **kwargs: Any) -> None: ...
@property
def url(self) -> str: ...
class HttpResponseRedirect(HttpResponseRedirectBase): ...
class HttpResponsePermanentRedirect(HttpResponseRedirectBase): ...
class HttpResponseNotModified(HttpResponse):
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
class HttpResponseBadRequest(HttpResponse): ...
class HttpResponseNotFound(HttpResponse): ...
class HttpResponseForbidden(HttpResponse): ...
class HttpResponseNotAllowed(HttpResponse):
def __init__(self, permitted_methods: Iterable[str], *args: Any, **kwargs: Any) -> None: ...
class HttpResponseGone(HttpResponse): ...
class HttpResponseServerError(HttpResponse): ...
class Http404(Exception): ...
class JsonResponse(HttpResponse):
def __init__(
self,
data: object,
encoder: Type[JSONEncoder] = ...,
safe: bool = True,
json_dumps_params: Dict[str, Any] = None,
**kwargs: Any
) -> None: ...