MCPcopy
hub / github.com/pallets/werkzeug / bind

Method bind

src/werkzeug/routing/map.py:183–250  ·  src/werkzeug/routing/map.py::Map.bind

Return a new :class:`MapAdapter` with the details specified to the call. Note that `script_name` will default to ``'/'`` if not further specified or `None`. The `server_name` at least is a requirement because the HTTP RFC requires absolute URLs for redirects and so all

(
        self,
        server_name: str,
        script_name: str | None = None,
        subdomain: str | None = None,
        url_scheme: str = "http",
        default_method: str = "GET",
        path_info: str | None = None,
        query_args: t.Mapping[str, t.Any] | str | None = None,
    )

Source from the content-addressed store, hash-verified

181 self._remap = True
182
183 def bind(
184 self,
185 server_name: str,
186 script_name: str | None = None,
187 subdomain: str | None = None,
188 url_scheme: str = class="st">"http",
189 default_method: str = class="st">"GET",
190 path_info: str | None = None,
191 query_args: t.Mapping[str, t.Any] | str | None = None,
192 ) -> MapAdapter:
193 class="st">"""Return a new :class:`MapAdapter` with the details specified to the
194 call. Note that `script_name` will default to ``&class="cm">#x27;/'`` if not further
195 specified or `None`. The `server_name` at least is a requirement
196 because the HTTP RFC requires absolute URLs for redirects and so all
197 redirect exceptions raised by Werkzeug will contain the full canonical
198 URL.
199
200 If no path_info is passed to :meth:`match` it will use the default path
201 info passed to bind. While this doesn&class="cm">#x27;t really make sense for
202 manual bind calls, it&class="cm">#x27;s useful if you bind a map to a WSGI
203 environment which already contains the path info.
204
205 `subdomain` will default to the `default_subdomain` for this map if
206 no defined. If there is no `default_subdomain` you cannot use the
207 subdomain feature.
208
209 .. versionchanged:: 1.0
210 If ``url_scheme`` is ``ws`` or ``wss``, only WebSocket rules
211 will match.
212
213 .. versionchanged:: 0.15
214 ``path_info`` defaults to ``&class="cm">#x27;/'`` if ``None``.
215
216 .. versionchanged:: 0.8
217 ``query_args`` can be a string.
218
219 .. versionchanged:: 0.7
220 Added ``query_args``.
221 class="st">"""
222 server_name = server_name.lower()
223 if self.host_matching:
224 if subdomain is not None:
225 raise RuntimeError(class="st">"host matching enabled and a subdomain was provided")
226 elif subdomain is None:
227 subdomain = self.default_subdomain
228 if script_name is None:
229 script_name = class="st">"/"
230 if path_info is None:
231 path_info = class="st">"/"
232
233 class="cm"># Port isn't part of IDNA, and might push a name over the 63 octet limit.
234 server_name, port_sep, port = server_name.partition(class="st">":")
235
236 try:
237 server_name = server_name.encode(class="st">"idna").decode(class="st">"ascii")
238 except UnicodeError as e:
239 raise BadHost() from e
240

Callers 15

test_basic_routingFunction · 0.95
test_merge_slashes_matchFunction · 0.95
test_merge_slashes_buildFunction · 0.95
test_basic_buildingFunction · 0.95
test_long_buildFunction · 0.95
test_defaultsFunction · 0.95
test_negativeFunction · 0.95
test_greedyFunction · 0.95
test_pathFunction · 0.95

Calls 2

BadHostClass · 0.85
MapAdapterClass · 0.85

Tested by 15

test_basic_routingFunction · 0.76
test_merge_slashes_matchFunction · 0.76
test_merge_slashes_buildFunction · 0.76
test_basic_buildingFunction · 0.76
test_long_buildFunction · 0.76
test_defaultsFunction · 0.76
test_negativeFunction · 0.76
test_greedyFunction · 0.76
test_pathFunction · 0.76