plain 0.45.0__py3-none-any.whl → 0.47.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/runtime/__init__.py CHANGED
@@ -18,16 +18,31 @@ PLAIN_TEMP_PATH = Path.cwd() / ".plain"
18
18
  # from plain.runtime import settings
19
19
  settings = Settings()
20
20
 
21
+ _is_setup_complete = False
22
+
21
23
 
22
24
  class AppPathNotFound(RuntimeError):
23
25
  pass
24
26
 
25
27
 
28
+ class SetupError(RuntimeError):
29
+ pass
30
+
31
+
26
32
  def setup():
27
33
  """
28
34
  Configure the settings (this happens as a side effect of accessing the
29
35
  first setting), configure logging and populate the app registry.
30
36
  """
37
+ global _is_setup_complete
38
+
39
+ if _is_setup_complete:
40
+ raise SetupError(
41
+ "Plain runtime is already set up. You can only call `setup()` once."
42
+ )
43
+ else:
44
+ # Make sure we don't call setup() again
45
+ _is_setup_complete = True
31
46
 
32
47
  # Packages can hook into the setup process through an entrypoint.
33
48
  for entry_point in entry_points().select(group="plain.setup"):
plain/views/base.py CHANGED
@@ -71,26 +71,37 @@ class View:
71
71
  return self.convert_value_to_response(result)
72
72
 
73
73
  def convert_value_to_response(self, value) -> ResponseBase:
74
- """Convert a value to a Response."""
74
+ """Convert a return value to a Response."""
75
75
  if isinstance(value, ResponseBase):
76
76
  return value
77
77
 
78
- if isinstance(value, str):
79
- # Assume a str is rendered HTML
80
- return Response(value)
81
-
82
- if isinstance(value, list):
83
- return JsonResponse(value, safe=False)
84
-
85
- if isinstance(value, dict):
86
- return JsonResponse(value)
87
-
88
78
  if isinstance(value, int):
89
79
  return Response(status_code=value)
90
80
 
91
81
  if value is None:
82
+ # TODO raise 404 instead?
92
83
  return ResponseNotFound()
93
84
 
85
+ status_code = 200
86
+
87
+ if isinstance(value, tuple):
88
+ if len(value) != 2:
89
+ raise ValueError(
90
+ "Tuple response must be of length 2 (status_code, value)"
91
+ )
92
+
93
+ status_code = value[0]
94
+ value = value[1]
95
+
96
+ if isinstance(value, str):
97
+ return Response(value, status_code=status_code)
98
+
99
+ if isinstance(value, list):
100
+ return JsonResponse(value, status_code=status_code, safe=False)
101
+
102
+ if isinstance(value, dict):
103
+ return JsonResponse(value, status_code=status_code)
104
+
94
105
  raise ValueError(f"Unexpected view return type: {type(value)}")
95
106
 
96
107
  def options(self) -> Response:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plain
3
- Version: 0.45.0
3
+ Version: 0.47.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
@@ -82,7 +82,7 @@ plain/preflight/registry.py,sha256=wHLq6LSMkKunkxElBmNwzMzQx3tc6OGYeKyOOi0tuyQ,2
82
82
  plain/preflight/security.py,sha256=oxUZBp2M0bpBfUoLYepIxoex2Y90nyjlrL8XU8UTHYY,2438
83
83
  plain/preflight/urls.py,sha256=cQ-WnFa_5oztpKdtwhuIGb7pXEml__bHsjs1SWO2YNI,1468
84
84
  plain/runtime/README.md,sha256=S_FIOmSq8LkVQHh9Xm6s3EJWKTVdlSr5A_bNXgh02X8,4740
85
- plain/runtime/__init__.py,sha256=0Q7k0V-8OfmTaKC0paNvV4Lx92L1_J7xoEWQH9aO5y4,2005
85
+ plain/runtime/__init__.py,sha256=8GtvKROf3HUCtneDYXTbEioPcCtwnV76dP57n2PnjuE,2343
86
86
  plain/runtime/global_settings.py,sha256=MpJ6vtBMO2EYALaKXrtgcGoxLh9Y549zwwErC5D5K7I,5343
