MCPcopy Create free account
hub / github.com/encode/starlette / url_path_for

Method url_path_for

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

Source from the content-addressed store, hash-verified

497 return Match.NONE, {}
498
499 def url_path_for(self, name: str, /, **path_params: Any) -> URLPath:
500 if self.name is not None and name == self.name and "path" in path_params:
501 # 'name' matches "<mount_name>".
502 path = path_params.pop("path")
503 host, remaining_params = replace_params(self.host_format, self.param_convertors, path_params)
504 if not remaining_params:
505 return URLPath(path=path, host=host)
506 elif self.name is None or name.startswith(self.name + ":"):
507 if self.name is None:
508 # No mount name.
509 remaining_name = name
510 else:
511 # 'name' matches "<mount_name>:<child_name>".
512 remaining_name = name[len(self.name) + 1 :]
513 host, remaining_params = replace_params(self.host_format, self.param_convertors, path_params)
514 for route in self.routes or []:
515 try:
516 url = route.url_path_for(remaining_name, **remaining_params)
517 return URLPath(path=str(url), protocol=url.protocol, host=host)
518 except NoMatchFound:
519 pass
520 raise NoMatchFound(name, path_params)
521
522 async def handle(self, scope: Scope, receive: Receive, send: Send) -> None:
523 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