prompt: 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/jwt/jwt_token.py`
  Content:
  ```
  1 from __future__ import annotations
  2 
  3 from dataclasses import asdict, dataclass, field
  4 from datetime import datetime, timezone
  5 from typing import cast
  6 
  7 from jose import JWSError, JWTError, jwt
  8 
  9 from litestar.exceptions import ImproperlyConfiguredException, NotAuthorizedException
  10 
  11 __all__ = ("Token",)
  12 
  13 
  14 def _normalize_datetime(value: datetime) -> datetime:
  15     """Convert the given value into UTC and strip microseconds.
  16 
  17     Args:
  18         value: A datetime instance
  19 
  20     Returns:
  21         A datetime instance
  22     """
  23     if value.tzinfo is not None:
  24         value.astimezone(timezone.utc)
  25 
  26     return value.replace(microsecond=0)
  27 
  28 
  29 @dataclass
  30 class Token:
  31     """JWT Token DTO."""
  32 
  33     exp: datetime
  34     """Expiration - datetime for token expiration."""
  35     sub: str
  36     """Subject - usually a unique identifier of the user or equivalent entity."""
  37     iat: datetime = field(default_factory=lambda: _normalize_datetime(datetime.now(timezone.utc)))
  38     """Issued at - should always be current now."""
  39     iss: str | None = field(default=None)
  40     """Issuer - optional unique identifier for the issuer."""
  41     aud: str | None = field(default=None)
  42     """Audience - intended audience."""
  43     jti: str | None = field(default=None)
  44     """JWT ID - a unique identifier of the JWT between different issuers."""
  45 
  46     def __post_init__(self) -> None:
  47         if len(self.sub) < 1:
  48             raise ImproperlyConfiguredException("sub must be a string with a length greater than 0")
  49 
  50         if isinstance(self.exp, datetime) and (
  51             (exp := _normalize_datetime(self.exp))
  52             and exp.timestamp() >= _normalize_datetime(datetime.now(timezone.utc)).timestamp()
  53         ):
  54             self.exp = exp
  55         else:
  56             raise ImproperlyConfiguredException("exp value must be a datetime in the future")
  57 
  58         if isinstance(self.iat, datetime) and (
  59             (iat := _normalize_datetime(self.iat))
  60             and iat.timestamp() <= _normalize_datetime(datetime.now(timezone.utc)).timestamp()
  61         ):
  62             self.iat = iat
  63         else:
  64             raise ImproperlyConfiguredException("iat must be a current or past time")
  65 
  66     @staticmethod
  67     def decode(encoded_token: str, secret: str | dict[str, str], algorithm: str) -> Token:
  68         """Decode a passed in token string and returns a Token instance.
  69 
  70         Args:
  71             encoded_token: A base64 string containing an encoded JWT.
  72             secret: The secret with which the JWT is encoded. It may optionally be an individual JWK or JWS set dict
  73             algorithm: The algorithm used to encode the JWT.
  74 
  75         Returns:
  76             A decoded Token instance.
  77 
  78         Raises:
  79             NotAuthorizedException: If the token is invalid.
  80         """
  81         try:
  82             payload = jwt.decode(token=encoded_token, key=secret, algorithms=[algorithm], options={"verify_aud": False})
  83             exp = datetime.fromtimestamp(payload.pop("exp"), tz=timezone.utc)
  84             iat = datetime.fromtimestamp(payload.pop("iat"), tz=timezone.utc)
  85             return Token(exp=exp, iat=iat, **payload)
  86         except (KeyError, JWTError, ImproperlyConfiguredException) as e:
  87             raise NotAuthorizedException("Invalid token") from e
  88 
  89     def encode(self, secret: str, algorithm: str) -> str:
  90         """Encode the token instance into a string.
  91 
  92         Args:
  93             secret: The secret with which the JWT is encoded.
  94             algorithm: The algorithm used to encode the JWT.
  95 
  96         Returns:
  97             An encoded token string.
  98 
  99         Raises:
  100             ImproperlyConfiguredException: If encoding fails.
  101         """
  102         try:
  103             return cast(
  104                 "str",
  105                 jwt.encode(
  106                     claims={k: v for k, v in asdict(self).items() if v is not None}, key=secret, algorithm=algorithm
  107                 ),
  108             )
  109         except (JWTError, JWSError) as e:
  110             raise ImproperlyConfiguredException("Failed to encode token") from e
  111
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/litestar/contrib/jwt/jwt_token.py b/litestar/contrib/jwt/jwt_token.py
  --- a/litestar/contrib/jwt/jwt_token.py
  +++ b/litestar/contrib/jwt/jwt_token.py
  @@ -1,13 +1,18 @@
   from __future__ import annotations
   
  +import dataclasses
   from dataclasses import asdict, dataclass, field
   from datetime import datetime, timezone
  -from typing import cast
  +from typing import TYPE_CHECKING, Any, cast
   
   from jose import JWSError, JWTError, jwt
   
   from litestar.exceptions import ImproperlyConfiguredException, NotAuthorizedException
   
  +if TYPE_CHECKING:
  +    from typing_extensions import Self
  +
  +
   __all__ = ("Token",)
   
   
  @@ -42,6 +47,8 @@
       """Audience - intended audience."""
       jti: str | None = field(default=None)
       """JWT ID - a unique identifier of the JWT between different issuers."""
  +    extras: dict[str, Any] = field(default_factory=dict)
  +    """Extra fields that were found on the JWT token."""
   
       def __post_init__(self) -> None:
           if len(self.sub) < 1:
  @@ -63,8 +70,8 @@
           else:
               raise ImproperlyConfiguredException("iat must be a current or past time")
   
  -    @staticmethod
  -    def decode(encoded_token: str, secret: str | dict[str, str], algorithm: str) -> Token:
  +    @classmethod
  +    def decode(cls, encoded_token: str, secret: str | dict[str, str], algorithm: str) -> Self:
           """Decode a passed in token string and returns a Token instance.
   
           Args:
  @@ -82,7 +89,12 @@
               payload = jwt.decode(token=encoded_token, key=secret, algorithms=[algorithm], options={"verify_aud": False})
               exp = datetime.fromtimestamp(payload.pop("exp"), tz=timezone.utc)
               iat = datetime.fromtimestamp(payload.pop("iat"), tz=timezone.utc)
  -            return Token(exp=exp, iat=iat, **payload)
  +            field_names = {f.name for f in dataclasses.fields(Token)}
  +            extra_fields = payload.keys() - field_names
  +            extras = payload.pop("extras", {})
  +            for key in extra_fields:
  +                extras[key] = payload.pop(key)
  +            return cls(exp=exp, iat=iat, **payload, extras=extras)
           except (KeyError, JWTError, ImproperlyConfiguredException) as e:
               raise NotAuthorizedException("Invalid token") from e
  
verification_info: {"golden_diff": "diff --git a/litestar/contrib/jwt/jwt_token.py b/litestar/contrib/jwt/jwt_token.py\n--- a/litestar/contrib/jwt/jwt_token.py\n+++ b/litestar/contrib/jwt/jwt_token.py\n@@ -1,13 +1,18 @@\n from __future__ import annotations\n \n+import dataclasses\n from dataclasses import asdict, dataclass, field\n from datetime import datetime, timezone\n-from typing import cast\n+from typing import TYPE_CHECKING, Any, cast\n \n from jose import JWSError, JWTError, jwt\n \n from litestar.exceptions import ImproperlyConfiguredException, NotAuthorizedException\n \n+if TYPE_CHECKING:\n+    from typing_extensions import Self\n+\n+\n __all__ = (\"Token\",)\n \n \n@@ -42,6 +47,8 @@\n     \"\"\"Audience - intended audience.\"\"\"\n     jti: str | None = field(default=None)\n     \"\"\"JWT ID - a unique identifier of the JWT between different issuers.\"\"\"\n+    extras: dict[str, Any] = field(default_factory=dict)\n+    \"\"\"Extra fields that were found on the JWT token.\"\"\"\n \n     def __post_init__(self) -> None:\n         if len(self.sub) < 1:\n@@ -63,8 +70,8 @@\n         else:\n             raise ImproperlyConfiguredException(\"iat must be a current or past time\")\n \n-    @staticmethod\n-    def decode(encoded_token: str, secret: str | dict[str, str], algorithm: str) -> Token:\n+    @classmethod\n+    def decode(cls, encoded_token: str, secret: str | dict[str, str], algorithm: str) -> Self:\n         \"\"\"Decode a passed in token string and returns a Token instance.\n \n         Args:\n@@ -82,7 +89,12 @@\n             payload = jwt.decode(token=encoded_token, key=secret, algorithms=[algorithm], options={\"verify_aud\": False})\n             exp = datetime.fromtimestamp(payload.pop(\"exp\"), tz=timezone.utc)\n             iat = datetime.fromtimestamp(payload.pop(\"iat\"), tz=timezone.utc)\n-            return Token(exp=exp, iat=iat, **payload)\n+            field_names = {f.name for f in dataclasses.fields(Token)}\n+            extra_fields = payload.keys() - field_names\n+            extras = payload.pop(\"extras\", {})\n+            for key in extra_fields:\n+                extras[key] = payload.pop(key)\n+            return cls(exp=exp, iat=iat, **payload, extras=extras)\n         except (KeyError, JWTError, ImproperlyConfiguredException) as e:\n             raise NotAuthorizedException(\"Invalid token\") from e\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 asdict, dataclass, field\nfrom datetime import datetime, timezone\nfrom typing import cast\n\nfrom jose import JWSError, JWTError, jwt\n\nfrom litestar.exceptions import ImproperlyConfiguredException, NotAuthorizedException\n\n__all__ = (\"Token\",)\n\n\ndef _normalize_datetime(value: datetime) -> datetime:\n    \"\"\"Convert the given value into UTC and strip microseconds.\n\n    Args:\n        value: A datetime instance\n\n    Returns:\n        A datetime instance\n    \"\"\"\n    if value.tzinfo is not None:\n        value.astimezone(timezone.utc)\n\n    return value.replace(microsecond=0)\n\n\n@dataclass\nclass Token:\n    \"\"\"JWT Token DTO.\"\"\"\n\n    exp: datetime\n    \"\"\"Expiration - datetime for token expiration.\"\"\"\n    sub: str\n    \"\"\"Subject - usually a unique identifier of the user or equivalent entity.\"\"\"\n    iat: datetime = field(default_factory=lambda: _normalize_datetime(datetime.now(timezone.utc)))\n    \"\"\"Issued at - should always be current now.\"\"\"\n    iss: str | None = field(default=None)\n    \"\"\"Issuer - optional unique identifier for the issuer.\"\"\"\n    aud: str | None = field(default=None)\n    \"\"\"Audience - intended audience.\"\"\"\n    jti: str | None = field(default=None)\n    \"\"\"JWT ID - a unique identifier of the JWT between different issuers.\"\"\"\n\n    def __post_init__(self) -> None:\n        if len(self.sub) < 1:\n            raise ImproperlyConfiguredException(\"sub must be a string with a length greater than 0\")\n\n        if isinstance(self.exp, datetime) and (\n            (exp := _normalize_datetime(self.exp))\n            and exp.timestamp() >= _normalize_datetime(datetime.now(timezone.utc)).timestamp()\n        ):\n            self.exp = exp\n        else:\n            raise ImproperlyConfiguredException(\"exp value must be a datetime in the future\")\n\n        if isinstance(self.iat, datetime) and (\n            (iat := _normalize_datetime(self.iat))\n            and iat.timestamp() <= _normalize_datetime(datetime.now(timezone.utc)).timestamp()\n        ):\n            self.iat = iat\n        else:\n            raise ImproperlyConfiguredException(\"iat must be a current or past time\")\n\n    @staticmethod\n    def decode(encoded_token: str, secret: str | dict[str, str], algorithm: str) -> Token:\n        \"\"\"Decode a passed in token string and returns a Token instance.\n\n        Args:\n            encoded_token: A base64 string containing an encoded JWT.\n            secret: The secret with which the JWT is encoded. It may optionally be an individual JWK or JWS set dict\n            algorithm: The algorithm used to encode the JWT.\n\n        Returns:\n            A decoded Token instance.\n\n        Raises:\n            NotAuthorizedException: If the token is invalid.\n        \"\"\"\n        try:\n            payload = jwt.decode(token=encoded_token, key=secret, algorithms=[algorithm], options={\"verify_aud\": False})\n            exp = datetime.fromtimestamp(payload.pop(\"exp\"), tz=timezone.utc)\n            iat = datetime.fromtimestamp(payload.pop(\"iat\"), tz=timezone.utc)\n            return Token(exp=exp, iat=iat, **payload)\n        except (KeyError, JWTError, ImproperlyConfiguredException) as e:\n            raise NotAuthorizedException(\"Invalid token\") from e\n\n    def encode(self, secret: str, algorithm: str) -> str:\n        \"\"\"Encode the token instance into a string.\n\n        Args:\n            secret: The secret with which the JWT is encoded.\n            algorithm: The algorithm used to encode the JWT.\n\n        Returns:\n            An encoded token string.\n\n        Raises:\n            ImproperlyConfiguredException: If encoding fails.\n        \"\"\"\n        try:\n            return cast(\n                \"str\",\n                jwt.encode(\n                    claims={k: v for k, v in asdict(self).items() if v is not None}, key=secret, algorithm=algorithm\n                ),\n            )\n        except (JWTError, JWSError) as e:\n            raise ImproperlyConfiguredException(\"Failed to encode token\") from e\n", "path": "litestar/contrib/jwt/jwt_token.py"}], "after_files": [{"content": "from __future__ import annotations\n\nimport dataclasses\nfrom dataclasses import asdict, dataclass, field\nfrom datetime import datetime, timezone\nfrom typing import TYPE_CHECKING, Any, cast\n\nfrom jose import JWSError, JWTError, jwt\n\nfrom litestar.exceptions import ImproperlyConfiguredException, NotAuthorizedException\n\nif TYPE_CHECKING:\n    from typing_extensions import Self\n\n\n__all__ = (\"Token\",)\n\n\ndef _normalize_datetime(value: datetime) -> datetime:\n    \"\"\"Convert the given value into UTC and strip microseconds.\n\n    Args:\n        value: A datetime instance\n\n    Returns:\n        A datetime instance\n    \"\"\"\n    if value.tzinfo is not None:\n        value.astimezone(timezone.utc)\n\n    return value.replace(microsecond=0)\n\n\n@dataclass\nclass Token:\n    \"\"\"JWT Token DTO.\"\"\"\n\n    exp: datetime\n    \"\"\"Expiration - datetime for token expiration.\"\"\"\n    sub: str\n    \"\"\"Subject - usually a unique identifier of the user or equivalent entity.\"\"\"\n    iat: datetime = field(default_factory=lambda: _normalize_datetime(datetime.now(timezone.utc)))\n    \"\"\"Issued at - should always be current now.\"\"\"\n    iss: str | None = field(default=None)\n    \"\"\"Issuer - optional unique identifier for the issuer.\"\"\"\n    aud: str | None = field(default=None)\n    \"\"\"Audience - intended audience.\"\"\"\n    jti: str | None = field(default=None)\n    \"\"\"JWT ID - a unique identifier of the JWT between different issuers.\"\"\"\n    extras: dict[str, Any] = field(default_factory=dict)\n    \"\"\"Extra fields that were found on the JWT token.\"\"\"\n\n    def __post_init__(self) -> None:\n        if len(self.sub) < 1:\n            raise ImproperlyConfiguredException(\"sub must be a string with a length greater than 0\")\n\n        if isinstance(self.exp, datetime) and (\n            (exp := _normalize_datetime(self.exp))\n            and exp.timestamp() >= _normalize_datetime(datetime.now(timezone.utc)).timestamp()\n        ):\n            self.exp = exp\n        else:\n            raise ImproperlyConfiguredException(\"exp value must be a datetime in the future\")\n\n        if isinstance(self.iat, datetime) and (\n            (iat := _normalize_datetime(self.iat))\n            and iat.timestamp() <= _normalize_datetime(datetime.now(timezone.utc)).timestamp()\n        ):\n            self.iat = iat\n        else:\n            raise ImproperlyConfiguredException(\"iat must be a current or past time\")\n\n    @classmethod\n    def decode(cls, encoded_token: str, secret: str | dict[str, str], algorithm: str) -> Self:\n        \"\"\"Decode a passed in token string and returns a Token instance.\n\n        Args:\n            encoded_token: A base64 string containing an encoded JWT.\n            secret: The secret with which the JWT is encoded. It may optionally be an individual JWK or JWS set dict\n            algorithm: The algorithm used to encode the JWT.\n\n        Returns:\n            A decoded Token instance.\n\n        Raises:\n            NotAuthorizedException: If the token is invalid.\n        \"\"\"\n        try:\n            payload = jwt.decode(token=encoded_token, key=secret, algorithms=[algorithm], options={\"verify_aud\": False})\n            exp = datetime.fromtimestamp(payload.pop(\"exp\"), tz=timezone.utc)\n            iat = datetime.fromtimestamp(payload.pop(\"iat\"), tz=timezone.utc)\n            field_names = {f.name for f in dataclasses.fields(Token)}\n            extra_fields = payload.keys() - field_names\n            extras = payload.pop(\"extras\", {})\n            for key in extra_fields:\n                extras[key] = payload.pop(key)\n            return cls(exp=exp, iat=iat, **payload, extras=extras)\n        except (KeyError, JWTError, ImproperlyConfiguredException) as e:\n            raise NotAuthorizedException(\"Invalid token\") from e\n\n    def encode(self, secret: str, algorithm: str) -> str:\n        \"\"\"Encode the token instance into a string.\n\n        Args:\n            secret: The secret with which the JWT is encoded.\n            algorithm: The algorithm used to encode the JWT.\n\n        Returns:\n            An encoded token string.\n\n        Raises:\n            ImproperlyConfiguredException: If encoding fails.\n        \"\"\"\n        try:\n            return cast(\n                \"str\",\n                jwt.encode(\n                    claims={k: v for k, v in asdict(self).items() if v is not None}, key=secret, algorithm=algorithm\n                ),\n            )\n        except (JWTError, JWSError) as e:\n            raise ImproperlyConfiguredException(\"Failed to encode token\") from e\n", "path": "litestar/contrib/jwt/jwt_token.py"}]}