Path 1: 441 calls (0.98)

'flask_test' (318) 'test_config' (22) 'test_basic' (17) 'test_helpers' (10) 'test_async' (8) 'test_templating' (7) 'testapp' (6) 'appname' (6) 'test_r...

None (438) '/foo' (1) '/foo/' (1) '' (1)

'static' (437) '' (2) PosixPath (1) 'static/' (1)

None (440) 'example.com' (1)

False (440) True (1)

False (434) True (7)

'templates' (441)

None (441)

False (441)

'/Users/andrehora/Documents/git/projects-pathspotter/flask/tests' (318) None (123)

1def __init__(
2        self,
3        import_name: str,
4        static_url_path: str | None = None,
5        static_folder: str | os.PathLike | None = "static",
6        static_host: str | None = None,
7        host_matching: bool = False,
8        subdomain_matching: bool = False,
9        template_folder: str | os.PathLike | None = "templates",
10        instance_path: str | None = None,
11        instance_relative_config: bool = False,
12        root_path: str | None = None,
13    ):
14        super().__init__(
15            import_name=import_name,
16            static_folder=static_folder,
17            static_url_path=static_url_path,
18            template_folder=template_folder,
19            root_path=root_path,
20        )
21
22        if instance_path is None:
23            instance_path = self.auto_find_instance_path()
24        elif not os.path.isabs(instance_path):
25            raise ValueError(
26                "If an instance path is provided it must be absolute."
27                " A relative path was given instead."
28            )
29
30        #: Holds the path to the instance folder.
31        #:
32        #: .. versionadded:: 0.8
33        self.instance_path = instance_path
34
35        #: The configuration dictionary as :class:`Config`.  This behaves
36        #: exactly like a regular dictionary but supports additional methods
37        #: to load a config from files.
38        self.config = self.make_config(instance_relative_config)
39
40        #: An instance of :attr:`aborter_class` created by
41        #: :meth:`make_aborter`. This is called by :func:`flask.abort`
42        #: to raise HTTP errors, and can be called directly as well.
43        #:
44        #: .. versionadded:: 2.2
45        #:     Moved from ``flask.abort``, which calls this object.
46        self.aborter = self.make_aborter()
47
48        self.json: JSONProvider = self.json_provider_class(self)
49        """Provides access to JSON methods. Functions in ``flask.json``
50        will call methods on this provider when the application context
51        is active. Used for handling JSON requests and responses.
52
53        An instance of :attr:`json_provider_class`. Can be customized by
54        changing that attribute on a subclass, or by assigning to this
55        attribute afterwards.
56
57        The default, :class:`~flask.json.provider.DefaultJSONProvider`,
58        uses Python's built-in :mod:`json` library. A different provider
59        can use a different JSON library.
60
61        .. versionadded:: 2.2
62        """
63
64        #: A list of functions that are called by
65        #: :meth:`handle_url_build_error` when :meth:`.url_for` raises a
66        #: :exc:`~werkzeug.routing.BuildError`. Each function is called
67        #: with ``error``, ``endpoint`` and ``values``. If a function
68        #: returns ``None`` or raises a ``BuildError``, it is skipped.
69        #: Otherwise, its return value is returned by ``url_for``.
70        #:
71        #: .. versionadded:: 0.9
72        self.url_build_error_handlers: list[
73            t.Callable[[Exception, str, dict[str, t.Any]], str]
74        ] = []
75
76        #: A list of functions that are called when the application context
77        #: is destroyed.  Since the application context is also torn down
78        #: if the request ends this is the place to store code that disconnects
79        #: from databases.
80        #:
81        #: .. versionadded:: 0.9
82        self.teardown_appcontext_funcs: list[ft.TeardownCallable] = []
83
84        #: A list of shell context processor functions that should be run
85        #: when a shell context is created.
86        #:
87        #: .. versionadded:: 0.11
88        self.shell_context_processors: list[ft.ShellContextProcessorCallable] = []
89
90        #: Maps registered blueprint names to blueprint objects. The
91        #: dict retains the order the blueprints were registered in.
92        #: Blueprints can be registered multiple times, this dict does
93        #: not track how often they were attached.
94        #:
95        #: .. versionadded:: 0.7
96        self.blueprints: dict[str, Blueprint] = {}
97
98        #: a place where extensions can store application specific state.  For
99        #: example this is where an extension could store database engines and
100        #: similar things.
101        #:
102        #: The key must match the name of the extension module. For example in
103        #: case of a "Flask-Foo" extension in `flask_foo`, the key would be
104        #: ``'foo'``.
105        #:
106        #: .. versionadded:: 0.7
107        self.extensions: dict = {}
108
109        #: The :class:`~werkzeug.routing.Map` for this instance.  You can use
110        #: this to change the routing converters after the class was created
111        #: but before any routes are connected.  Example::
112        #:
113        #:    from werkzeug.routing import BaseConverter
114        #:
115        #:    class ListConverter(BaseConverter):
116        #:        def to_python(self, value):
117        #:            return value.split(',')
118        #:        def to_url(self, values):
119        #:            return ','.join(super(ListConverter, self).to_url(value)
120        #:                            for value in values)
121        #:
122        #:    app = Flask(__name__)
123        #:    app.url_map.converters['list'] = ListConverter
124        self.url_map = self.url_map_class()
125
126        self.url_map.host_matching = host_matching
127        self.subdomain_matching = subdomain_matching
128
129        # tracks internally if the application already handled at least one
130        # request.
131        self._got_first_request = False
132
133        # Add a static route using the provided static_url_path, static_host,
134        # and static_folder if there is a configured static_folder.
135        # Note we do this without checking if static_folder exists.
136        # For one, it might be created while the server is running (e.g. during
137        # development). Also, Google App Engine stores static files somewhere
138        if self.has_static_folder:
139            assert (
140                bool(static_host) == host_matching
141            ), "Invalid static_host/host_matching combination"
142            # Use a weakref to avoid creating a reference cycle between the app
143            # and the view function (see #3761).
144            self_ref = weakref.ref(self)
145            self.add_url_rule(
146                f"{self.static_url_path}/<path:filename>",
147                endpoint="static",
148                host=static_host,
149                view_func=lambda **kw: self_ref().send_static_file(**kw),  # type: ignore # noqa: B950
150            )
151
152        # Set the name of the Click group in case someone wants to add
153        # the app's commands to another CLI tool.
154        self.cli.name = self.name
            

