Home / Function/ open() — flask Function Reference

open() — flask Function Reference

Architecture documentation for the open() function in testing.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  3dfbf89e_0efa_e73a_439f_b07e59e5d57d["open()"]
  bd3a5eb6_81cb_6392_c9b8_19dcbec7785f["FlaskClient"]
  3dfbf89e_0efa_e73a_439f_b07e59e5d57d -->|defined in| bd3a5eb6_81cb_6392_c9b8_19dcbec7785f
  c92a3a8a_766d_75a0_8dd5_ab00df390e5d["open_resource()"]
  c92a3a8a_766d_75a0_8dd5_ab00df390e5d -->|calls| 3dfbf89e_0efa_e73a_439f_b07e59e5d57d
  5a6d3d45_9ce0_b4dc_5aad_19ba0e2d3bd8["open_instance_resource()"]
  5a6d3d45_9ce0_b4dc_5aad_19ba0e2d3bd8 -->|calls| 3dfbf89e_0efa_e73a_439f_b07e59e5d57d
  1138f3ac_9053_e93b_3cc9_fa68bae97450["_copy_environ()"]
  3dfbf89e_0efa_e73a_439f_b07e59e5d57d -->|calls| 1138f3ac_9053_e93b_3cc9_fa68bae97450
  4e0af686_482d_2acf_be5d_79822774d7b0["_request_from_builder_args()"]
  3dfbf89e_0efa_e73a_439f_b07e59e5d57d -->|calls| 4e0af686_482d_2acf_be5d_79822774d7b0
  style 3dfbf89e_0efa_e73a_439f_b07e59e5d57d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/testing.py lines 204–247

    def open(
        self,
        *args: t.Any,
        buffered: bool = False,
        follow_redirects: bool = False,
        **kwargs: t.Any,
    ) -> TestResponse:
        if args and isinstance(
            args[0], (werkzeug.test.EnvironBuilder, dict, BaseRequest)
        ):
            if isinstance(args[0], werkzeug.test.EnvironBuilder):
                builder = copy(args[0])
                builder.environ_base = self._copy_environ(builder.environ_base or {})  # type: ignore[arg-type]
                request = builder.get_request()
            elif isinstance(args[0], dict):
                request = EnvironBuilder.from_environ(
                    args[0], app=self.application, environ_base=self._copy_environ({})
                ).get_request()
            else:
                # isinstance(args[0], BaseRequest)
                request = copy(args[0])
                request.environ = self._copy_environ(request.environ)
        else:
            # request is None
            request = self._request_from_builder_args(args, kwargs)

        # Pop any previously preserved contexts. This prevents contexts
        # from being preserved across redirects or multiple requests
        # within a single block.
        self._context_stack.close()

        response = super().open(
            request,
            buffered=buffered,
            follow_redirects=follow_redirects,
        )
        response.json_module = self.application.json  # type: ignore[assignment]

        # Re-push contexts that were preserved during the request.
        for cm in self._new_contexts:
            self._context_stack.enter_context(cm)

        self._new_contexts.clear()
        return response

Subdomains

Frequently Asked Questions

What does open() do?
open() is a function in the flask codebase, defined in src/flask/testing.py.
Where is open() defined?
open() is defined in src/flask/testing.py at line 204.
What does open() call?
open() calls 2 function(s): _copy_environ, _request_from_builder_args.
What calls open()?
open() is called by 2 function(s): open_instance_resource, open_resource.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free