MCPcopy
hub / github.com/encode/starlette / url_path_for

Method url_path_for

starlette/routing.py:486–507  ·  view source on GitHub ↗
(self, name: str, /, **path_params: Any)

Source from the content-addressed store, hash-verified

484 return Match.NONE, {}
485
486 def url_path_for(self, name: str, /, **path_params: Any) -> URLPath:
487 if self.name is not None and name == self.name and "path" in path_params:
488 # 'name' matches "<mount_name>".
489 path = path_params.pop("path")
490 host, remaining_params = replace_params(self.host_format, self.param_convertors, path_params)
491 if not remaining_params:
492 return URLPath(path=path, host=host)
493 elif self.name is None or name.startswith(self.name + ":"):
494 if self.name is None:
495 # No mount name.
496 remaining_name = name
497 else:
498 # 'name' matches "<mount_name>:<child_name>".
499 remaining_name = name[len(self.name) + 1 :]
500 host, remaining_params = replace_params(self.host_format, self.param_convertors, path_params)
501 for route in self.routes or []:
502 try:
503 url = route.url_path_for(remaining_name, **remaining_params)
504 return URLPath(path=str(url), protocol=url.protocol, host=host)
505 except NoMatchFound:
506 pass
507 raise NoMatchFound(name, path_params)
508
509 async def handle(self, scope: Scope, receive: Receive, send: Send) -> None:
510 await self.app(scope, receive, send)

Callers 12

url_forMethod · 0.45
url_path_forMethod · 0.45
url_path_forMethod · 0.45
test_url_path_forFunction · 0.45
test_route_convertersFunction · 0.45
test_url_path_forFunction · 0.45
test_url_forFunction · 0.45
test_host_reverse_urlsFunction · 0.45
test_datetime_convertorFunction · 0.45

Calls 4

URLPathClass · 0.90
replace_paramsFunction · 0.85
NoMatchFoundClass · 0.85
popMethod · 0.45