-
-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3081 from litestar-org/develop
chore: Release 2.6.0
- Loading branch information
Showing
71 changed files
with
2,082 additions
and
521 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from inspect import Parameter, Signature | ||
from typing import Any, Dict, Tuple | ||
|
||
from litestar import Litestar, get | ||
from litestar.di import Provide | ||
from litestar.plugins import DIPlugin | ||
|
||
|
||
class MyBaseType: | ||
def __init__(self, param): | ||
self.param = param | ||
|
||
|
||
class MyDIPlugin(DIPlugin): | ||
def has_typed_init(self, type_: Any) -> bool: | ||
return issubclass(type_, MyBaseType) | ||
|
||
def get_typed_init(self, type_: Any) -> Tuple[Signature, Dict[str, Any]]: | ||
signature = Signature([Parameter(name="param", kind=Parameter.POSITIONAL_OR_KEYWORD)]) | ||
annotations = {"param": str} | ||
return signature, annotations | ||
|
||
|
||
@get("/", dependencies={"injected": Provide(MyBaseType, sync_to_thread=False)}) | ||
async def handler(injected: MyBaseType) -> str: | ||
return injected.param | ||
|
||
|
||
app = Litestar(route_handlers=[handler], plugins=[MyDIPlugin()]) | ||
|
||
# run: /?param=hello |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from litestar import Litestar | ||
from litestar.router import Router | ||
from litestar.static_files import create_static_files_router | ||
|
||
|
||
class MyRouter(Router): | ||
pass | ||
|
||
|
||
app = Litestar( | ||
route_handlers=[ | ||
create_static_files_router( | ||
path="/static", | ||
directories=["assets"], | ||
router_class=MyRouter, | ||
) | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from fsspec.implementations.ftp import FTPFileSystem | ||
|
||
from litestar import Litestar | ||
from litestar.static_files import create_static_files_router | ||
|
||
app = Litestar( | ||
route_handlers=[ | ||
create_static_files_router( | ||
path="/static", | ||
directories=["assets"], | ||
file_system=FTPFileSystem(host="127.0.0.1"), | ||
), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from pathlib import Path | ||
|
||
from litestar import Litestar | ||
from litestar.static_files import create_static_files_router | ||
|
||
ASSETS_DIR = Path("assets") | ||
|
||
|
||
def on_startup(): | ||
ASSETS_DIR.mkdir(exist_ok=True) | ||
ASSETS_DIR.joinpath("hello.txt").write_text("Hello, world!") | ||
|
||
|
||
app = Litestar( | ||
route_handlers=[ | ||
create_static_files_router(path="/static", directories=["assets"]), | ||
], | ||
on_startup=[on_startup], | ||
) | ||
|
||
|
||
# run: /static/hello.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from pathlib import Path | ||
|
||
from litestar import Litestar | ||
from litestar.static_files import create_static_files_router | ||
|
||
HTML_DIR = Path("html") | ||
|
||
|
||
def on_startup() -> None: | ||
HTML_DIR.mkdir(exist_ok=True) | ||
HTML_DIR.joinpath("index.html").write_text("<strong>Hello, world!</strong>") | ||
HTML_DIR.joinpath("404.html").write_text("<h1>Not found</h1>") | ||
|
||
|
||
app = Litestar( | ||
route_handlers=[ | ||
create_static_files_router( | ||
path="/", | ||
directories=["html"], | ||
html_mode=True, | ||
) | ||
], | ||
on_startup=[on_startup], | ||
) | ||
|
||
|
||
# run: / | ||
# run: /index.html | ||
# run: /something |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from litestar import Litestar | ||
from litestar.static_files import create_static_files_router | ||
|
||
app = Litestar( | ||
route_handlers=[ | ||
create_static_files_router( | ||
path="/", | ||
directories=["assets"], | ||
opt={"some": True}, | ||
include_in_schema=False, | ||
tags=["static"], | ||
) | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from litestar import Litestar | ||
from litestar.static_files import create_static_files_router | ||
|
||
app = Litestar( | ||
route_handlers=[ | ||
create_static_files_router(path="/static", directories=["assets"]), | ||
] | ||
) | ||
|
||
|
||
print(app.route_reverse(name="static", file_path="/some_file.txt")) # /static/some_file.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from litestar import Litestar | ||
from litestar.static_files import create_static_files_router | ||
|
||
app = Litestar( | ||
route_handlers=[ | ||
create_static_files_router( | ||
path="/static", | ||
directories=["assets"], | ||
send_as_attachment=True, | ||
) | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from litestar import Litestar | ||
from litestar.static_files.config import StaticFilesConfig | ||
|
||
app = Litestar( | ||
static_files_config=[ | ||
StaticFilesConfig(directories=["assets"], path="/static"), | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from litestar import Litestar | ||
from litestar.static_files import create_static_files_router | ||
|
||
app = Litestar( | ||
route_handlers=[ | ||
create_static_files_router(directories=["assets"], path="/static"), | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.