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/dto/exceptions.py`
Content:
```
1 from __future__ import annotations
2 
3 from litestar.exceptions import ImproperlyConfiguredException
4 
5 __all__ = ["DTOException", "UnsupportedType"]
6 
7 
8 class DTOException(ImproperlyConfiguredException):
9     """Base exception for DTO errors."""
10 
11 
12 class UnsupportedType(DTOException):
13     """Raised when a type is not supported by Litestar."""
14
```

Path: `litestar/dto/factory/abc.py`
Content:
```
1 from __future__ import annotations
2 
3 from abc import ABCMeta, abstractmethod
4 from typing import TYPE_CHECKING, Generic, TypeVar
5 
6 from litestar.dto.interface import ConnectionContext, DTOInterface
7 from litestar.enums import RequestEncodingType
8 from litestar.typing import ParsedType
9 
10 from ._backends import MsgspecDTOBackend, PydanticDTOBackend
11 from ._backends.abc import BackendContext
12 from .config import DTOConfig
13 from .data_structures import DTOData
14 from .exc import InvalidAnnotation
15 from .utils import parse_configs_from_annotation
16 
17 if TYPE_CHECKING:
18     from typing import Any, ClassVar, Collection, Generator
19 
20     from typing_extensions import Self
21 
22     from litestar.dto.interface import HandlerContext
23     from litestar.dto.types import ForType
24     from litestar.openapi.spec import Reference, Schema
25     from litestar.types.serialization import LitestarEncodableType
26 
27     from ._backends import AbstractDTOBackend
28     from .types import FieldDefinition
29 
30 __all__ = ["AbstractDTOFactory"]
31 
32 T = TypeVar("T")
33 
34 
35 class AbstractDTOFactory(DTOInterface, Generic[T], metaclass=ABCMeta):
36     """Base class for DTO types."""
37 
38     __slots__ = ("connection_context",)
39 
40     config: ClassVar[DTOConfig]
41     """Config objects to define properties of the DTO."""
42     model_type: ClassVar[type[Any]]
43     """If ``annotation`` is an iterable, this is the inner type, otherwise will be the same as ``annotation``."""
44 
45     _type_backend_map: ClassVar[dict[tuple[ForType, ParsedType, RequestEncodingType | str | None], AbstractDTOBackend]]
46     _handler_backend_map: ClassVar[dict[tuple[ForType, str], AbstractDTOBackend]]
47 
48     def __init__(self, connection_context: ConnectionContext) -> None:
49         """Create an AbstractDTOFactory type.
50 
51         Args:
52             connection_context: A :class:`ConnectionContext <.ConnectionContext>` instance, which provides
53                 information about the connection.
54         """
55         self.connection_context = connection_context
56 
57     def __class_getitem__(cls, annotation: Any) -> type[Self]:
58         parsed_type = ParsedType(annotation)
59 
60         if (parsed_type.is_optional and len(parsed_type.args) > 2) or (
61             parsed_type.is_union and not parsed_type.is_optional
62         ):
63             raise InvalidAnnotation(
64                 "Unions are currently not supported as type argument to DTO. Want this? Open an issue."
65             )
66 
67         if parsed_type.is_forward_ref:
68             raise InvalidAnnotation("Forward references are not supported as type argument to DTO")
69 
70         # if a configuration is not provided, and the type narrowing is a type var, we don't want to create a subclass
71         configs = parse_configs_from_annotation(parsed_type)
72         if parsed_type.is_type_var and not configs:
73             return cls
74 
75         if configs:
76             # provided config is always preferred
77             config = configs[0]
78         elif hasattr(cls, "config"):
79             # if no config is provided, but the class has one assigned, use that
80             config = cls.config
81         else:
82             # otherwise, create a new config
83             config = DTOConfig()
84 
85         cls_dict: dict[str, Any] = {"config": config, "_type_backend_map": {}, "_handler_backend_map": {}}
86         if not parsed_type.is_type_var:
87             cls_dict.update(model_type=parsed_type.annotation)
88 
89         return type(f"{cls.__name__}[{annotation}]", (cls,), cls_dict)
90 
91     def builtins_to_data_type(self, builtins: Any) -> Any:
92         """Coerce the unstructured data into the data type."""
93         backend = self._get_backend("data", self.connection_context.handler_id)
94         return backend.populate_data_from_builtins(builtins, self.connection_context)
95 
96     def bytes_to_data_type(self, raw: bytes) -> Any:
97         """Return the data held by the DTO."""
98         backend = self._get_backend("data", self.connection_context.handler_id)
99         return backend.populate_data_from_raw(raw, self.connection_context)
100 
101     def data_to_encodable_type(self, data: T | Collection[T]) -> LitestarEncodableType:
102         backend = self._get_backend("return", self.connection_context.handler_id)
103         return backend.encode_data(data, self.connection_context)
104 
105     @classmethod
106     @abstractmethod
107     def generate_field_definitions(cls, model_type: type[Any]) -> Generator[FieldDefinition, None, None]:
108         """Generate ``FieldDefinition`` instances from ``model_type``.
109 
110         Yields:
111             ``FieldDefinition`` instances.
112         """
113 
114     @classmethod
115     @abstractmethod
116     def detect_nested_field(cls, parsed_type: ParsedType) -> bool:
117         """Return ``True`` if ``field_definition`` represents a nested model field.
118 
119         Args:
120             parsed_type: inspect type to determine if field represents a nested model.
121 
122         Returns:
123             ``True`` if ``parsed_type`` represents a nested model field.
124         """
125 
126     @classmethod
127     def on_registration(cls, handler_context: HandlerContext) -> None:
128         """Called each time the DTO type is encountered during signature modelling.
129 
130         Args:
131             handler_context: A :class:`HandlerContext <.HandlerContext>` instance. Provides information about the
132                 handler and application of the DTO.
133         """
134         if handler_context.parsed_type.is_subclass_of(DTOData):
135             parsed_type = handler_context.parsed_type.annotation.parsed_type
136         else:
137             parsed_type = handler_context.parsed_type
138 
139         if parsed_type.is_collection:
140             if len(parsed_type.inner_types) != 1:
141                 raise InvalidAnnotation("AbstractDTOFactory only supports homogeneous collection types")
142             handler_type = parsed_type.inner_types[0]
143         else:
144             handler_type = parsed_type
145 
146         if not handler_type.is_subclass_of(cls.model_type):
147             raise InvalidAnnotation(
148                 f"DTO narrowed with '{cls.model_type}', handler type is '{handler_context.parsed_type.annotation}'"
149             )
150 
151         key = (handler_context.dto_for, handler_context.parsed_type, handler_context.request_encoding_type)
152         backend = cls._type_backend_map.get(key)
153         if backend is None:
154             backend_type: type[AbstractDTOBackend]
155             if handler_context.request_encoding_type in {
156                 RequestEncodingType.URL_ENCODED,
157                 RequestEncodingType.MULTI_PART,
158             }:
159                 backend_type = PydanticDTOBackend
160             else:
161                 backend_type = MsgspecDTOBackend
162 
163             backend_context = BackendContext(
164                 cls.config,
165                 handler_context.dto_for,
166                 handler_context.parsed_type,
167                 cls.generate_field_definitions,
168                 cls.detect_nested_field,
169                 handler_type.annotation,
170             )
171             backend = cls._type_backend_map.setdefault(key, backend_type(backend_context))
172         cls._handler_backend_map[(handler_context.dto_for, handler_context.handler_id)] = backend
173 
174     @classmethod
175     def create_openapi_schema(
176         cls,
177         dto_for: ForType,
178         handler_id: str,
179         generate_examples: bool,
180         schemas: dict[str, Schema],
181     ) -> Reference | Schema:
182         """Create an OpenAPI request body.
183 
184         Returns:
185             OpenAPI request body.
186         """
187         backend = cls._get_backend(dto_for, handler_id)
188         return backend.create_openapi_schema(generate_examples, schemas)
189 
190     @classmethod
191     def _get_backend(cls, dto_for: ForType, handler_id: str) -> AbstractDTOBackend:
192         """Return the backend for the handler/dto_for combo."""
193         return cls._handler_backend_map[(dto_for, handler_id)]
194
```

Path: `litestar/contrib/repository/filters.py`
Content:
```
1 """Collection filter datastructures."""
2 from __future__ import annotations
3 
4 from collections import abc  # noqa: TCH003
5 from dataclasses import dataclass
6 from datetime import datetime  # noqa: TCH003
7 from typing import Generic, Literal, TypeVar
8 
9 T = TypeVar("T")
10 
11 __all__ = ["BeforeAfter", "CollectionFilter", "LimitOffset", "OrderBy", "SearchFilter"]
12 
13 
14 @dataclass
15 class BeforeAfter:
16     """Data required to filter a query on a ``datetime`` column."""
17 
18     field_name: str
19     """Name of the model attribute to filter on."""
20     before: datetime | None
21     """Filter results where field earlier than this."""
22     after: datetime | None
23     """Filter results where field later than this."""
24 
25 
26 @dataclass
27 class CollectionFilter(Generic[T]):
28     """Data required to construct a ``WHERE ... IN (...)`` clause."""
29 
30     field_name: str
31     """Name of the model attribute to filter on."""
32     values: abc.Collection[T]
33     """Values for ``IN`` clause."""
34 
35 
36 @dataclass
37 class LimitOffset:
38     """Data required to add limit/offset filtering to a query."""
39 
40     limit: int
41     """Value for ``LIMIT`` clause of query."""
42     offset: int
43     """Value for ``OFFSET`` clause of query."""
44 
45 
46 @dataclass
47 class OrderBy:
48     """Data required to construct a ``ORDER BY ...`` clause."""
49 
50     field_name: str
51     """Name of the model attribute to sort on."""
52     sort_order: Literal["asc", "desc"] = "asc"
53     """Sort ascending or descending"""
54 
55 
56 @dataclass
57 class SearchFilter:
58     """Data required to construct a ``WHERE field_name LIKE '%' || :value || '%'`` clause."""
59 
60     field_name: str
61     """Name of the model attribute to sort on."""
62     value: str
63     """Values for ``LIKE`` clause."""
64     ignore_case: bool | None = False
65     """Should the search be case insensitive."""
66
```
--- 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/repository/filters.py b/litestar/contrib/repository/filters.py
--- a/litestar/contrib/repository/filters.py
+++ b/litestar/contrib/repository/filters.py
@@ -8,7 +8,13 @@
 
 T = TypeVar("T")
 
-__all__ = ["BeforeAfter", "CollectionFilter", "LimitOffset", "OrderBy", "SearchFilter"]
+__all__ = (
+    "BeforeAfter",
+    "CollectionFilter",
+    "LimitOffset",
+    "OrderBy",
+    "SearchFilter",
+)
 
 
 @dataclass
diff --git a/litestar/dto/exceptions.py b/litestar/dto/exceptions.py
--- a/litestar/dto/exceptions.py
+++ b/litestar/dto/exceptions.py
@@ -2,7 +2,7 @@
 
 from litestar.exceptions import ImproperlyConfiguredException
 
-__all__ = ["DTOException", "UnsupportedType"]
+__all__ = ("DTOException", "UnsupportedType")
 
 
 class DTOException(ImproperlyConfiguredException):
diff --git a/litestar/dto/factory/abc.py b/litestar/dto/factory/abc.py
--- a/litestar/dto/factory/abc.py
+++ b/litestar/dto/factory/abc.py
@@ -27,7 +27,7 @@
     from ._backends import AbstractDTOBackend
     from .types import FieldDefinition
 
-__all__ = ["AbstractDTOFactory"]
+__all__ = ("AbstractDTOFactory",)
 
 T = TypeVar("T")

{"golden_diff": "diff --git a/litestar/contrib/repository/filters.py b/litestar/contrib/repository/filters.py\n--- a/litestar/contrib/repository/filters.py\n+++ b/litestar/contrib/repository/filters.py\n@@ -8,7 +8,13 @@\n \n T = TypeVar(\"T\")\n \n-__all__ = [\"BeforeAfter\", \"CollectionFilter\", \"LimitOffset\", \"OrderBy\", \"SearchFilter\"]\n+__all__ = (\n+    \"BeforeAfter\",\n+    \"CollectionFilter\",\n+    \"LimitOffset\",\n+    \"OrderBy\",\n+    \"SearchFilter\",\n+)\n \n \n @dataclass\ndiff --git a/litestar/dto/exceptions.py b/litestar/dto/exceptions.py\n--- a/litestar/dto/exceptions.py\n+++ b/litestar/dto/exceptions.py\n@@ -2,7 +2,7 @@\n \n from litestar.exceptions import ImproperlyConfiguredException\n \n-__all__ = [\"DTOException\", \"UnsupportedType\"]\n+__all__ = (\"DTOException\", \"UnsupportedType\")\n \n \n class DTOException(ImproperlyConfiguredException):\ndiff --git a/litestar/dto/factory/abc.py b/litestar/dto/factory/abc.py\n--- a/litestar/dto/factory/abc.py\n+++ b/litestar/dto/factory/abc.py\n@@ -27,7 +27,7 @@\n     from ._backends import AbstractDTOBackend\n     from .types import FieldDefinition\n \n-__all__ = [\"AbstractDTOFactory\"]\n+__all__ = (\"AbstractDTOFactory\",)\n \n T = TypeVar(\"T\")\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 litestar.exceptions import ImproperlyConfiguredException\n\n__all__ = [\"DTOException\", \"UnsupportedType\"]\n\n\nclass DTOException(ImproperlyConfiguredException):\n    \"\"\"Base exception for DTO errors.\"\"\"\n\n\nclass UnsupportedType(DTOException):\n    \"\"\"Raised when a type is not supported by Litestar.\"\"\"\n", "path": "litestar/dto/exceptions.py"}, {"content": "from __future__ import annotations\n\nfrom abc import ABCMeta, abstractmethod\nfrom typing import TYPE_CHECKING, Generic, TypeVar\n\nfrom litestar.dto.interface import ConnectionContext, DTOInterface\nfrom litestar.enums import RequestEncodingType\nfrom litestar.typing import ParsedType\n\nfrom ._backends import MsgspecDTOBackend, PydanticDTOBackend\nfrom ._backends.abc import BackendContext\nfrom .config import DTOConfig\nfrom .data_structures import DTOData\nfrom .exc import InvalidAnnotation\nfrom .utils import parse_configs_from_annotation\n\nif TYPE_CHECKING:\n    from typing import Any, ClassVar, Collection, Generator\n\n    from typing_extensions import Self\n\n    from litestar.dto.interface import HandlerContext\n    from litestar.dto.types import ForType\n    from litestar.openapi.spec import Reference, Schema\n    from litestar.types.serialization import LitestarEncodableType\n\n    from ._backends import AbstractDTOBackend\n    from .types import FieldDefinition\n\n__all__ = [\"AbstractDTOFactory\"]\n\nT = TypeVar(\"T\")\n\n\nclass AbstractDTOFactory(DTOInterface, Generic[T], metaclass=ABCMeta):\n    \"\"\"Base class for DTO types.\"\"\"\n\n    __slots__ = (\"connection_context\",)\n\n    config: ClassVar[DTOConfig]\n    \"\"\"Config objects to define properties of the DTO.\"\"\"\n    model_type: ClassVar[type[Any]]\n    \"\"\"If ``annotation`` is an iterable, this is the inner type, otherwise will be the same as ``annotation``.\"\"\"\n\n    _type_backend_map: ClassVar[dict[tuple[ForType, ParsedType, RequestEncodingType | str | None], AbstractDTOBackend]]\n    _handler_backend_map: ClassVar[dict[tuple[ForType, str], AbstractDTOBackend]]\n\n    def __init__(self, connection_context: ConnectionContext) -> None:\n        \"\"\"Create an AbstractDTOFactory type.\n\n        Args:\n            connection_context: A :class:`ConnectionContext <.ConnectionContext>` instance, which provides\n                information about the connection.\n        \"\"\"\n        self.connection_context = connection_context\n\n    def __class_getitem__(cls, annotation: Any) -> type[Self]:\n        parsed_type = ParsedType(annotation)\n\n        if (parsed_type.is_optional and len(parsed_type.args) > 2) or (\n            parsed_type.is_union and not parsed_type.is_optional\n        ):\n            raise InvalidAnnotation(\n                \"Unions are currently not supported as type argument to DTO. Want this? Open an issue.\"\n            )\n\n        if parsed_type.is_forward_ref:\n            raise InvalidAnnotation(\"Forward references are not supported as type argument to DTO\")\n\n        # if a configuration is not provided, and the type narrowing is a type var, we don't want to create a subclass\n        configs = parse_configs_from_annotation(parsed_type)\n        if parsed_type.is_type_var and not configs:\n            return cls\n\n        if configs:\n            # provided config is always preferred\n            config = configs[0]\n        elif hasattr(cls, \"config\"):\n            # if no config is provided, but the class has one assigned, use that\n            config = cls.config\n        else:\n            # otherwise, create a new config\n            config = DTOConfig()\n\n        cls_dict: dict[str, Any] = {\"config\": config, \"_type_backend_map\": {}, \"_handler_backend_map\": {}}\n        if not parsed_type.is_type_var:\n            cls_dict.update(model_type=parsed_type.annotation)\n\n        return type(f\"{cls.__name__}[{annotation}]\", (cls,), cls_dict)\n\n    def builtins_to_data_type(self, builtins: Any) -> Any:\n        \"\"\"Coerce the unstructured data into the data type.\"\"\"\n        backend = self._get_backend(\"data\", self.connection_context.handler_id)\n        return backend.populate_data_from_builtins(builtins, self.connection_context)\n\n    def bytes_to_data_type(self, raw: bytes) -> Any:\n        \"\"\"Return the data held by the DTO.\"\"\"\n        backend = self._get_backend(\"data\", self.connection_context.handler_id)\n        return backend.populate_data_from_raw(raw, self.connection_context)\n\n    def data_to_encodable_type(self, data: T | Collection[T]) -> LitestarEncodableType:\n        backend = self._get_backend(\"return\", self.connection_context.handler_id)\n        return backend.encode_data(data, self.connection_context)\n\n    @classmethod\n    @abstractmethod\n    def generate_field_definitions(cls, model_type: type[Any]) -> Generator[FieldDefinition, None, None]:\n        \"\"\"Generate ``FieldDefinition`` instances from ``model_type``.\n\n        Yields:\n            ``FieldDefinition`` instances.\n        \"\"\"\n\n    @classmethod\n    @abstractmethod\n    def detect_nested_field(cls, parsed_type: ParsedType) -> bool:\n        \"\"\"Return ``True`` if ``field_definition`` represents a nested model field.\n\n        Args:\n            parsed_type: inspect type to determine if field represents a nested model.\n\n        Returns:\n            ``True`` if ``parsed_type`` represents a nested model field.\n        \"\"\"\n\n    @classmethod\n    def on_registration(cls, handler_context: HandlerContext) -> None:\n        \"\"\"Called each time the DTO type is encountered during signature modelling.\n\n        Args:\n            handler_context: A :class:`HandlerContext <.HandlerContext>` instance. Provides information about the\n                handler and application of the DTO.\n        \"\"\"\n        if handler_context.parsed_type.is_subclass_of(DTOData):\n            parsed_type = handler_context.parsed_type.annotation.parsed_type\n        else:\n            parsed_type = handler_context.parsed_type\n\n        if parsed_type.is_collection:\n            if len(parsed_type.inner_types) != 1:\n                raise InvalidAnnotation(\"AbstractDTOFactory only supports homogeneous collection types\")\n            handler_type = parsed_type.inner_types[0]\n        else:\n            handler_type = parsed_type\n\n        if not handler_type.is_subclass_of(cls.model_type):\n            raise InvalidAnnotation(\n                f\"DTO narrowed with '{cls.model_type}', handler type is '{handler_context.parsed_type.annotation}'\"\n            )\n\n        key = (handler_context.dto_for, handler_context.parsed_type, handler_context.request_encoding_type)\n        backend = cls._type_backend_map.get(key)\n        if backend is None:\n            backend_type: type[AbstractDTOBackend]\n            if handler_context.request_encoding_type in {\n                RequestEncodingType.URL_ENCODED,\n                RequestEncodingType.MULTI_PART,\n            }:\n                backend_type = PydanticDTOBackend\n            else:\n                backend_type = MsgspecDTOBackend\n\n            backend_context = BackendContext(\n                cls.config,\n                handler_context.dto_for,\n                handler_context.parsed_type,\n                cls.generate_field_definitions,\n                cls.detect_nested_field,\n                handler_type.annotation,\n            )\n            backend = cls._type_backend_map.setdefault(key, backend_type(backend_context))\n        cls._handler_backend_map[(handler_context.dto_for, handler_context.handler_id)] = backend\n\n    @classmethod\n    def create_openapi_schema(\n        cls,\n        dto_for: ForType,\n        handler_id: str,\n        generate_examples: bool,\n        schemas: dict[str, Schema],\n    ) -> Reference | Schema:\n        \"\"\"Create an OpenAPI request body.\n\n        Returns:\n            OpenAPI request body.\n        \"\"\"\n        backend = cls._get_backend(dto_for, handler_id)\n        return backend.create_openapi_schema(generate_examples, schemas)\n\n    @classmethod\n    def _get_backend(cls, dto_for: ForType, handler_id: str) -> AbstractDTOBackend:\n        \"\"\"Return the backend for the handler/dto_for combo.\"\"\"\n        return cls._handler_backend_map[(dto_for, handler_id)]\n", "path": "litestar/dto/factory/abc.py"}, {"content": "\"\"\"Collection filter datastructures.\"\"\"\nfrom __future__ import annotations\n\nfrom collections import abc  # noqa: TCH003\nfrom dataclasses import dataclass\nfrom datetime import datetime  # noqa: TCH003\nfrom typing import Generic, Literal, TypeVar\n\nT = TypeVar(\"T\")\n\n__all__ = [\"BeforeAfter\", \"CollectionFilter\", \"LimitOffset\", \"OrderBy\", \"SearchFilter\"]\n\n\n@dataclass\nclass BeforeAfter:\n    \"\"\"Data required to filter a query on a ``datetime`` column.\"\"\"\n\n    field_name: str\n    \"\"\"Name of the model attribute to filter on.\"\"\"\n    before: datetime | None\n    \"\"\"Filter results where field earlier than this.\"\"\"\n    after: datetime | None\n    \"\"\"Filter results where field later than this.\"\"\"\n\n\n@dataclass\nclass CollectionFilter(Generic[T]):\n    \"\"\"Data required to construct a ``WHERE ... IN (...)`` clause.\"\"\"\n\n    field_name: str\n    \"\"\"Name of the model attribute to filter on.\"\"\"\n    values: abc.Collection[T]\n    \"\"\"Values for ``IN`` clause.\"\"\"\n\n\n@dataclass\nclass LimitOffset:\n    \"\"\"Data required to add limit/offset filtering to a query.\"\"\"\n\n    limit: int\n    \"\"\"Value for ``LIMIT`` clause of query.\"\"\"\n    offset: int\n    \"\"\"Value for ``OFFSET`` clause of query.\"\"\"\n\n\n@dataclass\nclass OrderBy:\n    \"\"\"Data required to construct a ``ORDER BY ...`` clause.\"\"\"\n\n    field_name: str\n    \"\"\"Name of the model attribute to sort on.\"\"\"\n    sort_order: Literal[\"asc\", \"desc\"] = \"asc\"\n    \"\"\"Sort ascending or descending\"\"\"\n\n\n@dataclass\nclass SearchFilter:\n    \"\"\"Data required to construct a ``WHERE field_name LIKE '%' || :value || '%'`` clause.\"\"\"\n\n    field_name: str\n    \"\"\"Name of the model attribute to sort on.\"\"\"\n    value: str\n    \"\"\"Values for ``LIKE`` clause.\"\"\"\n    ignore_case: bool | None = False\n    \"\"\"Should the search be case insensitive.\"\"\"\n", "path": "litestar/contrib/repository/filters.py"}], "after_files": [{"content": "from __future__ import annotations\n\nfrom litestar.exceptions import ImproperlyConfiguredException\n\n__all__ = (\"DTOException\", \"UnsupportedType\")\n\n\nclass DTOException(ImproperlyConfiguredException):\n    \"\"\"Base exception for DTO errors.\"\"\"\n\n\nclass UnsupportedType(DTOException):\n    \"\"\"Raised when a type is not supported by Litestar.\"\"\"\n", "path": "litestar/dto/exceptions.py"}, {"content": "from __future__ import annotations\n\nfrom abc import ABCMeta, abstractmethod\nfrom typing import TYPE_CHECKING, Generic, TypeVar\n\nfrom litestar.dto.interface import ConnectionContext, DTOInterface\nfrom litestar.enums import RequestEncodingType\nfrom litestar.typing import ParsedType\n\nfrom ._backends import MsgspecDTOBackend, PydanticDTOBackend\nfrom ._backends.abc import BackendContext\nfrom .config import DTOConfig\nfrom .data_structures import DTOData\nfrom .exc import InvalidAnnotation\nfrom .utils import parse_configs_from_annotation\n\nif TYPE_CHECKING:\n    from typing import Any, ClassVar, Collection, Generator\n\n    from typing_extensions import Self\n\n    from litestar.dto.interface import HandlerContext\n    from litestar.dto.types import ForType\n    from litestar.openapi.spec import Reference, Schema\n    from litestar.types.serialization import LitestarEncodableType\n\n    from ._backends import AbstractDTOBackend\n    from .types import FieldDefinition\n\n__all__ = (\"AbstractDTOFactory\",)\n\nT = TypeVar(\"T\")\n\n\nclass AbstractDTOFactory(DTOInterface, Generic[T], metaclass=ABCMeta):\n    \"\"\"Base class for DTO types.\"\"\"\n\n    __slots__ = (\"connection_context\",)\n\n    config: ClassVar[DTOConfig]\n    \"\"\"Config objects to define properties of the DTO.\"\"\"\n    model_type: ClassVar[type[Any]]\n    \"\"\"If ``annotation`` is an iterable, this is the inner type, otherwise will be the same as ``annotation``.\"\"\"\n\n    _type_backend_map: ClassVar[dict[tuple[ForType, ParsedType, RequestEncodingType | str | None], AbstractDTOBackend]]\n    _handler_backend_map: ClassVar[dict[tuple[ForType, str], AbstractDTOBackend]]\n\n    def __init__(self, connection_context: ConnectionContext) -> None:\n        \"\"\"Create an AbstractDTOFactory type.\n\n        Args:\n            connection_context: A :class:`ConnectionContext <.ConnectionContext>` instance, which provides\n                information about the connection.\n        \"\"\"\n        self.connection_context = connection_context\n\n    def __class_getitem__(cls, annotation: Any) -> type[Self]:\n        parsed_type = ParsedType(annotation)\n\n        if (parsed_type.is_optional and len(parsed_type.args) > 2) or (\n            parsed_type.is_union and not parsed_type.is_optional\n        ):\n            raise InvalidAnnotation(\n                \"Unions are currently not supported as type argument to DTO. Want this? Open an issue.\"\n            )\n\n        if parsed_type.is_forward_ref:\n            raise InvalidAnnotation(\"Forward references are not supported as type argument to DTO\")\n\n        # if a configuration is not provided, and the type narrowing is a type var, we don't want to create a subclass\n        configs = parse_configs_from_annotation(parsed_type)\n        if parsed_type.is_type_var and not configs:\n            return cls\n\n        if configs:\n            # provided config is always preferred\n            config = configs[0]\n        elif hasattr(cls, \"config\"):\n            # if no config is provided, but the class has one assigned, use that\n            config = cls.config\n        else:\n            # otherwise, create a new config\n            config = DTOConfig()\n\n        cls_dict: dict[str, Any] = {\"config\": config, \"_type_backend_map\": {}, \"_handler_backend_map\": {}}\n        if not parsed_type.is_type_var:\n            cls_dict.update(model_type=parsed_type.annotation)\n\n        return type(f\"{cls.__name__}[{annotation}]\", (cls,), cls_dict)\n\n    def builtins_to_data_type(self, builtins: Any) -> Any:\n        \"\"\"Coerce the unstructured data into the data type.\"\"\"\n        backend = self._get_backend(\"data\", self.connection_context.handler_id)\n        return backend.populate_data_from_builtins(builtins, self.connection_context)\n\n    def bytes_to_data_type(self, raw: bytes) -> Any:\n        \"\"\"Return the data held by the DTO.\"\"\"\n        backend = self._get_backend(\"data\", self.connection_context.handler_id)\n        return backend.populate_data_from_raw(raw, self.connection_context)\n\n    def data_to_encodable_type(self, data: T | Collection[T]) -> LitestarEncodableType:\n        backend = self._get_backend(\"return\", self.connection_context.handler_id)\n        return backend.encode_data(data, self.connection_context)\n\n    @classmethod\n    @abstractmethod\n    def generate_field_definitions(cls, model_type: type[Any]) -> Generator[FieldDefinition, None, None]:\n        \"\"\"Generate ``FieldDefinition`` instances from ``model_type``.\n\n        Yields:\n            ``FieldDefinition`` instances.\n        \"\"\"\n\n    @classmethod\n    @abstractmethod\n    def detect_nested_field(cls, parsed_type: ParsedType) -> bool:\n        \"\"\"Return ``True`` if ``field_definition`` represents a nested model field.\n\n        Args:\n            parsed_type: inspect type to determine if field represents a nested model.\n\n        Returns:\n            ``True`` if ``parsed_type`` represents a nested model field.\n        \"\"\"\n\n    @classmethod\n    def on_registration(cls, handler_context: HandlerContext) -> None:\n        \"\"\"Called each time the DTO type is encountered during signature modelling.\n\n        Args:\n            handler_context: A :class:`HandlerContext <.HandlerContext>` instance. Provides information about the\n                handler and application of the DTO.\n        \"\"\"\n        if handler_context.parsed_type.is_subclass_of(DTOData):\n            parsed_type = handler_context.parsed_type.annotation.parsed_type\n        else:\n            parsed_type = handler_context.parsed_type\n\n        if parsed_type.is_collection:\n            if len(parsed_type.inner_types) != 1:\n                raise InvalidAnnotation(\"AbstractDTOFactory only supports homogeneous collection types\")\n            handler_type = parsed_type.inner_types[0]\n        else:\n            handler_type = parsed_type\n\n        if not handler_type.is_subclass_of(cls.model_type):\n            raise InvalidAnnotation(\n                f\"DTO narrowed with '{cls.model_type}', handler type is '{handler_context.parsed_type.annotation}'\"\n            )\n\n        key = (handler_context.dto_for, handler_context.parsed_type, handler_context.request_encoding_type)\n        backend = cls._type_backend_map.get(key)\n        if backend is None:\n            backend_type: type[AbstractDTOBackend]\n            if handler_context.request_encoding_type in {\n                RequestEncodingType.URL_ENCODED,\n                RequestEncodingType.MULTI_PART,\n            }:\n                backend_type = PydanticDTOBackend\n            else:\n                backend_type = MsgspecDTOBackend\n\n            backend_context = BackendContext(\n                cls.config,\n                handler_context.dto_for,\n                handler_context.parsed_type,\n                cls.generate_field_definitions,\n                cls.detect_nested_field,\n                handler_type.annotation,\n            )\n            backend = cls._type_backend_map.setdefault(key, backend_type(backend_context))\n        cls._handler_backend_map[(handler_context.dto_for, handler_context.handler_id)] = backend\n\n    @classmethod\n    def create_openapi_schema(\n        cls,\n        dto_for: ForType,\n        handler_id: str,\n        generate_examples: bool,\n        schemas: dict[str, Schema],\n    ) -> Reference | Schema:\n        \"\"\"Create an OpenAPI request body.\n\n        Returns:\n            OpenAPI request body.\n        \"\"\"\n        backend = cls._get_backend(dto_for, handler_id)\n        return backend.create_openapi_schema(generate_examples, schemas)\n\n    @classmethod\n    def _get_backend(cls, dto_for: ForType, handler_id: str) -> AbstractDTOBackend:\n        \"\"\"Return the backend for the handler/dto_for combo.\"\"\"\n        return cls._handler_backend_map[(dto_for, handler_id)]\n", "path": "litestar/dto/factory/abc.py"}, {"content": "\"\"\"Collection filter datastructures.\"\"\"\nfrom __future__ import annotations\n\nfrom collections import abc  # noqa: TCH003\nfrom dataclasses import dataclass\nfrom datetime import datetime  # noqa: TCH003\nfrom typing import Generic, Literal, TypeVar\n\nT = TypeVar(\"T\")\n\n__all__ = (\n    \"BeforeAfter\",\n    \"CollectionFilter\",\n    \"LimitOffset\",\n    \"OrderBy\",\n    \"SearchFilter\",\n)\n\n\n@dataclass\nclass BeforeAfter:\n    \"\"\"Data required to filter a query on a ``datetime`` column.\"\"\"\n\n    field_name: str\n    \"\"\"Name of the model attribute to filter on.\"\"\"\n    before: datetime | None\n    \"\"\"Filter results where field earlier than this.\"\"\"\n    after: datetime | None\n    \"\"\"Filter results where field later than this.\"\"\"\n\n\n@dataclass\nclass CollectionFilter(Generic[T]):\n    \"\"\"Data required to construct a ``WHERE ... IN (...)`` clause.\"\"\"\n\n    field_name: str\n    \"\"\"Name of the model attribute to filter on.\"\"\"\n    values: abc.Collection[T]\n    \"\"\"Values for ``IN`` clause.\"\"\"\n\n\n@dataclass\nclass LimitOffset:\n    \"\"\"Data required to add limit/offset filtering to a query.\"\"\"\n\n    limit: int\n    \"\"\"Value for ``LIMIT`` clause of query.\"\"\"\n    offset: int\n    \"\"\"Value for ``OFFSET`` clause of query.\"\"\"\n\n\n@dataclass\nclass OrderBy:\n    \"\"\"Data required to construct a ``ORDER BY ...`` clause.\"\"\"\n\n    field_name: str\n    \"\"\"Name of the model attribute to sort on.\"\"\"\n    sort_order: Literal[\"asc\", \"desc\"] = \"asc\"\n    \"\"\"Sort ascending or descending\"\"\"\n\n\n@dataclass\nclass SearchFilter:\n    \"\"\"Data required to construct a ``WHERE field_name LIKE '%' || :value || '%'`` clause.\"\"\"\n\n    field_name: str\n    \"\"\"Name of the model attribute to sort on.\"\"\"\n    value: str\n    \"\"\"Values for ``LIKE`` clause.\"\"\"\n    ignore_case: bool | None = False\n    \"\"\"Should the search be case insensitive.\"\"\"\n", "path": "litestar/contrib/repository/filters.py"}]}