plain 0.22.1__py3-none-any.whl → 0.23.0__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.
plain/urls/resolvers.py CHANGED
@@ -16,7 +16,6 @@ from urllib.parse import quote
16
16
  from plain.preflight.urls import check_resolver
17
17
  from plain.runtime import settings
18
18
  from plain.utils.datastructures import MultiValueDict
19
- from plain.utils.functional import cached_property
20
19
  from plain.utils.http import RFC3986_SUBDELIMS, escape_leading_slashes
21
20
  from plain.utils.regex_helper import normalize
22
21
 
@@ -106,7 +105,7 @@ def _get_cached_resolver(urls_module):
106
105
  urls_module = import_module(urls_module)
107
106
 
108
107
  router = routers_registry.get_module_router(urls_module)
109
- return URLResolver(pattern=RegexPattern(r"^/"), router_class=router)
108
+ return URLResolver(pattern=RegexPattern(r"^/"), router=router)
110
109
 
111
110
 
112
111
  @functools.cache
@@ -120,16 +119,18 @@ def get_ns_resolver(ns_pattern, resolver, converters):
120
119
  pattern.converters = dict(converters)
121
120
 
122
121
  class _NestedRouter(RouterBase):
122
+ namespace = ""
123
123
  urls = resolver.url_patterns
124
124
 
125
- ns_resolver = URLResolver(pattern=pattern, router_class=_NestedRouter)
125
+ ns_resolver = URLResolver(pattern=pattern, router=_NestedRouter())
126
126
 
127
127
  class _NamespacedRouter(RouterBase):
128
+ namespace = ""
128
129
  urls = [ns_resolver]
129
130
 
130
131
  return URLResolver(
131
132
  pattern=RegexPattern(r"^/"),
132
- router_class=_NamespacedRouter,
133
+ router=_NamespacedRouter(),
133
134
  )
134
135
 
135
136
 
@@ -138,18 +139,23 @@ class URLResolver:
138
139
  self,
139
140
  *,
140
141
  pattern,
141
- router_class,
142
+ router,
142
143
  ):
143
144
  self.pattern = pattern
144
- self.router_class = router_class
145
+ self.router = router
145
146
  self._reverse_dict = {}
146
147
  self._namespace_dict = {}
147
148
  self._app_dict = {}
148
149
  self._populated = False
149
150
  self._local = local()
150
151
 
152
+ # Set these immediately, in part so we can find routers
153
+ # where the attributes weren't set correctly.
154
+ self.namespace = self.router.namespace
155
+ self.url_patterns = self.router.urls
156
+
151
157
  def __repr__(self):
152
- return f"<{self.__class__.__name__} {repr(self.router_class)} ({self.namespace}) {self.pattern.describe()}>"
158
+ return f"<{self.__class__.__name__} {repr(self.router)} ({self.namespace}) {self.pattern.describe()}>"
153
159
 
154
160
  def check(self):
155
161
  messages = []
@@ -313,15 +319,6 @@ class URLResolver:
313
319
  raise Resolver404({"tried": tried, "path": new_path})
314
320
  raise Resolver404({"path": path})
315
321
 
316
- @cached_property
317
- def url_patterns(self):
318
- # Don't need to instantiate the class because they are just class attributes for now.
319
- return self.router_class.urls
320
-
321
- @cached_property
322
- def namespace(self):
323
- return self.router_class.namespace
324
-
325
322
  def reverse(self, lookup_view, *args, **kwargs):
326
323
  if args and kwargs:
327
324
  raise ValueError("Don't mix *args and **kwargs in call to reverse()!")
plain/urls/routers.py CHANGED
@@ -1,5 +1,4 @@
1
1
  import re
2
- from abc import ABC
3
2
  from types import ModuleType
4
3
  from typing import TYPE_CHECKING
5
4
 
@@ -14,9 +13,16 @@ if TYPE_CHECKING:
14
13
  from plain.views import View
15
14
 
16
15
 
17
- class RouterBase(ABC):
18
- namespace: str = ""
19
- urls: list # Required
16
+ class RouterBase:
17
+ """
18
+ Base class for defining url patterns.
19
+
20
+ A namespace is required, and generally recommended,
21
+ except for the root router in app.urls where it is typically "".
22
+ """
23
+
24
+ namespace: str
25
+ urls: list
20
26
 
21
27
 
22
28
  class RoutersRegistry:
@@ -26,9 +32,12 @@ class RoutersRegistry:
26
32
  self._routers = {}
27
33
 
28
34
  def register_router(self, router_class):
35
+ router = (
36
+ router_class()
37
+ ) # Don't necessarily need to instantiate it yet, but will likely add methods.
29
38
  router_module_name = router_class.__module__
30
- self._routers[router_module_name] = router_class
31
- return router_class
39
+ self._routers[router_module_name] = router
40
+ return router
32
41
 
33
42
  def get_module_router(self, module):
34
43
  if isinstance(module, str):
