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

Method url_path_for

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

Source from the content-addressed store, hash-verified

418 return Match.NONE, {}
419
420 def url_path_for(self, name: str, /, **path_params: Any) -> URLPath:
421 if self.name is not None and name == self.name and "path" in path_params:
422 # 'name' matches "<mount_name>".
423 path_params["path"] = path_params["path"].lstrip("/")
424 path, remaining_params = replace_params(self.path_format, self.param_convertors, path_params)
425 if not remaining_params:
426 return URLPath(path=path)
427 elif self.name is None or name.startswith(self.name + ":"):
428 if self.name is None:
429 # No mount name.
430 remaining_name = name
431 else:
432 # 'name' matches "<mount_name>:<child_name>".
433 remaining_name = name[len(self.name) + 1 :]
434 path_kwarg = path_params.get("path")
435 path_params["path"] = ""
436 path_prefix, remaining_params = replace_params(self.path_format, self.param_convertors, path_params)
437 if path_kwarg is not None:
438 remaining_params["path"] = path_kwarg
439 for route in self.routes or []:
440 try:
441 url = route.url_path_for(remaining_name, **remaining_params)
442 return URLPath(path=path_prefix.rstrip("/") + str(url), protocol=url.protocol)
443 except NoMatchFound:
444 pass
445 raise NoMatchFound(name, path_params)
446
447 async def handle(self, scope: Scope, receive: Receive, send: Send) -> None:
448 await self.app(scope, receive, send)

Callers

nothing calls this directly

Calls 5

URLPathClass · 0.90
replace_paramsFunction · 0.85
NoMatchFoundClass · 0.85
getMethod · 0.45
url_path_forMethod · 0.45

Tested by

no test coverage detected