MCPcopy
hub / github.com/tornadoweb/tornado / fetch

Method fetch

tornado/testing.py:406–449  ·  view source on GitHub ↗

Convenience method to synchronously fetch a URL. The given path will be appended to the local server's host and port. Any additional keyword arguments will be passed directly to `.AsyncHTTPClient.fetch` (and so could be used to pass ``method="POST"``, ``body="..."``

(
        self, path: str, raise_error: bool = False, **kwargs: Any
    )

Source from the content-addressed store, hash-verified

404 raise NotImplementedError()
405
406 def fetch(
407 self, path: str, raise_error: bool = False, **kwargs: Any
408 ) -> HTTPResponse:
409 """Convenience method to synchronously fetch a URL.
410
411 The given path will be appended to the local server's host and
412 port. Any additional keyword arguments will be passed directly to
413 `.AsyncHTTPClient.fetch` (and so could be used to pass
414 ``method="POST"``, ``body="..."``, etc).
415
416 If the path begins with http:// or https://, it will be treated as a
417 full URL and will be fetched as-is.
418
419 If ``raise_error`` is ``True``, a `tornado.httpclient.HTTPError` will
420 be raised if the response code is not 200. This is the same behavior
421 as the ``raise_error`` argument to `.AsyncHTTPClient.fetch`, but
422 the default is ``False`` here (it's ``True`` in `.AsyncHTTPClient`)
423 because tests often need to deal with non-200 response codes.
424
425 .. versionchanged:: 5.0
426 Added support for absolute URLs.
427
428 .. versionchanged:: 5.1
429
430 Added the ``raise_error`` argument.
431
432 .. deprecated:: 5.1
433
434 This method currently turns any exception into an
435 `.HTTPResponse` with status code 599. In Tornado 6.0,
436 errors other than `tornado.httpclient.HTTPError` will be
437 passed through, and ``raise_error=False`` will only
438 suppress errors that would be raised due to non-200
439 response codes.
440
441 """
442 if path.lower().startswith(("http://", "https://")):
443 url = path
444 else:
445 url = self.get_url(path)
446 return self.io_loop.run_sync(
447 lambda: self.http_client.fetch(url, raise_error=raise_error, **kwargs),
448 timeout=get_async_test_timeout(),
449 )
450
451 def get_httpserver_options(self) -> Dict[str, Any]:
452 """May be overridden by subclasses to return additional

Callers

nothing calls this directly

Calls 3

get_urlMethod · 0.95
get_async_test_timeoutFunction · 0.85
run_syncMethod · 0.80

Tested by

no test coverage detected