litestar-vite 0.2.5__py3-none-any.whl → 0.2.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of litestar-vite might be problematic. Click here for more details.

@@ -6,6 +6,7 @@ from litestar.connection import Request
6
6
  from litestar.connection.base import AuthT, StateT, UserT
7
7
  from litestar.exceptions import (
8
8
  HTTPException,
9
+ ImproperlyConfiguredException,
9
10
  InternalServerException,
10
11
  NotAuthorizedException,
11
12
  NotFoundException,
@@ -72,7 +73,7 @@ def create_inertia_exception_response(request: Request[UserT, AuthT, StateT], ex
72
73
  content.update({"extra": extras})
73
74
  try:
74
75
  flash(request, detail, category="error")
75
- except AttributeError:
76
+ except (AttributeError, ImproperlyConfiguredException):
76
77
  msg = "Unable to set `flash` session state. A valid session was not found for this request."
77
78
  request.logger.warning(msg)
78
79
  if extras and len(extras) >= 1:
@@ -82,11 +83,8 @@ def create_inertia_exception_response(request: Request[UserT, AuthT, StateT], ex
82
83
  match = FIELD_ERR_RE.search(error_detail)
83
84
  field = match.group(1) if match else default_field
84
85
  if isinstance(message, dict):
85
- error(request, field, error_detail)
86
- if status_code in {HTTP_422_UNPROCESSABLE_ENTITY, HTTP_400_BAD_REQUEST} or isinstance(
87
- exc,
88
- PermissionDeniedException,
89
- ):
86
+ error(request, field, error_detail if error_detail else detail)
87
+ if status_code in {HTTP_422_UNPROCESSABLE_ENTITY, HTTP_400_BAD_REQUEST}:
90
88
  return InertiaBack(request)
91
89
  if isinstance(exc, PermissionDeniedException):
92
90
  return InertiaBack(request)
@@ -7,7 +7,7 @@ from mimetypes import guess_type
7
7
  from pathlib import PurePath
8
8
  from textwrap import dedent
9
9
  from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Mapping, TypeVar, cast
10
- from urllib.parse import quote, urlparse
10
+ from urllib.parse import quote, urlparse, urlunparse
11
11
 
12
12
  from litestar import Litestar, MediaType, Request, Response
13
13
  from litestar.datastructures.cookie import Cookie
@@ -48,7 +48,7 @@ def share(
48
48
  ) -> None:
49
49
  try:
50
50
  connection.session.setdefault("_shared", {}).update({key: value})
51
- except AttributeError:
51
+ except (AttributeError, ImproperlyConfiguredException):
52
52
  msg = "Unable to set `share` session state. A valid session was not found for this request."
53
53
  connection.logger.warning(msg)
54
54
 
@@ -60,7 +60,7 @@ def error(
60
60
  ) -> None:
61
61
  try:
62
62
  connection.session.setdefault("_errors", {}).update({key: message})
63
- except AttributeError:
63
+ except (AttributeError, ImproperlyConfiguredException):
64
64
  msg = "Unable to set `error` session state. A valid session was not found for this request."
65
65
  connection.logger.warning(msg)
66
66
 
@@ -72,11 +72,12 @@ def get_shared_props(request: ASGIConnection[Any, Any, Any, Any]) -> Dict[str, A
72
72
  Be sure to call this before `self.create_template_context` if you would like to include the `flash` message details.
73
73
  """
74
74
  props: dict[str, Any] = {}
75
+ flash: dict[str, list[str]] = defaultdict(list)
76
+ errors: dict[str, Any] = {}
77
+ error_bag = request.headers.get("X-Inertia-Error-Bag", None)
75
78
  try:
76
- error_bag = request.headers.get("X-Inertia-Error-Bag", None)
77
- errors: dict[str, Any] = request.session.pop("_errors", {})
79
+ errors = request.session.pop("_errors", {})
78
80
  props.update(cast("Dict[str,Any]", request.session.pop("_shared", {})))
79
- flash: dict[str, list[str]] = defaultdict(list)
80
81
  for message in cast("List[Dict[str,Any]]", request.session.pop("_messages", [])):
81
82
  flash[message["category"]].append(message["message"])
82
83
 
@@ -85,11 +86,12 @@ def get_shared_props(request: ASGIConnection[Any, Any, Any, Any]) -> Dict[str, A
85
86
  for session_prop in inertia_plugin.config.extra_session_page_props:
86
87
  if session_prop not in props and session_prop in request.session:
87
88
  props[session_prop] = request.session.get(session_prop)
88
- props["flash"] = flash
89
- props["errors"] = {error_bag: errors} if error_bag is not None else errors
90
- except AttributeError:
89
+
90
+ except (AttributeError, ImproperlyConfiguredException):
91
91
  msg = "Unable to generate all shared props. A valid session was not found for this request."
92
92
  request.logger.warning(msg)
93
+ props["flash"] = flash
94
+ props["errors"] = {error_bag: errors} if error_bag is not None else errors
93
95
  props["csrf_token"] = value_or_default(ScopeState.from_scope(request.scope).csrf_token, "")
94
96
  return props
95
97
 
@@ -336,7 +338,7 @@ class InertiaRedirect(Redirect):
336
338
  and pass redirect url.
337
339
  """
338
340
  referer = urlparse(request.headers.get("referer", str(request.base_url)))
339
- redirect_to = str(urlparse(redirect_to)._replace(scheme=referer.scheme))
341
+ redirect_to = urlunparse(urlparse(redirect_to)._replace(scheme=referer.scheme))
340
342
  super().__init__(
341
343
  path=redirect_to,
342
344
  status_code=HTTP_307_TEMPORARY_REDIRECT if request.method == "GET" else HTTP_303_SEE_OTHER,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: litestar-vite
3
- Version: 0.2.5
3
+ Version: 0.2.7
4
4
  Summary: Vite plugin for Litestar
5
5
  Project-URL: Changelog, https://cofin.github.io/litestar-vite/latest/changelog
6
6
  Project-URL: Discord, https://discord.gg/X3FJqy8d2j
@@ -10,11 +10,11 @@ litestar_vite/template_engine.py,sha256=ffC4KPtUUNkuC0tJ0bD1Bu7c8lE33vKP0US1fWUY
10
10
  litestar_vite/inertia/__init__.py,sha256=RLeCWGHsHyBPpUjSXRhYOQlTh9cG33Q115zGH89M6XE,863
11
11
  litestar_vite/inertia/_utils.py,sha256=ijO9Lgka7ZPIAHkby9szbTGoSg0nDShC2bqWT9cDxi0,1956
12
12
  litestar_vite/inertia/config.py,sha256=ziEO-xQ5SoE7niri39PMXYgieM94Yf0y4BCFyaMs6P0,1125
13
- litestar_vite/inertia/exception_handler.py,sha256=HrFa8in0wF9V5PuctG3flIrhhEPsWUuocEW56_hfFAc,4747
13
+ litestar_vite/inertia/exception_handler.py,sha256=S-55sCQ6zLSMICo8l9co0RbT5Dr_TzJlRQBg7YpsRXM,4774
14
14
  litestar_vite/inertia/middleware.py,sha256=NEDcAoT7GMWA9hEGvANZ3MG5_p3MmZX57RF95T71les,1716
15
15
  litestar_vite/inertia/plugin.py,sha256=ebAG9XnDBahttuc7WIUgBd3o_Ys8MdPS273LPNs5H8A,2344
16
16
  litestar_vite/inertia/request.py,sha256=hk8m1pmDiMbWhVurRDHfDPD24nMHp56JzUKV6SBDeqA,3665
17
- litestar_vite/inertia/response.py,sha256=cWpLU07sHcty_f9-j9qwPymnU_h8gNz23zKMCZ8Tqg4,15866
17
+ litestar_vite/inertia/response.py,sha256=XcAXmQ6Ex_XZVc5UF9ULxzOgJ2EKlivJKKVm_EPAebw,15985
18
18
  litestar_vite/inertia/routes.py,sha256=QksJm2RUfL-WbuhOieYnPXXWO5GYnPtmsYEm6Ef8Yeo,1782
19
19
  litestar_vite/inertia/types.py,sha256=tLp0pm1N__hcWC875khf6wH1nuFlKS9-VjDqgsRkXnw,702
20
20
  litestar_vite/templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -24,7 +24,7 @@ litestar_vite/templates/package.json.j2,sha256=0JWgdTuaSZ25EmCltF_zbqDdpxfvCLeYu
24
24
  litestar_vite/templates/styles.css.j2,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  litestar_vite/templates/tsconfig.json.j2,sha256=q1REIuVyXUHCy4Zi2kgTkmrhdT98vyY89k-WTrImOj8,843
26
26
  litestar_vite/templates/vite.config.ts.j2,sha256=FZ4OJaB8Kjby_nlx4_LCP8eCe1LRi8kW2GspCiVMfDY,1115
27
- litestar_vite-0.2.5.dist-info/METADATA,sha256=aUXrSGZZV-NDdqiCANvOkt9WQ5ZVLERTflwpXJPJljU,6180
28
- litestar_vite-0.2.5.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
29
- litestar_vite-0.2.5.dist-info/licenses/LICENSE,sha256=HeTiEfEgvroUXZe_xAmYHxtTBgw--mbXyZLsWDYabHc,1069
30
- litestar_vite-0.2.5.dist-info/RECORD,,
27
+ litestar_vite-0.2.7.dist-info/METADATA,sha256=tMy61p67HGfR89sAeQECdLdltWx1B767mzjw_emFujU,6180
28
+ litestar_vite-0.2.7.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
29
+ litestar_vite-0.2.7.dist-info/licenses/LICENSE,sha256=HeTiEfEgvroUXZe_xAmYHxtTBgw--mbXyZLsWDYabHc,1069
30
+ litestar_vite-0.2.7.dist-info/RECORD,,