From 12cf076118570eebbff08c6b3090e0d4798447a1 Mon Sep 17 00:00:00 2001 From: cyfraeviolae Date: Wed, 3 Apr 2024 03:17:55 -0400 Subject: no venv --- .../site-packages/litestar/template/config.py | 57 ---------------------- 1 file changed, 57 deletions(-) delete mode 100644 venv/lib/python3.11/site-packages/litestar/template/config.py (limited to 'venv/lib/python3.11/site-packages/litestar/template/config.py') diff --git a/venv/lib/python3.11/site-packages/litestar/template/config.py b/venv/lib/python3.11/site-packages/litestar/template/config.py deleted file mode 100644 index d2aa87c..0000000 --- a/venv/lib/python3.11/site-packages/litestar/template/config.py +++ /dev/null @@ -1,57 +0,0 @@ -from __future__ import annotations - -from dataclasses import dataclass, field -from functools import cached_property -from inspect import isclass -from typing import TYPE_CHECKING, Callable, Generic, TypeVar, cast - -from litestar.exceptions import ImproperlyConfiguredException -from litestar.template import TemplateEngineProtocol - -__all__ = ("TemplateConfig",) - -if TYPE_CHECKING: - from litestar.types import PathType - -EngineType = TypeVar("EngineType", bound=TemplateEngineProtocol) - - -@dataclass -class TemplateConfig(Generic[EngineType]): - """Configuration for Templating. - - To enable templating, pass an instance of this class to the :class:`Litestar ` constructor using the - 'template_config' key. - """ - - engine: type[EngineType] | EngineType | None = field(default=None) - """A template engine adhering to the :class:`TemplateEngineProtocol `.""" - directory: PathType | list[PathType] | None = field(default=None) - """A directory or list of directories from which to serve templates.""" - engine_callback: Callable[[EngineType], None] | None = field(default=None) - """A callback function that allows modifying the instantiated templating protocol.""" - instance: EngineType | None = field(default=None) - """An instance of the templating protocol.""" - - def __post_init__(self) -> None: - """Ensure that directory is set if engine is a class.""" - if isclass(self.engine) and not self.directory: - raise ImproperlyConfiguredException("directory is a required kwarg when passing a template engine class") - """Ensure that directory is not set if instance is.""" - if self.instance is not None and self.directory is not None: - raise ImproperlyConfiguredException("directory cannot be set if instance is") - - def to_engine(self) -> EngineType: - """Instantiate the template engine.""" - template_engine = cast( - "EngineType", - self.engine(directory=self.directory, engine_instance=None) if isclass(self.engine) else self.engine, - ) - if callable(self.engine_callback): - self.engine_callback(template_engine) - return template_engine - - @cached_property - def engine_instance(self) -> EngineType: - """Return the template engine instance.""" - return self.to_engine() if self.instance is None else self.instance -- cgit v1.2.3