mirror of
https://github.com/Textualize/textual-serve.git
synced 2025-10-17 02:50:37 +03:00
docstrings
This commit is contained in:
4
examples/serve.py
Normal file
4
examples/serve.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
from textual_serve.server import Server
|
||||||
|
|
||||||
|
server = Server("python -m textual")
|
||||||
|
server.serve()
|
||||||
@@ -91,9 +91,13 @@ class Server:
|
|||||||
self.console = Console()
|
self.console = Console()
|
||||||
|
|
||||||
def initialize_logging(self) -> None:
|
def initialize_logging(self) -> None:
|
||||||
|
"""Initialize logging.
|
||||||
|
|
||||||
|
May be overridden in a subclass.
|
||||||
|
"""
|
||||||
FORMAT = "%(message)s"
|
FORMAT = "%(message)s"
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level="INFO",
|
level="DEBUG" if self.debug else "INFO",
|
||||||
format=FORMAT,
|
format=FORMAT,
|
||||||
datefmt="[%X]",
|
datefmt="[%X]",
|
||||||
handlers=[
|
handlers=[
|
||||||
@@ -101,6 +105,7 @@ class Server:
|
|||||||
show_path=False,
|
show_path=False,
|
||||||
show_time=False,
|
show_time=False,
|
||||||
rich_tracebacks=True,
|
rich_tracebacks=True,
|
||||||
|
tracebacks_show_locals=True,
|
||||||
highlighter=LogHighlighter(),
|
highlighter=LogHighlighter(),
|
||||||
console=self.console,
|
console=self.console,
|
||||||
)
|
)
|
||||||
@@ -134,9 +139,18 @@ class Server:
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
async def on_shutdown(self, app: web.Application) -> None:
|
async def on_shutdown(self, app: web.Application) -> None:
|
||||||
pass
|
"""Called on shutdown.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
app: App instance.
|
||||||
|
"""
|
||||||
|
|
||||||
async def on_startup(self, app: web.Application) -> None:
|
async def on_startup(self, app: web.Application) -> None:
|
||||||
|
"""Called on startup.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
app: App instance.
|
||||||
|
"""
|
||||||
self.console.print(f"Serving {self.command!r} on {self.public_url}")
|
self.console.print(f"Serving {self.command!r} on {self.public_url}")
|
||||||
self.console.print("[bold yellow]Press Ctrl+C to quit")
|
self.console.print("[bold yellow]Press Ctrl+C to quit")
|
||||||
|
|
||||||
@@ -165,6 +179,14 @@ class Server:
|
|||||||
|
|
||||||
@aiohttp_jinja2.template("app_index.html")
|
@aiohttp_jinja2.template("app_index.html")
|
||||||
async def handle_index(self, request: web.Request) -> dict[str, Any]:
|
async def handle_index(self, request: web.Request) -> dict[str, Any]:
|
||||||
|
"""Serves the HTML for an app.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request: Request object.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Template data.
|
||||||
|
"""
|
||||||
router = request.app.router
|
router = request.app.router
|
||||||
font_size = to_int(request.query.get("fontsize", "16"), 16)
|
font_size = to_int(request.query.get("fontsize", "16"), 16)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user