MCPcopy
hub / github.com/scrapy/scrapy / __init__

Method __init__

scrapy/http/request/json_request.py:27–51  ·  view source on GitHub ↗
(
        self, *args: Any, dumps_kwargs: dict[str, Any] | None = None, **kwargs: Any
    )

Source from the content-addressed store, hash-verified

25 attributes: tuple[str, ...] = (*Request.attributes, "dumps_kwargs")
26
27 def __init__(
28 self, *args: Any, dumps_kwargs: dict[str, Any] | None = None, **kwargs: Any
29 ) -> None:
30 dumps_kwargs = copy.deepcopy(dumps_kwargs) if dumps_kwargs is not None else {}
31 dumps_kwargs.setdefault("sort_keys", True)
32 self._dumps_kwargs: dict[str, Any] = dumps_kwargs
33
34 body_passed = kwargs.get("body") is not None
35 data: Any = kwargs.pop("data", None)
36 data_passed: bool = data is not None
37
38 if body_passed and data_passed:
39 warnings.warn(
40 "Both body and data passed. data will be ignored", stacklevel=2
41 )
42 elif not body_passed and data_passed:
43 kwargs["body"] = self._dumps(data)
44 if "method" not in kwargs:
45 kwargs["method"] = "POST"
46
47 super().__init__(*args, **kwargs)
48 self.headers.setdefault("Content-Type", "application/json")
49 self.headers.setdefault(
50 "Accept", "application/json, text/javascript, */*; q=0.01"
51 )
52
53 @property
54 def dumps_kwargs(self) -> dict[str, Any]:

Callers

nothing calls this directly

Calls 5

_dumpsMethod · 0.95
deepcopyMethod · 0.80
setdefaultMethod · 0.45
getMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected