from functools import wraps from typing import TYPE_CHECKING
if TYPE_CHECKING: # pragma: no cover import os
from typing import Any from typing import BinaryIO from typing import Callable from typing import Dict from typing import List from typing import Optional from typing import Type from typing import Union from responses import FirstMatchRegistry from responses import HTTPAdapter from responses import PreparedRequest from responses import models from responses import _F from responses import BaseResponse
from io import TextIOWrapper
import yaml
from responses import RequestsMock from responses import Response from responses import _real_send from responses.registries import OrderedRegistry
def _remove_nones(d: "Any") -> "Any": if isinstance(d, dict): return {k: _remove_nones(v) for k, v in d.items() if v isnotNone} if isinstance(d, list): return [_remove_nones(i) for i in d] return d
def _remove_default_headers(data: "Any") -> "Any": """
It would be too verbose to store these headers in the file generated by the
record functionality. """ if isinstance(data, dict):
keys_to_remove = [ "Content-Length", "Content-Type", "Date", "Server", "Connection", "Content-Encoding",
] for i, response in enumerate(data["responses"]): for key in keys_to_remove: if key in response["response"]["headers"]: del data["responses"][i]["response"]["headers"][key] ifnot response["response"]["headers"]: del data["responses"][i]["response"]["headers"] return data
def _dump(
registered: "List[BaseResponse]",
destination: "Union[BinaryIO, TextIOWrapper]",
dumper: "Callable[[Union[Dict[Any, Any], List[Any]], Union[BinaryIO, TextIOWrapper]], Any]",
) -> None:
data: Dict[str, Any] = {"responses": []} for rsp in registered: try:
content_length = rsp.auto_calculate_content_length # type: ignore[attr-defined]
data["responses"].append(
{ "response": { "method": rsp.method, "url": rsp.url, "body": rsp.body, "status": rsp.status, "headers": rsp.headers, "content_type": rsp.content_type, "auto_calculate_content_length": content_length,
}
}
) except AttributeError as exc: # pragma: no cover raise AttributeError( "Cannot dump response object." "Probably you use custom Response object that is missing required attributes"
) from exc
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.