BlueprintSetupState Class — flask Architecture
Architecture documentation for the BlueprintSetupState class in blueprints.py from the flask codebase.
Entity Profile
Dependency Diagram
graph TD e57fb048_2e7e_7939_8012_b7bdd3145ba8["BlueprintSetupState"] 758a865d_0775_4c38_5582_499379448d06["blueprints.py"] e57fb048_2e7e_7939_8012_b7bdd3145ba8 -->|defined in| 758a865d_0775_4c38_5582_499379448d06 98006bb3_985f_40a2_29d1_c25b4f5b82cc["__init__()"] e57fb048_2e7e_7939_8012_b7bdd3145ba8 -->|method| 98006bb3_985f_40a2_29d1_c25b4f5b82cc a095b8ad_24db_e31f_c7dd_d94b4dc565d0["add_url_rule()"] e57fb048_2e7e_7939_8012_b7bdd3145ba8 -->|method| a095b8ad_24db_e31f_c7dd_d94b4dc565d0
Relationship Graph
Source Code
src/flask/sansio/blueprints.py lines 34–116
class BlueprintSetupState:
"""Temporary holder object for registering a blueprint with the
application. An instance of this class is created by the
:meth:`~flask.Blueprint.make_setup_state` method and later passed
to all register callback functions.
"""
def __init__(
self,
blueprint: Blueprint,
app: App,
options: t.Any,
first_registration: bool,
) -> None:
#: a reference to the current application
self.app = app
#: a reference to the blueprint that created this setup state.
self.blueprint = blueprint
#: a dictionary with all options that were passed to the
#: :meth:`~flask.Flask.register_blueprint` method.
self.options = options
#: as blueprints can be registered multiple times with the
#: application and not everything wants to be registered
#: multiple times on it, this attribute can be used to figure
#: out if the blueprint was registered in the past already.
self.first_registration = first_registration
subdomain = self.options.get("subdomain")
if subdomain is None:
subdomain = self.blueprint.subdomain
#: The subdomain that the blueprint should be active for, ``None``
#: otherwise.
self.subdomain = subdomain
url_prefix = self.options.get("url_prefix")
if url_prefix is None:
url_prefix = self.blueprint.url_prefix
#: The prefix that should be used for all URLs defined on the
#: blueprint.
self.url_prefix = url_prefix
self.name = self.options.get("name", blueprint.name)
self.name_prefix = self.options.get("name_prefix", "")
#: A dictionary with URL defaults that is added to each and every
#: URL that was defined with the blueprint.
self.url_defaults = dict(self.blueprint.url_values_defaults)
self.url_defaults.update(self.options.get("url_defaults", ()))
def add_url_rule(
self,
rule: str,
endpoint: str | None = None,
view_func: ft.RouteCallable | None = None,
**options: t.Any,
) -> None:
"""A helper method to register a rule (and optionally a view function)
to the application. The endpoint is automatically prefixed with the
blueprint's name.
"""
if self.url_prefix is not None:
if rule:
rule = "/".join((self.url_prefix.rstrip("/"), rule.lstrip("/")))
else:
rule = self.url_prefix
options.setdefault("subdomain", self.subdomain)
if endpoint is None:
endpoint = _endpoint_from_view_func(view_func) # type: ignore
defaults = self.url_defaults
if "defaults" in options:
defaults = dict(defaults, **options.pop("defaults"))
self.app.add_url_rule(
rule,
f"{self.name_prefix}.{self.name}.{endpoint}".lstrip("."),
view_func,
defaults=defaults,
Domain
Defined In
Source
Frequently Asked Questions
What is the BlueprintSetupState class?
BlueprintSetupState is a class in the flask codebase, defined in src/flask/sansio/blueprints.py.
Where is BlueprintSetupState defined?
BlueprintSetupState is defined in src/flask/sansio/blueprints.py at line 34.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free