Path 2: 4 calls (0.01)

'test_cli' (3) 'test_basic' (1)

None (4)

None (4)

None (4)

True (2) False (2)

False (4)

'templates' (4)

None (4)

False (4)

None (4)

1def __init__(
2        self,
3        import_name: str,
4        static_url_path: str | None = None,
5        static_folder: str | os.PathLike | None = "static",
6        static_host: str | None = None,
7        host_matching: bool = False,
8        subdomain_matching: bool = False,
9        template_folder: str | os.PathLike | None = "templates",
10        instance_path: str | None = None,
11        instance_relative_config: bool = False,
12        root_path: str | None = None,
13    ):
14        super().__init__(
15            import_name=import_name,
16            static_folder=static_folder,
17            static_url_path=static_url_path,
18            template_folder=template_folder,
19            root_path=root_path,
20        )
21
22        if instance_path is None:
23            instance_path = self.auto_find_instance_path()
24        elif not os.path.isabs(instance_path):
25            raise ValueError(
26                "If an instance path is provided it must be absolute."
27                " A relative path was given instead."
28            )
29
30        #: Holds the path to the instance folder.
31        #:
32        #: .. versionadded:: 0.8
33        self.instance_path = instance_path
34
35        #: The configuration dictionary as :class:`Config`.  This behaves
36        #: exactly like a regular dictionary but supports additional methods
37        #: to load a config from files.
38        self.config = self.make_config(instance_relative_config)
39
40        #: An instance of :attr:`aborter_class` created by
41        #: :meth:`make_aborter`. This is called by :func:`flask.abort`
42        #: to raise HTTP errors, and can be called directly as well.
43        #:
44        #: .. versionadded:: 2.2
45        #:     Moved from ``flask.abort``, which calls this object.
46        self.aborter = self.make_aborter()
47
48        self.json: JSONProvider = self.json_provider_class(self)
49        """Provides access to JSON methods. Functions in ``flask.json``
50        will call methods on this provider when the application context
51        is active. Used for handling JSON requests and responses.
52
53        An instance of :attr:`json_provider_class`. Can be customized by
54        changing that attribute on a subclass, or by assigning to this
55        attribute afterwards.
56
57        The default, :class:`~flask.json.provider.DefaultJSONProvider`,
58        uses Python's built-in :mod:`json` library. A different provider
59        can use a different JSON library.
60
61        .. versionadded:: 2.2
62        """
63
64        #: A list of functions that are called by
65        #: :meth:`handle_url_build_error` when :meth:`.url_for` raises a
66        #: :exc:`~werkzeug.routing.BuildError`. Each function is called
67        #: with ``error``, ``endpoint`` and ``values``. If a function
68        #: returns ``None`` or raises a ``BuildError``, it is skipped.
69        #: Otherwise, its return value is returned by ``url_for``.
70        #:
71        #: .. versionadded:: 0.9
72        self.url_build_error_handlers: list[
73            t.Callable[[Exception, str, dict[str, t.Any]], str]
74        ] = []
75
76        #: A list of functions that are called when the application context
77        #: is destroyed.  Since the application context is also torn down
78        #: if the request ends this is the place to store code that disconnects
79        #: from databases.
80        #:
81        #: .. versionadded:: 0.9
82        self.teardown_appcontext_funcs: list[ft.TeardownCallable] = []
83
84        #: A list of shell context processor functions that should be run
85        #: when a shell context is created.
86        #:
87        #: .. versionadded:: 0.11
88        self.shell_context_processors: list[ft.ShellContextProcessorCallable] = []
89
90        #: Maps registered blueprint names to blueprint objects. The
91        #: dict retains the order the blueprints were registered in.
92        #: Blueprints can be registered multiple times, this dict does
93        #: not track how often they were attached.
94        #:
95        #: .. versionadded:: 0.7
96        self.blueprints: dict[str, Blueprint] = {}
97
98        #: a place where extensions can store application specific state.  For
99        #: example this is where an extension could store database engines and
100        #: similar things.
101        #:
102        #: The key must match the name of the extension module. For example in
103        #: case of a "Flask-Foo" extension in `flask_foo`, the key would be
104        #: ``'foo'``.
105        #:
106        #: .. versionadded:: 0.7
107        self.extensions: dict = {}
108
109        #: The :class:`~werkzeug.routing.Map` for this instance.  You can use
110        #: this to change the routing converters after the class was created
111        #: but before any routes are connected.  Example::
112        #:
113        #:    from werkzeug.routing import BaseConverter
114        #:
115        #:    class ListConverter(BaseConverter):
116        #:        def to_python(self, value):
117        #:            return value.split(',')
118        #:        def to_url(self, values):
119        #:            return ','.join(super(ListConverter, self).to_url(value)
120        #:                            for value in values)
121        #:
122        #:    app = Flask(__name__)
123        #:    app.url_map.converters['list'] = ListConverter
124        self.url_map = self.url_map_class()
125
126        self.url_map.host_matching = host_matching
127        self.subdomain_matching = subdomain_matching
128
129        # tracks internally if the application already handled at least one
130        # request.
131        self._got_first_request = False
132
133        # Add a static route using the provided static_url_path, static_host,
134        # and static_folder if there is a configured static_folder.
135        # Note we do this without checking if static_folder exists.
136        # For one, it might be created while the server is running (e.g. during
137        # development). Also, Google App Engine stores static files somewhere
138        if self.has_static_folder:
139            assert (
140                bool(static_host) == host_matching
141            ), "Invalid static_host/host_matching combination"
142            # Use a weakref to avoid creating a reference cycle between the app
143            # and the view function (see #3761).
144            self_ref = weakref.ref(self)
145            self.add_url_rule(
146                f"{self.static_url_path}/<path:filename>",
147                endpoint="static",
148                host=static_host,
149                view_func=lambda **kw: self_ref().send_static_file(**kw),  # type: ignore # noqa: B950
150            )
151
152        # Set the name of the Click group in case someone wants to add
153        # the app's commands to another CLI tool.
154        self.cli.name = self.name
            

Path 3: 2 calls (0.0)

'test_basic' (2)

None (2)

'static' (2)

'example.com' (1) None (1)

False (1) True (1)

False (2)

'templates' (2)

None (2)

False (2)

None (2)

AssertionError (2)

1def __init__(
2        self,
3        import_name: str,
4        static_url_path: str | None = None,
5        static_folder: str | os.PathLike | None = "static",
6        static_host: str | None = None,
7        host_matching: bool = False,
8        subdomain_matching: bool = False,
9        template_folder: str | os.PathLike | None = "templates",
10        instance_path: str | None = None,
11        instance_relative_config: bool = False,
12        root_path: str | None = None,
13    ):
14        super().__init__(
15            import_name=import_name,
16            static_folder=static_folder,
17            static_url_path=static_url_path,
18            template_folder=template_folder,
19            root_path=root_path,
20        )
21
22        if instance_path is None:
23            instance_path = self.auto_find_instance_path()
24        elif not os.path.isabs(instance_path):
25            raise ValueError(
26                "If an instance path is provided it must be absolute."
27                " A relative path was given instead."
28            )
29
30        #: Holds the path to the instance folder.
31        #:
32        #: .. versionadded:: 0.8
33        self.instance_path = instance_path
34
35        #: The configuration dictionary as :class:`Config`.  This behaves
36        #: exactly like a regular dictionary but supports additional methods
37        #: to load a config from files.
38        self.config = self.make_config(instance_relative_config)
39
40        #: An instance of :attr:`aborter_class` created by
41        #: :meth:`make_aborter`. This is called by :func:`flask.abort`
42        #: to raise HTTP errors, and can be called directly as well.
43        #:
44        #: .. versionadded:: 2.2
45        #:     Moved from ``flask.abort``, which calls this object.
46        self.aborter = self.make_aborter()
47
48        self.json: JSONProvider = self.json_provider_class(self)
49        """Provides access to JSON methods. Functions in ``flask.json``
50        will call methods on this provider when the application context
51        is active. Used for handling JSON requests and responses.
52
53        An instance of :attr:`json_provider_class`. Can be customized by
54        changing that attribute on a subclass, or by assigning to this
55        attribute afterwards.
56
57        The default, :class:`~flask.json.provider.DefaultJSONProvider`,
58        uses Python's built-in :mod:`json` library. A different provider
59        can use a different JSON library.
60
61        .. versionadded:: 2.2
62        """
63
64        #: A list of functions that are called by
65        #: :meth:`handle_url_build_error` when :meth:`.url_for` raises a
66        #: :exc:`~werkzeug.routing.BuildError`. Each function is called
67        #: with ``error``, ``endpoint`` and ``values``. If a function
68        #: returns ``None`` or raises a ``BuildError``, it is skipped.
69        #: Otherwise, its return value is returned by ``url_for``.
70        #:
71        #: .. versionadded:: 0.9
72        self.url_build_error_handlers: list[
73            t.Callable[[Exception, str, dict[str, t.Any]], str]
74        ] = []
75
76        #: A list of functions that are called when the application context
77        #: is destroyed.  Since the application context is also torn down
78        #: if the request ends this is the place to store code that disconnects
79        #: from databases.
80        #:
81        #: .. versionadded:: 0.9
82        self.teardown_appcontext_funcs: list[ft.TeardownCallable] = []
83
84        #: A list of shell context processor functions that should be run
85        #: when a shell context is created.
86        #:
87        #: .. versionadded:: 0.11
88        self.shell_context_processors: list[ft.ShellContextProcessorCallable] = []
89
90        #: Maps registered blueprint names to blueprint objects. The
91        #: dict retains the order the blueprints were registered in.
92        #: Blueprints can be registered multiple times, this dict does
93        #: not track how often they were attached.
94        #:
95        #: .. versionadded:: 0.7
96        self.blueprints: dict[str, Blueprint] = {}
97
98        #: a place where extensions can store application specific state.  For
99        #: example this is where an extension could store database engines and
100        #: similar things.
101        #:
102        #: The key must match the name of the extension module. For example in
103        #: case of a "Flask-Foo" extension in `flask_foo`, the key would be
104        #: ``'foo'``.
105        #:
106        #: .. versionadded:: 0.7
107        self.extensions: dict = {}
108
109        #: The :class:`~werkzeug.routing.Map` for this instance.  You can use
110        #: this to change the routing converters after the class was created
111        #: but before any routes are connected.  Example::
112        #:
113        #:    from werkzeug.routing import BaseConverter
114        #:
115        #:    class ListConverter(BaseConverter):
116        #:        def to_python(self, value):
117        #:            return value.split(',')
118        #:        def to_url(self, values):
119        #:            return ','.join(super(ListConverter, self).to_url(value)
120        #:                            for value in values)
121        #:
122        #:    app = Flask(__name__)
123        #:    app.url_map.converters['list'] = ListConverter
124        self.url_map = self.url_map_class()
125
126        self.url_map.host_matching = host_matching
127        self.subdomain_matching = subdomain_matching
128
129        # tracks internally if the application already handled at least one
130        # request.
131        self._got_first_request = False
132
133        # Add a static route using the provided static_url_path, static_host,
134        # and static_folder if there is a configured static_folder.
135        # Note we do this without checking if static_folder exists.
136        # For one, it might be created while the server is running (e.g. during
137        # development). Also, Google App Engine stores static files somewhere
138        if self.has_static_folder:
139            assert (
140                bool(static_host) == host_matching
141            ), "Invalid static_host/host_matching combination"
142            # Use a weakref to avoid creating a reference cycle between the app
143            # and the view function (see #3761).
144            self_ref = weakref.ref(self)
145            self.add_url_rule(
146                f"{self.static_url_path}/<path:filename>",
147                endpoint="static",
148                host=static_host,
149                view_func=lambda **kw: self_ref().send_static_file(**kw),  # type: ignore # noqa: B950
150            )
151
152        # Set the name of the Click group in case someone wants to add
153        # the app's commands to another CLI tool.
154        self.cli.name = self.name
            

Path 4: 1 calls (0.0)

'test_instance_config' (1)

None (1)

'static' (1)

None (1)

False (1)

False (1)

'templates' (1)

'instance' (1)

False (1)

None (1)

ValueError (1)

1def __init__(
2        self,
3        import_name: str,
4        static_url_path: str | None = None,
5        static_folder: str | os.PathLike | None = "static",
6        static_host: str | None = None,
7        host_matching: bool = False,
8        subdomain_matching: bool = False,
9        template_folder: str | os.PathLike | None = "templates",
10        instance_path: str | None = None,
11        instance_relative_config: bool = False,
12        root_path: str | None = None,
13    ):
14        super().__init__(
15            import_name=import_name,
16            static_folder=static_folder,
17            static_url_path=static_url_path,
18            template_folder=template_folder,
19            root_path=root_path,
20        )
21
22        if instance_path is None:
23            instance_path = self.auto_find_instance_path()
24        elif not os.path.isabs(instance_path):
25            raise ValueError(
26                "If an instance path is provided it must be absolute."
27                " A relative path was given instead."
28            )
29
30        #: Holds the path to the instance folder.
31        #:
32        #: .. versionadded:: 0.8
33        self.instance_path = instance_path
34
35        #: The configuration dictionary as :class:`Config`.  This behaves
36        #: exactly like a regular dictionary but supports additional methods
37        #: to load a config from files.
38        self.config = self.make_config(instance_relative_config)
39
40        #: An instance of :attr:`aborter_class` created by
41        #: :meth:`make_aborter`. This is called by :func:`flask.abort`
42        #: to raise HTTP errors, and can be called directly as well.
43        #:
44        #: .. versionadded:: 2.2
45        #:     Moved from ``flask.abort``, which calls this object.
46        self.aborter = self.make_aborter()
47
48        self.json: JSONProvider = self.json_provider_class(self)
49        """Provides access to JSON methods. Functions in ``flask.json``
50        will call methods on this provider when the application context
51        is active. Used for handling JSON requests and responses.
52
53        An instance of :attr:`json_provider_class`. Can be customized by
54        changing that attribute on a subclass, or by assigning to this
55        attribute afterwards.
56
57        The default, :class:`~flask.json.provider.DefaultJSONProvider`,
58        uses Python's built-in :mod:`json` library. A different provider
59        can use a different JSON library.
60
61        .. versionadded:: 2.2
62        """
63
64        #: A list of functions that are called by
65        #: :meth:`handle_url_build_error` when :meth:`.url_for` raises a
66        #: :exc:`~werkzeug.routing.BuildError`. Each function is called
67        #: with ``error``, ``endpoint`` and ``values``. If a function
68        #: returns ``None`` or raises a ``BuildError``, it is skipped.
69        #: Otherwise, its return value is returned by ``url_for``.
70        #:
71        #: .. versionadded:: 0.9
72        self.url_build_error_handlers: list[
73            t.Callable[[Exception, str, dict[str, t.Any]], str]
74        ] = []
75
76        #: A list of functions that are called when the application context
77        #: is destroyed.  Since the application context is also torn down
78        #: if the request ends this is the place to store code that disconnects
79        #: from databases.
80        #:
81        #: .. versionadded:: 0.9
82        self.teardown_appcontext_funcs: list[ft.TeardownCallable] = []
83
84        #: A list of shell context processor functions that should be run
85        #: when a shell context is created.
86        #:
87        #: .. versionadded:: 0.11
88        self.shell_context_processors: list[ft.ShellContextProcessorCallable] = []
89
90        #: Maps registered blueprint names to blueprint objects. The
91        #: dict retains the order the blueprints were registered in.
92        #: Blueprints can be registered multiple times, this dict does
93        #: not track how often they were attached.
94        #:
95        #: .. versionadded:: 0.7
96        self.blueprints: dict[str, Blueprint] = {}
97
98        #: a place where extensions can store application specific state.  For
99        #: example this is where an extension could store database engines and
100        #: similar things.
101        #:
102        #: The key must match the name of the extension module. For example in
103        #: case of a "Flask-Foo" extension in `flask_foo`, the key would be
104        #: ``'foo'``.
105        #:
106        #: .. versionadded:: 0.7
107        self.extensions: dict = {}
108
109        #: The :class:`~werkzeug.routing.Map` for this instance.  You can use
110        #: this to change the routing converters after the class was created
111        #: but before any routes are connected.  Example::
112        #:
113        #:    from werkzeug.routing import BaseConverter
114        #:
115        #:    class ListConverter(BaseConverter):
116        #:        def to_python(self, value):
117        #:            return value.split(',')
118        #:        def to_url(self, values):
119        #:            return ','.join(super(ListConverter, self).to_url(value)
120        #:                            for value in values)
121        #:
122        #:    app = Flask(__name__)
123        #:    app.url_map.converters['list'] = ListConverter
124        self.url_map = self.url_map_class()
125
126        self.url_map.host_matching = host_matching
127        self.subdomain_matching = subdomain_matching
128
129        # tracks internally if the application already handled at least one
130        # request.
131        self._got_first_request = False
132
133        # Add a static route using the provided static_url_path, static_host,
134        # and static_folder if there is a configured static_folder.
135        # Note we do this without checking if static_folder exists.
136        # For one, it might be created while the server is running (e.g. during
137        # development). Also, Google App Engine stores static files somewhere
138        if self.has_static_folder:
139            assert (
140                bool(static_host) == host_matching
141            ), "Invalid static_host/host_matching combination"
142            # Use a weakref to avoid creating a reference cycle between the app
143            # and the view function (see #3761).
144            self_ref = weakref.ref(self)
145            self.add_url_rule(
146                f"{self.static_url_path}/<path:filename>",
147                endpoint="static",
148                host=static_host,
149                view_func=lambda **kw: self_ref().send_static_file(**kw),  # type: ignore # noqa: B950
150            )
151
152        # Set the name of the Click group in case someone wants to add
153        # the app's commands to another CLI tool.
154        self.cli.name = self.name
            

Path 5: 1 calls (0.0)

'test_instance_config' (1)

None (1)

'static' (1)

None (1)

False (1)

False (1)

'templates' (1)

'/Users/andrehora/Documents/git/projects-pathspotter/flask/.tox/tmp/py310/test_explicit_instance_paths0/modules_tmp' (1)

False (1)

None (1)

1def __init__(
2        self,
3        import_name: str,
4        static_url_path: str | None = None,
5        static_folder: str | os.PathLike | None = "static",
6        static_host: str | None = None,
7        host_matching: bool = False,
8        subdomain_matching: bool = False,
9        template_folder: str | os.PathLike | None = "templates",
10        instance_path: str | None = None,
11        instance_relative_config: bool = False,
12        root_path: str | None = None,
13    ):
14        super().__init__(
15            import_name=import_name,
16            static_folder=static_folder,
17            static_url_path=static_url_path,
18            template_folder=template_folder,
19            root_path=root_path,
20        )
21
22        if instance_path is None:
23            instance_path = self.auto_find_instance_path()
24        elif not os.path.isabs(instance_path):
25            raise ValueError(
26                "If an instance path is provided it must be absolute."
27                " A relative path was given instead."
28            )
29
30        #: Holds the path to the instance folder.
31        #:
32        #: .. versionadded:: 0.8
33        self.instance_path = instance_path
34
35        #: The configuration dictionary as :class:`Config`.  This behaves
36        #: exactly like a regular dictionary but supports additional methods
37        #: to load a config from files.
38        self.config = self.make_config(instance_relative_config)
39
40        #: An instance of :attr:`aborter_class` created by
41        #: :meth:`make_aborter`. This is called by :func:`flask.abort`
42        #: to raise HTTP errors, and can be called directly as well.
43        #:
44        #: .. versionadded:: 2.2
45        #:     Moved from ``flask.abort``, which calls this object.
46        self.aborter = self.make_aborter()
47
48        self.json: JSONProvider = self.json_provider_class(self)
49        """Provides access to JSON methods. Functions in ``flask.json``
50        will call methods on this provider when the application context
51        is active. Used for handling JSON requests and responses.
52
53        An instance of :attr:`json_provider_class`. Can be customized by
54        changing that attribute on a subclass, or by assigning to this
55        attribute afterwards.
56
57        The default, :class:`~flask.json.provider.DefaultJSONProvider`,
58        uses Python's built-in :mod:`json` library. A different provider
59        can use a different JSON library.
60
61        .. versionadded:: 2.2
62        """
63
64        #: A list of functions that are called by
65        #: :meth:`handle_url_build_error` when :meth:`.url_for` raises a
66        #: :exc:`~werkzeug.routing.BuildError`. Each function is called
67        #: with ``error``, ``endpoint`` and ``values``. If a function
68        #: returns ``None`` or raises a ``BuildError``, it is skipped.
69        #: Otherwise, its return value is returned by ``url_for``.
70        #:
71        #: .. versionadded:: 0.9
72        self.url_build_error_handlers: list[
73            t.Callable[[Exception, str, dict[str, t.Any]], str]
74        ] = []
75
76        #: A list of functions that are called when the application context
77        #: is destroyed.  Since the application context is also torn down
78        #: if the request ends this is the place to store code that disconnects
79        #: from databases.
80        #:
81        #: .. versionadded:: 0.9
82        self.teardown_appcontext_funcs: list[ft.TeardownCallable] = []
83
84        #: A list of shell context processor functions that should be run
85        #: when a shell context is created.
86        #:
87        #: .. versionadded:: 0.11
88        self.shell_context_processors: list[ft.ShellContextProcessorCallable] = []
89
90        #: Maps registered blueprint names to blueprint objects. The
91        #: dict retains the order the blueprints were registered in.
92        #: Blueprints can be registered multiple times, this dict does
93        #: not track how often they were attached.
94        #:
95        #: .. versionadded:: 0.7
96        self.blueprints: dict[str, Blueprint] = {}
97
98        #: a place where extensions can store application specific state.  For
99        #: example this is where an extension could store database engines and
100        #: similar things.
101        #:
102        #: The key must match the name of the extension module. For example in
103        #: case of a "Flask-Foo" extension in `flask_foo`, the key would be
104        #: ``'foo'``.
105        #:
106        #: .. versionadded:: 0.7
107        self.extensions: dict = {}
108
109        #: The :class:`~werkzeug.routing.Map` for this instance.  You can use
110        #: this to change the routing converters after the class was created
111        #: but before any routes are connected.  Example::
112        #:
113        #:    from werkzeug.routing import BaseConverter
114        #:
115        #:    class ListConverter(BaseConverter):
116        #:        def to_python(self, value):
117        #:            return value.split(',')
118        #:        def to_url(self, values):
119        #:            return ','.join(super(ListConverter, self).to_url(value)
120        #:                            for value in values)
121        #:
122        #:    app = Flask(__name__)
123        #:    app.url_map.converters['list'] = ListConverter
124        self.url_map = self.url_map_class()
125
126        self.url_map.host_matching = host_matching
127        self.subdomain_matching = subdomain_matching
128
129        # tracks internally if the application already handled at least one
130        # request.
131        self._got_first_request = False
132
133        # Add a static route using the provided static_url_path, static_host,
134        # and static_folder if there is a configured static_folder.
135        # Note we do this without checking if static_folder exists.
136        # For one, it might be created while the server is running (e.g. during
137        # development). Also, Google App Engine stores static files somewhere
138        if self.has_static_folder:
139            assert (
140                bool(static_host) == host_matching
141            ), "Invalid static_host/host_matching combination"
142            # Use a weakref to avoid creating a reference cycle between the app
143            # and the view function (see #3761).
144            self_ref = weakref.ref(self)
145            self.add_url_rule(
146                f"{self.static_url_path}/<path:filename>",
147                endpoint="static",
148                host=static_host,
149                view_func=lambda **kw: self_ref().send_static_file(**kw),  # type: ignore # noqa: B950
150            )
151
152        # Set the name of the Click group in case someone wants to add
153        # the app's commands to another CLI tool.
154        self.cli.name = self.name