MCPcopy
hub / github.com/scrapy/scrapy / _clean_req

Method _clean_req

scrapy/contracts/__init__.py:174–197  ·  view source on GitHub ↗

stop the request from returning objects and records any errors

(
        self, request: Request, method: Callable[..., Any], results: TestResult
    )

Source from the content-addressed store, hash-verified

172 return None
173
174 def _clean_req(
175 self, request: Request, method: Callable[..., Any], results: TestResult
176 ) -> None:
177 """stop the request from returning objects and records any errors"""
178
179 cb = request.callback
180 assert cb is not None
181
182 @wraps(cb)
183 def cb_wrapper(response: Response, **cb_kwargs: Any) -> None:
184 try:
185 output = cb(response, **cb_kwargs)
186 output = list(cast("Iterable[Any]", iterate_spider_output(output)))
187 except Exception:
188 case = _create_testcase(method, "callback")
189 results.addError(case, sys.exc_info())
190
191 def eb_wrapper(failure: Failure) -> None:
192 case = _create_testcase(method, "errback")
193 exc_info = failure.type, failure.value, failure.getTracebackObject()
194 results.addError(case, exc_info) # type: ignore[arg-type]
195
196 request.callback = cb_wrapper
197 request.errback = eb_wrapper
198
199
200def _create_testcase(method: Callable[..., Any], desc: str) -> TestCase:

Callers 1

from_methodMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected