From 43ed5327288e91dd1b526ce8c8e080c86147c584 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 12 Jul 2018 14:09:05 +0100 Subject: [PATCH] Tweak imports and docs --- README.md | 13 ++++++++----- starlette/__init__.py | 4 ---- starlette/staticfiles.py | 2 +- tests/test_routing.py | 3 ++- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1aceeeac..c9cf88a1 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ Starlette is a small library for working with [ASGI](https://asgi.readthedocs.io/en/latest/). -It gives you `Request` and `Response` classes, request routing, a test client, and a -decorator for writing super-minimal applications. +It gives you `Request` and `Response` classes, request routing, static files support, +a test client, and a decorator for writing super-minimal applications. **Requirements:** @@ -279,7 +279,7 @@ Starlette includes a `Router` class which is an ASGI application that dispatches to other ASGI applications. ```python -from starlette import Router, Path, PathPrefix +from starlette.routing import Router, Path, PathPrefix from myproject import Homepage, SubMountedApp @@ -315,7 +315,7 @@ responses for requests which do not match. --- -## Static files +## Static Files As well as the `FileResponse` class, Starlette also includes ASGI applications for serving a specific file or directory: @@ -332,11 +332,14 @@ from starlette.staticfiles import StaticFile, StaticFiles app = Router(routes=[ - Path('/', app=StaticFile('index.html')), + Path('/', app=StaticFile(path='index.html')), PathPrefix('/static/', app=StaticFiles(directory='static')), ]) ``` +Static files will respond with "404 Not found" or "406 Method not allowed" +responses for requests which do not match. + --- ## Test Client diff --git a/starlette/__init__.py b/starlette/__init__.py index 26ac565a..6f0778a7 100644 --- a/starlette/__init__.py +++ b/starlette/__init__.py @@ -8,7 +8,6 @@ from starlette.response import ( StreamingResponse, ) from starlette.request import Request -from starlette.routing import Path, PathPrefix, Router from starlette.testclient import TestClient @@ -17,11 +16,8 @@ __all__ = ( "FileResponse", "HTMLResponse", "JSONResponse", - "Path", - "PathPrefix", "PlainTextResponse", "Response", - "Router", "StreamingResponse", "Request", "TestClient", diff --git a/starlette/staticfiles.py b/starlette/staticfiles.py index adc46b9a..4826cbef 100644 --- a/starlette/staticfiles.py +++ b/starlette/staticfiles.py @@ -5,7 +5,7 @@ import stat class StaticFile: - def __init__(self, path): + def __init__(self, *, path): self.path = path def __call__(self, scope): diff --git a/tests/test_routing.py b/tests/test_routing.py index 8c365bec..6c03b1b6 100644 --- a/tests/test_routing.py +++ b/tests/test_routing.py @@ -1,4 +1,5 @@ -from starlette import Response, Path, PathPrefix, Router, TestClient +from starlette import Response, TestClient +from starlette.routing import Path, PathPrefix, Router def homepage(scope): -- 2.47.3