87
87
  plain/runtime/user_settings.py,sha256=OzMiEkE6ZQ50nxd1WIqirXPiNuMAQULklYHEzgzLWgA,11027
88
88
  plain/signals/README.md,sha256=FInfJXdVQkb7u93PvD8XgPbz_f6m0l2xIu_4PyttV1E,234
@@ -138,7 +138,7 @@ plain/utils/timezone.py,sha256=6u0sE-9RVp0_OCe0Y1KiYYQoq5THWLokZFQYY8jf78g,6221
138
138
  plain/utils/tree.py,sha256=wdWzmfsgc26YDF2wxhAY3yVxXTixQYqYDKE9mL3L3ZY,4383
139
139
  plain/views/README.md,sha256=_jR_8_eccE1Qwc9sbUhD_hpZGGf0r-HY4W-al6kqtGs,6762
140
140
  plain/views/__init__.py,sha256=a-N1nkklVohJTtz0yD1MMaS0g66HviEjsKydNVVjvVc,392
141
- plain/views/base.py,sha256=bF_yBHrBfOdq3OcA_CTGCs7hNI1O6LpDVLM2Pkzyfjs,3062
141
+ plain/views/base.py,sha256=WVwJZ-N8zt0lMjVWffxglgORZBq6TeXiYmT3I8dP7fg,3430
142
142
  plain/views/csrf.py,sha256=7q6l5xzLWhRnMY64aNj0hR6G-3pxI2yhRwG6k_5j00E,144
143
143
  plain/views/errors.py,sha256=jbNCJIzowwCsEvqyJ3opMeZpPDqTyhtrbqb0VnAm2HE,1263
144
144
  plain/views/exceptions.py,sha256=b4euI49ZUKS9O8AGAcFfiDpstzkRAuuj_uYQXzWNHME,138
@@ -146,8 +146,8 @@ plain/views/forms.py,sha256=ESZOXuo6IeYixp1RZvPb94KplkowRiwO2eGJCM6zJI0,2400
146
146
  plain/views/objects.py,sha256=GGbcfg_9fPZ-PiaBwIHG2e__8GfWDR7JQtQ15wTyiHg,5970
147
147
  plain/views/redirect.py,sha256=daq2cQIkdDF78bt43sjuZxRAyJm_t_SKw6tyPmiXPIc,1985
148
148
  plain/views/templates.py,sha256=SU1fO9gVMp-gEQHYeFplxvmgeMyrLgT8MJ12WNVmQC8,2085
149
- plain-0.45.0.dist-info/METADATA,sha256=U_Me_Y2Ao9CeDXzHQBLgZkC9RN9w_B80hHs7OGxwJFQ,4297
150
- plain-0.45.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
151
- plain-0.45.0.dist-info/entry_points.txt,sha256=1Ys2lsSeMepD1vz8RSrJopna0RQfUd951vYvCRsvl6A,45
152
- plain-0.45.0.dist-info/licenses/LICENSE,sha256=m0D5O7QoH9l5Vz_rrX_9r-C8d9UNr_ciK6Qwac7o6yo,3175
153
- plain-0.45.0.dist-info/RECORD,,
149
+ plain-0.47.0.dist-info/METADATA,sha256=1pZQsM230re8YuNsP-4sMkVswn-9OrSRzm0A7QxhVA8,4297
150
+ plain-0.47.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
151
+ plain-0.47.0.dist-info/entry_points.txt,sha256=1Ys2lsSeMepD1vz8RSrJopna0RQfUd951vYvCRsvl6A,45
152
+ plain-0.47.0.dist-info/licenses/LICENSE,sha256=m0D5O7QoH9l5Vz_rrX_9r-C8d9UNr_ciK6Qwac7o6yo,3175
153
+ plain-0.47.0.dist-info/RECORD,,
File without changes