@@ -62,17 +71,18 @@ def include(
62
71
  # We were given an explicit list of sub-patterns,
63
72
  # so we generate a router for it
64
73
  class _IncludeRouter(RouterBase):
74
+ namespace = ""
65
75
  urls = module_or_urls
66
76
 
67
- return URLResolver(pattern=pattern, router_class=_IncludeRouter)
77
+ return URLResolver(pattern=pattern, router=_IncludeRouter())
68
78
  else:
69
79
  # We were given a module, so we need to look up the router for that module
70
80
  module = module_or_urls
71
- router_class = routers_registry.get_module_router(module)
81
+ router = routers_registry.get_module_router(module)
72
82
 
73
83
  return URLResolver(
74
84
  pattern=pattern,
75
- router_class=router_class,
85
+ router=router,
76
86
  )
77
87
 
78
88
 
@@ -109,4 +119,9 @@ def path(route: str | re.Pattern, view: "View", *, name: str = "") -> URLPattern
109
119
 
110
120
 
111
121
  routers_registry = RoutersRegistry()
112
- register_router = routers_registry.register_router
122
+
123
+
124
+ def register_router(router_class):
125
+ """Decorator to register a router class"""
126
+ routers_registry.register_router(router_class)
127
+ return router_class # Return the class, not the instance
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plain
3
- Version: 0.22.1
3
+ Version: 0.23.0
4
4
  Summary: A web framework for building products with Python.
5
5
  Author-email: Dave Gaeddert <dave.gaeddert@dropseed.dev>
6
6
  License-File: LICENSE
@@ -96,8 +96,8 @@ plain/urls/__init__.py,sha256=XF-W2GqLMA4bHbDRKnpZ7tiUtJ-BhWN-yAzw4nNnHdc,590
96
96
  plain/urls/converters.py,sha256=s2JZVOdzZC16lgobsI93hygcdH5L0Kj4742WEkXsVcs,1193
97
97
  plain/urls/exceptions.py,sha256=q4iPh3Aa-zHbA-tw8v6WyX1J1n5WdAady2xvxFuyXB0,114
98
98
  plain/urls/patterns.py,sha256=bU_xfhZbKMSgRG9OJ8w_NSuYRm_9zGnqoz_WY44fhUk,9358
99
- plain/urls/resolvers.py,sha256=T_N7hZ2VrWWpLNkMbzpNcPK8OJb4yPt6QoK_qIls4D8,15592
100
- plain/urls/routers.py,sha256=0vwzL5udLfQDwFfE4_3lzRVq0Lsx9RcDF4rnnEiJJ1w,3613
99
+ plain/urls/resolvers.py,sha256=bVh7risata9V7F42o7a1BL3GuxjBsmvI-kEFUi_U9zI,15488
100
+ plain/urls/routers.py,sha256=RtOBeivHAJbaFW5DMu-gma47UKqyO9PSmxp_y5cTJCs,4029
101
101
  plain/urls/utils.py,sha256=WiGq6hHI-5DLFOxCQTAZ2qm0J-UdGosLcjuxlfK6_Tg,2137
102
102
  plain/utils/README.md,sha256=Bf5OG-MkOJDz_U8RGVreDfAI4M4nnPaLtk-LdinxHSc,99
103
103
  plain/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -138,8 +138,8 @@ plain/views/forms.py,sha256=RhlaUcZCkeqokY_fvv-NOS-kgZAG4XhDLOPbf9K_Zlc,2691
138
138
  plain/views/objects.py,sha256=g5Lzno0Zsv0K449UpcCtxwCoO7WMRAWqKlxxV2V0_qg,8263
139
139
  plain/views/redirect.py,sha256=9zHZgKvtSkdrMX9KmsRM8hJTPmBktxhc4d8OitbuniI,1724
140
140
  plain/views/templates.py,sha256=cBkFNCSXgVi8cMqQbhsqJ4M_rIQYVl8cUvq9qu4YIes,1951
141
- plain-0.22.1.dist-info/METADATA,sha256=lbcAVRTvoSbCtA3Nlt-ShyzQV1UOhb2bk_FSDKL5pS4,319
142
- plain-0.22.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
143
- plain-0.22.1.dist-info/entry_points.txt,sha256=DHHprvufgd7xypiBiqMANYRnpJ9xPPYhYbnPGwOkWqE,40
144
- plain-0.22.1.dist-info/licenses/LICENSE,sha256=m0D5O7QoH9l5Vz_rrX_9r-C8d9UNr_ciK6Qwac7o6yo,3175
145
- plain-0.22.1.dist-info/RECORD,,
141
+ plain-0.23.0.dist-info/METADATA,sha256=bxiquJgm2Ost04nSXFcMdh8rLoPkO3EeCceWqod97pc,319
142
+ plain-0.23.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
143
+ plain-0.23.0.dist-info/entry_points.txt,sha256=DHHprvufgd7xypiBiqMANYRnpJ9xPPYhYbnPGwOkWqE,40
144
+ plain-0.23.0.dist-info/licenses/LICENSE,sha256=m0D5O7QoH9l5Vz_rrX_9r-C8d9UNr_ciK6Qwac7o6yo,3175
145
+ plain-0.23.0.dist-info/RECORD,,
File without changes