plain 0.45.0__py3-none-any.whl → 0.46.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/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.46.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
@@ -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.46.0.dist-info/METADATA,sha256=rF6Xp8UI8IkRuYY0NTBPkAOUt9eOrULu8agjCovlSAA,4297
150
+ plain-0.46.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
151
+ plain-0.46.0.dist-info/entry_points.txt,sha256=1Ys2lsSeMepD1vz8RSrJopna0RQfUd951vYvCRsvl6A,45
152
+ plain-0.46.0.dist-info/licenses/LICENSE,sha256=m0D5O7QoH9l5Vz_rrX_9r-C8d9UNr_ciK6Qwac7o6yo,3175
153
+ plain-0.46.0.dist-info/RECORD,,
File without changes