We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
StaticFilesConfig and virtual directories
I'm trying to write a ``FileSystemProtocol`` to load files from the package data using [importlib_resources](https://importlib-resources.readthedocs.io/en/latest/using.html#). But because ``directories`` is defined as ``DirectoryPath``, pydantic checks if the given directories exist in the local filesystem. 

This is not generally true, especially in any kind of virtual filesystem (e.g. a zipped package). I think this condition should be relaxed to support virtual filesystems.

https://github.com/starlite-api/starlite/blob/9bb6dcd57c10a591377cf8e3a537e9292566d5b9/starlite/config/static_files.py#L32

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `litestar/contrib/htmx/response.py`
Content:
```
1 from __future__ import annotations
2 
3 from dataclasses import dataclass, field
4 from typing import TYPE_CHECKING, Any, Generic, TypeVar
5 from urllib.parse import quote
6 
7 from litestar import Litestar, MediaType, Request, Response
8 from litestar.contrib.htmx._utils import HTMX_STOP_POLLING, get_headers
9 from litestar.contrib.htmx.types import (
10     EventAfterType,
11     HtmxHeaderType,
12     LocationType,
13     PushUrlType,
14     ReSwapMethod,
15     TriggerEventType,
16 )
17 from litestar.response import TemplateResponse
18 from litestar.response_containers import ResponseContainer, Template
19 from litestar.status_codes import HTTP_200_OK
20 
21 __all__ = (
22     "ClientRedirect",
23     "ClientRefresh",
24     "HTMXTemplate",
25     "HXLocation",
26     "HXStopPolling",
27     "PushUrl",
28     "ReplaceUrl",
29     "Reswap",
30     "Retarget",
31     "TriggerEvent",
32 )
33 
34 if TYPE_CHECKING:
35     from litestar.background_tasks import BackgroundTask, BackgroundTasks
36     from litestar.datastructures import Cookie
37 
38 
39 # HTMX defined HTTP status code.
40 # Response carrying this status code will ask client to stop Polling.
41 T = TypeVar("T")
42 
43 
44 class HXStopPolling(Response):
45     """Stop HTMX client from Polling."""
46 
47     def __init__(self) -> None:
48         """Initialize"""
49         super().__init__(content=None)
50         self.status_code = HTMX_STOP_POLLING
51 
52 
53 class ClientRedirect(Response):
54     """HTMX Response class to support client side redirect."""
55 
56     def __init__(self, redirect_to: str) -> None:
57         """Set status code to 200 (required by HTMX), and pass redirect url."""
58         super().__init__(content=None, headers=get_headers(hx_headers=HtmxHeaderType(redirect=redirect_to)))
59         del self.headers["Location"]
60 
61 
62 class ClientRefresh(Response):
63     """Response to support HTMX client page refresh"""
64 
65     def __init__(self) -> None:
66         """Set Status code to 200 and set headers."""
67         super().__init__(content=None, headers=get_headers(hx_headers=HtmxHeaderType(refresh=True)))
68 
69 
70 class PushUrl(Generic[T], Response[T]):
71     """Response to push new url into the history stack."""
72 
73     def __init__(self, content: T, push_url: PushUrlType, **kwargs: Any) -> None:
74         """Initialize PushUrl."""
75         super().__init__(
76             content=content,
77             status_code=HTTP_200_OK,
78             headers=get_headers(hx_headers=HtmxHeaderType(push_url=push_url)),
79             **kwargs,
80         )
81 
82 
83 class ReplaceUrl(Generic[T], Response[T]):
84     """Response to replace url in the Browser Location bar."""
85 
86     def __init__(self, content: T, replace_url: PushUrlType, **kwargs: Any) -> None:
87         """Initialize ReplaceUrl."""
88         super().__init__(
89             content=content,
90             status_code=HTTP_200_OK,
91             headers=get_headers(hx_headers=HtmxHeaderType(replace_url=replace_url)),
92             **kwargs,
93         )
94 
95 
96 class Reswap(Generic[T], Response[T]):
97     """Response to specify how the response will be swapped."""
98 
99     def __init__(
100         self,
101         content: T,
102         method: ReSwapMethod,
103         **kwargs: Any,
104     ) -> None:
105         """Initialize Reswap."""
106         super().__init__(content=content, headers=get_headers(hx_headers=HtmxHeaderType(re_swap=method)), **kwargs)
107 
108 
109 class Retarget(Generic[T], Response[T]):
110     """Response to target different element on the page."""
111 
112     def __init__(self, content: T, target: str, **kwargs: Any) -> None:
113         """Initialize Retarget."""
114         super().__init__(content=content, headers=get_headers(hx_headers=HtmxHeaderType(re_target=target)), **kwargs)
115 
116 
117 class TriggerEvent(Generic[T], Response[T]):
118     """Trigger Client side event."""
119 
120     def __init__(
121         self,
122         content: T,
123         name: str,
124         after: EventAfterType,
125         params: dict[str, Any] | None = None,
126         **kwargs: Any,
127     ) -> None:
128         """Initialize TriggerEvent."""
129         event = TriggerEventType(name=name, params=params, after=after)
130         headers = get_headers(hx_headers=HtmxHeaderType(trigger_event=event))
131         super().__init__(content=content, headers=headers, **kwargs)
132 
133 
134 class HXLocation(Response):
135     """Client side redirect without full page reload."""
136 
137     def __init__(
138         self,
139         redirect_to: str,
140         source: str | None = None,
141         event: str | None = None,
142         target: str | None = None,
143         swap: ReSwapMethod = None,
144         hx_headers: dict[str, Any] | None = None,
145         values: dict[str, str] | None = None,
146         **kwargs: Any,
147     ) -> None:
148         """Initialize HXLocation, Set status code to 200 (required by HTMX),
149         and pass redirect url.
150         """
151         super().__init__(
152             content=None,
153             headers={"Location": quote(redirect_to, safe="/#%[]=:;$&()+,!?*@'~")},
154             **kwargs,
155         )
156         spec: dict[str, Any] = get_headers(
157             hx_headers=HtmxHeaderType(
158                 location=LocationType(
159                     path=str(self.headers.get("Location")),
160                     source=source,
161                     event=event,
162                     target=target,
163                     swap=swap,
164                     values=values,
165                     hx_headers=hx_headers,
166                 )
167             )
168         )
169         del self.headers["Location"]
170         self.headers.update(spec)
171 
172 
173 @dataclass
174 class HTMXTemplate(ResponseContainer[TemplateResponse]):
175     """HTMX template wrapper"""
176 
177     name: str
178     """Path-like name for the template to be rendered, e.g. "index.html"."""
179     context: dict[str, Any] = field(default_factory=dict)
180     """A dictionary of key/value pairs to be passed to the temple engine's render method.
181 
182     Defaults to None.
183     """
184     background: BackgroundTask | BackgroundTasks | None = field(default=None)
185     """A :class:`BackgroundTask <.background_tasks.BackgroundTask>` instance or
186     :class:`BackgroundTasks <.background_tasks.BackgroundTasks>` to execute after the response is finished. Defaults to
187     ``None``.
188     """
189     headers: dict[str, Any] = field(default_factory=dict)
190     """A string/string dictionary of response headers.Header keys are insensitive. Defaults to ``None``."""
191     cookies: list[Cookie] = field(default_factory=list)
192     """A list of :class:`Cookies <.datastructures.Cookie>` to be set under the response ``Set-Cookie`` header. Defaults
193     to ``None``.
194     """
195     media_type: MediaType | str | None = field(default=None)
196     """If defined, overrides the media type configured in the route decorator."""
197     encoding: str = field(default="utf-8")
198     """The encoding to be used for the response headers."""
199     push_url: PushUrlType | None = field(default=None)
200     """Either a string value specifying a URL to push to browser history or ``False`` to prevent HTMX client from
201     pushing a url to browser history."""
202     re_swap: ReSwapMethod | None = field(default=None)
203     """Method value to instruct HTMX which swapping method to use."""
204     re_target: str | None = field(default=None)
205     """Value for 'id of target element' to apply changes to."""
206     trigger_event: str | None = field(default=None)
207     """Event name to trigger."""
208     params: dict[str, Any] | None = field(default=None)
209     """Dictionary of parameters if any required with trigger event parameter."""
210     after: EventAfterType | None = field(default=None)
211     """Changes to apply after ``receive``, ``settle`` or ``swap`` event."""
212 
213     def to_response(
214         self,
215         headers: dict[str, Any],
216         media_type: MediaType | str,
217         status_code: int,
218         app: Litestar,
219         request: Request,
220     ) -> TemplateResponse:
221         """Add HTMX headers and return a :class:`TemplateResponse <.response.TemplateResponse>`."""
222 
223         event: TriggerEventType | None = None
224         if self.trigger_event:
225             event = TriggerEventType(name=str(self.trigger_event), params=self.params, after=self.after)
226 
227         hx_headers: dict[str, Any] = get_headers(
228             hx_headers=HtmxHeaderType(
229                 push_url=self.push_url, re_swap=self.re_swap, re_target=self.re_target, trigger_event=event
230             )
231         )
232 
233         template = Template(
234             name=self.name,
235             background=self.background,
236             encoding=self.encoding,
237         )
238 
239         return template.to_response(
240             headers=hx_headers, media_type=media_type, app=app, status_code=status_code, request=request
241         )
242
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/litestar/contrib/htmx/response.py b/litestar/contrib/htmx/response.py
--- a/litestar/contrib/htmx/response.py
+++ b/litestar/contrib/htmx/response.py
@@ -230,11 +230,7 @@
             )
         )
 
-        template = Template(
-            name=self.name,
-            background=self.background,
-            encoding=self.encoding,
-        )
+        template = Template(name=self.name, background=self.background, context=self.context, encoding=self.encoding)
 
         return template.to_response(
             headers=hx_headers, media_type=media_type, app=app, status_code=status_code, request=request

{"golden_diff": "diff --git a/litestar/contrib/htmx/response.py b/litestar/contrib/htmx/response.py\n--- a/litestar/contrib/htmx/response.py\n+++ b/litestar/contrib/htmx/response.py\n@@ -230,11 +230,7 @@\n             )\n         )\n \n-        template = Template(\n-            name=self.name,\n-            background=self.background,\n-            encoding=self.encoding,\n-        )\n+        template = Template(name=self.name, background=self.background, context=self.context, encoding=self.encoding)\n \n         return template.to_response(\n             headers=hx_headers, media_type=media_type, app=app, status_code=status_code, request=request\n", "issue": "StaticFilesConfig and virtual directories\nI'm trying to write a ``FileSystemProtocol`` to load files from the package data using [importlib_resources](https://importlib-resources.readthedocs.io/en/latest/using.html#). But because ``directories`` is defined as ``DirectoryPath``, pydantic checks if the given directories exist in the local filesystem. \r\n\r\nThis is not generally true, especially in any kind of virtual filesystem (e.g. a zipped package). I think this condition should be relaxed to support virtual filesystems.\r\n\r\nhttps://github.com/starlite-api/starlite/blob/9bb6dcd57c10a591377cf8e3a537e9292566d5b9/starlite/config/static_files.py#L32\n", "before_files": [{"content": "from __future__ import annotations\n\nfrom dataclasses import dataclass, field\nfrom typing import TYPE_CHECKING, Any, Generic, TypeVar\nfrom urllib.parse import quote\n\nfrom litestar import Litestar, MediaType, Request, Response\nfrom litestar.contrib.htmx._utils import HTMX_STOP_POLLING, get_headers\nfrom litestar.contrib.htmx.types import (\n    EventAfterType,\n    HtmxHeaderType,\n    LocationType,\n    PushUrlType,\n    ReSwapMethod,\n    TriggerEventType,\n)\nfrom litestar.response import TemplateResponse\nfrom litestar.response_containers import ResponseContainer, Template\nfrom litestar.status_codes import HTTP_200_OK\n\n__all__ = (\n    \"ClientRedirect\",\n    \"ClientRefresh\",\n    \"HTMXTemplate\",\n    \"HXLocation\",\n    \"HXStopPolling\",\n    \"PushUrl\",\n    \"ReplaceUrl\",\n    \"Reswap\",\n    \"Retarget\",\n    \"TriggerEvent\",\n)\n\nif TYPE_CHECKING:\n    from litestar.background_tasks import BackgroundTask, BackgroundTasks\n    from litestar.datastructures import Cookie\n\n\n# HTMX defined HTTP status code.\n# Response carrying this status code will ask client to stop Polling.\nT = TypeVar(\"T\")\n\n\nclass HXStopPolling(Response):\n    \"\"\"Stop HTMX client from Polling.\"\"\"\n\n    def __init__(self) -> None:\n        \"\"\"Initialize\"\"\"\n        super().__init__(content=None)\n        self.status_code = HTMX_STOP_POLLING\n\n\nclass ClientRedirect(Response):\n    \"\"\"HTMX Response class to support client side redirect.\"\"\"\n\n    def __init__(self, redirect_to: str) -> None:\n        \"\"\"Set status code to 200 (required by HTMX), and pass redirect url.\"\"\"\n        super().__init__(content=None, headers=get_headers(hx_headers=HtmxHeaderType(redirect=redirect_to)))\n        del self.headers[\"Location\"]\n\n\nclass ClientRefresh(Response):\n    \"\"\"Response to support HTMX client page refresh\"\"\"\n\n    def __init__(self) -> None:\n        \"\"\"Set Status code to 200 and set headers.\"\"\"\n        super().__init__(content=None, headers=get_headers(hx_headers=HtmxHeaderType(refresh=True)))\n\n\nclass PushUrl(Generic[T], Response[T]):\n    \"\"\"Response to push new url into the history stack.\"\"\"\n\n    def __init__(self, content: T, push_url: PushUrlType, **kwargs: Any) -> None:\n        \"\"\"Initialize PushUrl.\"\"\"\n        super().__init__(\n            content=content,\n            status_code=HTTP_200_OK,\n            headers=get_headers(hx_headers=HtmxHeaderType(push_url=push_url)),\n            **kwargs,\n        )\n\n\nclass ReplaceUrl(Generic[T], Response[T]):\n    \"\"\"Response to replace url in the Browser Location bar.\"\"\"\n\n    def __init__(self, content: T, replace_url: PushUrlType, **kwargs: Any) -> None:\n        \"\"\"Initialize ReplaceUrl.\"\"\"\n        super().__init__(\n            content=content,\n            status_code=HTTP_200_OK,\n            headers=get_headers(hx_headers=HtmxHeaderType(replace_url=replace_url)),\n            **kwargs,\n        )\n\n\nclass Reswap(Generic[T], Response[T]):\n    \"\"\"Response to specify how the response will be swapped.\"\"\"\n\n    def __init__(\n        self,\n        content: T,\n        method: ReSwapMethod,\n        **kwargs: Any,\n    ) -> None:\n        \"\"\"Initialize Reswap.\"\"\"\n        super().__init__(content=content, headers=get_headers(hx_headers=HtmxHeaderType(re_swap=method)), **kwargs)\n\n\nclass Retarget(Generic[T], Response[T]):\n    \"\"\"Response to target different element on the page.\"\"\"\n\n    def __init__(self, content: T, target: str, **kwargs: Any) -> None:\n        \"\"\"Initialize Retarget.\"\"\"\n        super().__init__(content=content, headers=get_headers(hx_headers=HtmxHeaderType(re_target=target)), **kwargs)\n\n\nclass TriggerEvent(Generic[T], Response[T]):\n    \"\"\"Trigger Client side event.\"\"\"\n\n    def __init__(\n        self,\n        content: T,\n        name: str,\n        after: EventAfterType,\n        params: dict[str, Any] | None = None,\n        **kwargs: Any,\n    ) -> None:\n        \"\"\"Initialize TriggerEvent.\"\"\"\n        event = TriggerEventType(name=name, params=params, after=after)\n        headers = get_headers(hx_headers=HtmxHeaderType(trigger_event=event))\n        super().__init__(content=content, headers=headers, **kwargs)\n\n\nclass HXLocation(Response):\n    \"\"\"Client side redirect without full page reload.\"\"\"\n\n    def __init__(\n        self,\n        redirect_to: str,\n        source: str | None = None,\n        event: str | None = None,\n        target: str | None = None,\n        swap: ReSwapMethod = None,\n        hx_headers: dict[str, Any] | None = None,\n        values: dict[str, str] | None = None,\n        **kwargs: Any,\n    ) -> None:\n        \"\"\"Initialize HXLocation, Set status code to 200 (required by HTMX),\n        and pass redirect url.\n        \"\"\"\n        super().__init__(\n            content=None,\n            headers={\"Location\": quote(redirect_to, safe=\"/#%[]=:;$&()+,!?*@'~\")},\n            **kwargs,\n        )\n        spec: dict[str, Any] = get_headers(\n            hx_headers=HtmxHeaderType(\n                location=LocationType(\n                    path=str(self.headers.get(\"Location\")),\n                    source=source,\n                    event=event,\n                    target=target,\n                    swap=swap,\n                    values=values,\n                    hx_headers=hx_headers,\n                )\n            )\n        )\n        del self.headers[\"Location\"]\n        self.headers.update(spec)\n\n\n@dataclass\nclass HTMXTemplate(ResponseContainer[TemplateResponse]):\n    \"\"\"HTMX template wrapper\"\"\"\n\n    name: str\n    \"\"\"Path-like name for the template to be rendered, e.g. \"index.html\".\"\"\"\n    context: dict[str, Any] = field(default_factory=dict)\n    \"\"\"A dictionary of key/value pairs to be passed to the temple engine's render method.\n\n    Defaults to None.\n    \"\"\"\n    background: BackgroundTask | BackgroundTasks | None = field(default=None)\n    \"\"\"A :class:`BackgroundTask <.background_tasks.BackgroundTask>` instance or\n    :class:`BackgroundTasks <.background_tasks.BackgroundTasks>` to execute after the response is finished. Defaults to\n    ``None``.\n    \"\"\"\n    headers: dict[str, Any] = field(default_factory=dict)\n    \"\"\"A string/string dictionary of response headers.Header keys are insensitive. Defaults to ``None``.\"\"\"\n    cookies: list[Cookie] = field(default_factory=list)\n    \"\"\"A list of :class:`Cookies <.datastructures.Cookie>` to be set under the response ``Set-Cookie`` header. Defaults\n    to ``None``.\n    \"\"\"\n    media_type: MediaType | str | None = field(default=None)\n    \"\"\"If defined, overrides the media type configured in the route decorator.\"\"\"\n    encoding: str = field(default=\"utf-8\")\n    \"\"\"The encoding to be used for the response headers.\"\"\"\n    push_url: PushUrlType | None = field(default=None)\n    \"\"\"Either a string value specifying a URL to push to browser history or ``False`` to prevent HTMX client from\n    pushing a url to browser history.\"\"\"\n    re_swap: ReSwapMethod | None = field(default=None)\n    \"\"\"Method value to instruct HTMX which swapping method to use.\"\"\"\n    re_target: str | None = field(default=None)\n    \"\"\"Value for 'id of target element' to apply changes to.\"\"\"\n    trigger_event: str | None = field(default=None)\n    \"\"\"Event name to trigger.\"\"\"\n    params: dict[str, Any] | None = field(default=None)\n    \"\"\"Dictionary of parameters if any required with trigger event parameter.\"\"\"\n    after: EventAfterType | None = field(default=None)\n    \"\"\"Changes to apply after ``receive``, ``settle`` or ``swap`` event.\"\"\"\n\n    def to_response(\n        self,\n        headers: dict[str, Any],\n        media_type: MediaType | str,\n        status_code: int,\n        app: Litestar,\n        request: Request,\n    ) -> TemplateResponse:\n        \"\"\"Add HTMX headers and return a :class:`TemplateResponse <.response.TemplateResponse>`.\"\"\"\n\n        event: TriggerEventType | None = None\n        if self.trigger_event:\n            event = TriggerEventType(name=str(self.trigger_event), params=self.params, after=self.after)\n\n        hx_headers: dict[str, Any] = get_headers(\n            hx_headers=HtmxHeaderType(\n                push_url=self.push_url, re_swap=self.re_swap, re_target=self.re_target, trigger_event=event\n            )\n        )\n\n        template = Template(\n            name=self.name,\n            background=self.background,\n            encoding=self.encoding,\n        )\n\n        return template.to_response(\n            headers=hx_headers, media_type=media_type, app=app, status_code=status_code, request=request\n        )\n", "path": "litestar/contrib/htmx/response.py"}], "after_files": [{"content": "from __future__ import annotations\n\nfrom dataclasses import dataclass, field\nfrom typing import TYPE_CHECKING, Any, Generic, TypeVar\nfrom urllib.parse import quote\n\nfrom litestar import Litestar, MediaType, Request, Response\nfrom litestar.contrib.htmx._utils import HTMX_STOP_POLLING, get_headers\nfrom litestar.contrib.htmx.types import (\n    EventAfterType,\n    HtmxHeaderType,\n    LocationType,\n    PushUrlType,\n    ReSwapMethod,\n    TriggerEventType,\n)\nfrom litestar.response import TemplateResponse\nfrom litestar.response_containers import ResponseContainer, Template\nfrom litestar.status_codes import HTTP_200_OK\n\n__all__ = (\n    \"ClientRedirect\",\n    \"ClientRefresh\",\n    \"HTMXTemplate\",\n    \"HXLocation\",\n    \"HXStopPolling\",\n    \"PushUrl\",\n    \"ReplaceUrl\",\n    \"Reswap\",\n    \"Retarget\",\n    \"TriggerEvent\",\n)\n\nif TYPE_CHECKING:\n    from litestar.background_tasks import BackgroundTask, BackgroundTasks\n    from litestar.datastructures import Cookie\n\n\n# HTMX defined HTTP status code.\n# Response carrying this status code will ask client to stop Polling.\nT = TypeVar(\"T\")\n\n\nclass HXStopPolling(Response):\n    \"\"\"Stop HTMX client from Polling.\"\"\"\n\n    def __init__(self) -> None:\n        \"\"\"Initialize\"\"\"\n        super().__init__(content=None)\n        self.status_code = HTMX_STOP_POLLING\n\n\nclass ClientRedirect(Response):\n    \"\"\"HTMX Response class to support client side redirect.\"\"\"\n\n    def __init__(self, redirect_to: str) -> None:\n        \"\"\"Set status code to 200 (required by HTMX), and pass redirect url.\"\"\"\n        super().__init__(content=None, headers=get_headers(hx_headers=HtmxHeaderType(redirect=redirect_to)))\n        del self.headers[\"Location\"]\n\n\nclass ClientRefresh(Response):\n    \"\"\"Response to support HTMX client page refresh\"\"\"\n\n    def __init__(self) -> None:\n        \"\"\"Set Status code to 200 and set headers.\"\"\"\n        super().__init__(content=None, headers=get_headers(hx_headers=HtmxHeaderType(refresh=True)))\n\n\nclass PushUrl(Generic[T], Response[T]):\n    \"\"\"Response to push new url into the history stack.\"\"\"\n\n    def __init__(self, content: T, push_url: PushUrlType, **kwargs: Any) -> None:\n        \"\"\"Initialize PushUrl.\"\"\"\n        super().__init__(\n            content=content,\n            status_code=HTTP_200_OK,\n            headers=get_headers(hx_headers=HtmxHeaderType(push_url=push_url)),\n            **kwargs,\n        )\n\n\nclass ReplaceUrl(Generic[T], Response[T]):\n    \"\"\"Response to replace url in the Browser Location bar.\"\"\"\n\n    def __init__(self, content: T, replace_url: PushUrlType, **kwargs: Any) -> None:\n        \"\"\"Initialize ReplaceUrl.\"\"\"\n        super().__init__(\n            content=content,\n            status_code=HTTP_200_OK,\n            headers=get_headers(hx_headers=HtmxHeaderType(replace_url=replace_url)),\n            **kwargs,\n        )\n\n\nclass Reswap(Generic[T], Response[T]):\n    \"\"\"Response to specify how the response will be swapped.\"\"\"\n\n    def __init__(\n        self,\n        content: T,\n        method: ReSwapMethod,\n        **kwargs: Any,\n    ) -> None:\n        \"\"\"Initialize Reswap.\"\"\"\n        super().__init__(content=content, headers=get_headers(hx_headers=HtmxHeaderType(re_swap=method)), **kwargs)\n\n\nclass Retarget(Generic[T], Response[T]):\n    \"\"\"Response to target different element on the page.\"\"\"\n\n    def __init__(self, content: T, target: str, **kwargs: Any) -> None:\n        \"\"\"Initialize Retarget.\"\"\"\n        super().__init__(content=content, headers=get_headers(hx_headers=HtmxHeaderType(re_target=target)), **kwargs)\n\n\nclass TriggerEvent(Generic[T], Response[T]):\n    \"\"\"Trigger Client side event.\"\"\"\n\n    def __init__(\n        self,\n        content: T,\n        name: str,\n        after: EventAfterType,\n        params: dict[str, Any] | None = None,\n        **kwargs: Any,\n    ) -> None:\n        \"\"\"Initialize TriggerEvent.\"\"\"\n        event = TriggerEventType(name=name, params=params, after=after)\n        headers = get_headers(hx_headers=HtmxHeaderType(trigger_event=event))\n        super().__init__(content=content, headers=headers, **kwargs)\n\n\nclass HXLocation(Response):\n    \"\"\"Client side redirect without full page reload.\"\"\"\n\n    def __init__(\n        self,\n        redirect_to: str,\n        source: str | None = None,\n        event: str | None = None,\n        target: str | None = None,\n        swap: ReSwapMethod = None,\n        hx_headers: dict[str, Any] | None = None,\n        values: dict[str, str] | None = None,\n        **kwargs: Any,\n    ) -> None:\n        \"\"\"Initialize HXLocation, Set status code to 200 (required by HTMX),\n        and pass redirect url.\n        \"\"\"\n        super().__init__(\n            content=None,\n            headers={\"Location\": quote(redirect_to, safe=\"/#%[]=:;$&()+,!?*@'~\")},\n            **kwargs,\n        )\n        spec: dict[str, Any] = get_headers(\n            hx_headers=HtmxHeaderType(\n                location=LocationType(\n                    path=str(self.headers.get(\"Location\")),\n                    source=source,\n                    event=event,\n                    target=target,\n                    swap=swap,\n                    values=values,\n                    hx_headers=hx_headers,\n                )\n            )\n        )\n        del self.headers[\"Location\"]\n        self.headers.update(spec)\n\n\n@dataclass\nclass HTMXTemplate(ResponseContainer[TemplateResponse]):\n    \"\"\"HTMX template wrapper\"\"\"\n\n    name: str\n    \"\"\"Path-like name for the template to be rendered, e.g. \"index.html\".\"\"\"\n    context: dict[str, Any] = field(default_factory=dict)\n    \"\"\"A dictionary of key/value pairs to be passed to the temple engine's render method.\n\n    Defaults to None.\n    \"\"\"\n    background: BackgroundTask | BackgroundTasks | None = field(default=None)\n    \"\"\"A :class:`BackgroundTask <.background_tasks.BackgroundTask>` instance or\n    :class:`BackgroundTasks <.background_tasks.BackgroundTasks>` to execute after the response is finished. Defaults to\n    ``None``.\n    \"\"\"\n    headers: dict[str, Any] = field(default_factory=dict)\n    \"\"\"A string/string dictionary of response headers.Header keys are insensitive. Defaults to ``None``.\"\"\"\n    cookies: list[Cookie] = field(default_factory=list)\n    \"\"\"A list of :class:`Cookies <.datastructures.Cookie>` to be set under the response ``Set-Cookie`` header. Defaults\n    to ``None``.\n    \"\"\"\n    media_type: MediaType | str | None = field(default=None)\n    \"\"\"If defined, overrides the media type configured in the route decorator.\"\"\"\n    encoding: str = field(default=\"utf-8\")\n    \"\"\"The encoding to be used for the response headers.\"\"\"\n    push_url: PushUrlType | None = field(default=None)\n    \"\"\"Either a string value specifying a URL to push to browser history or ``False`` to prevent HTMX client from\n    pushing a url to browser history.\"\"\"\n    re_swap: ReSwapMethod | None = field(default=None)\n    \"\"\"Method value to instruct HTMX which swapping method to use.\"\"\"\n    re_target: str | None = field(default=None)\n    \"\"\"Value for 'id of target element' to apply changes to.\"\"\"\n    trigger_event: str | None = field(default=None)\n    \"\"\"Event name to trigger.\"\"\"\n    params: dict[str, Any] | None = field(default=None)\n    \"\"\"Dictionary of parameters if any required with trigger event parameter.\"\"\"\n    after: EventAfterType | None = field(default=None)\n    \"\"\"Changes to apply after ``receive``, ``settle`` or ``swap`` event.\"\"\"\n\n    def to_response(\n        self,\n        headers: dict[str, Any],\n        media_type: MediaType | str,\n        status_code: int,\n        app: Litestar,\n        request: Request,\n    ) -> TemplateResponse:\n        \"\"\"Add HTMX headers and return a :class:`TemplateResponse <.response.TemplateResponse>`.\"\"\"\n\n        event: TriggerEventType | None = None\n        if self.trigger_event:\n            event = TriggerEventType(name=str(self.trigger_event), params=self.params, after=self.after)\n\n        hx_headers: dict[str, Any] = get_headers(\n            hx_headers=HtmxHeaderType(\n                push_url=self.push_url, re_swap=self.re_swap, re_target=self.re_target, trigger_event=event\n            )\n        )\n\n        template = Template(name=self.name, background=self.background, context=self.context, encoding=self.encoding)\n\n        return template.to_response(\n            headers=hx_headers, media_type=media_type, app=app, status_code=status_code, request=request\n        )\n", "path": "litestar/contrib/htmx/response.py"}]}