mirror of https://github.com/encode/starlette.git
parent
47a810ece8
commit
e3543aa08e
|
@ -7,6 +7,7 @@ fi
|
|||
|
||||
set -x
|
||||
|
||||
${PREFIX}mypy starlette --ignore-missing-imports --disallow-untyped-defs
|
||||
${PREFIX}autoflake --in-place --recursive starlette tests
|
||||
${PREFIX}black starlette tests
|
||||
${PREFIX}isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --combine-as --line-width 88 --recursive --apply starlette tests
|
||||
|
|
|
@ -276,10 +276,23 @@ class WebSocketRoute(BaseRoute):
|
|||
|
||||
|
||||
class Mount(BaseRoute):
|
||||
def __init__(self, path: str, app: ASGIApp, name: str = None) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
path: str,
|
||||
app: ASGIApp = None,
|
||||
routes: typing.List[BaseRoute] = None,
|
||||
name: str = None,
|
||||
) -> None:
|
||||
assert path == "" or path.startswith("/"), "Routed paths must start with '/'"
|
||||
assert (
|
||||
app is not None or routes is not None
|
||||
), "Either 'app', or 'routes' must be specified"
|
||||
self.path = path.rstrip("/")
|
||||
self.app = app
|
||||
if routes is None:
|
||||
assert app is not None
|
||||
self.app = app
|
||||
else:
|
||||
self.app = Router(routes=routes)
|
||||
self.name = name
|
||||
self.path_regex, self.path_format, self.param_convertors = compile_path(
|
||||
path + "/{path:path}"
|
||||
|
|
|
@ -38,14 +38,12 @@ app = Router(
|
|||
Route("/", endpoint=homepage, methods=["GET"]),
|
||||
Mount(
|
||||
"/users",
|
||||
app=Router(
|
||||
[
|
||||
Route("/", endpoint=users),
|
||||
Route("/me", endpoint=user_me),
|
||||
Route("/{username}", endpoint=user),
|
||||
Route("/nomatch", endpoint=user_no_match),
|
||||
]
|
||||
),
|
||||
routes=[
|
||||
Route("/", endpoint=users),
|
||||
Route("/me", endpoint=user_me),
|
||||
Route("/{username}", endpoint=user),
|
||||
Route("/nomatch", endpoint=user_no_match),
|
||||
],
|
||||
),
|
||||
Mount("/static", app=staticfiles),
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue