chisel 1.4.9__tar.gz → 1.5.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chisel
3
- Version: 1.4.9
3
+ Version: 1.5.0
4
4
  Summary: Lightweight WSGI application framework, schema-validated JSON APIs, and API documentation
5
5
  Home-page: https://github.com/craigahobbs/chisel
6
6
  Author: Craig A. Hobbs
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = chisel
3
- version = 1.4.9
3
+ version = 1.5.0
4
4
  url = https://github.com/craigahobbs/chisel
5
5
  author = Craig A. Hobbs
6
6
  author_email = craigahobbs@gmail.com
@@ -63,7 +63,7 @@ def create_doc_requests(requests=None, root_path='/doc', api=True, app=True, mar
63
63
  with importlib.resources.files('chisel.static').joinpath('markdown-up.tar.gz').open('rb') as tgz:
64
64
  with tarfile.open(fileobj=tgz, mode='r:gz') as tar:
65
65
  for member in tar.getmembers():
66
- if member.isfile():
66
+ if member.isfile(): # pragma: no branch
67
67
  yield StaticRequest(
68
68
  member.name,
69
69
  tar.extractfile(member).read(),
@@ -12,8 +12,6 @@ from itertools import chain
12
12
  import posixpath
13
13
  import re
14
14
 
15
- from .app import Context
16
-
17
15
 
18
16
  def request(wsgi_callback=None, **kwargs):
19
17
  """
@@ -124,7 +122,7 @@ class RedirectRequest(Request):
124
122
  :param str doc_group: The documentation group
125
123
  """
126
124
 
127
- __slots__ = ('_status', '_redirect_url')
125
+ __slots__ = ('status', 'redirect_url', 'content')
128
126
 
129
127
  def __init__(self, urls, redirect_url, permanent=True, name=None, doc=None, doc_group='Redirects'):
130
128
  if name is None:
@@ -132,13 +130,14 @@ class RedirectRequest(Request):
132
130
  if doc is None:
133
131
  doc = f'Redirect to {redirect_url}'
134
132
  super().__init__(name=name, urls=urls, doc=doc, doc_group=doc_group)
135
- self._status = HTTPStatus.MOVED_PERMANENTLY if permanent else HTTPStatus.FOUND
136
- self._redirect_url = redirect_url
133
+ status = HTTPStatus.MOVED_PERMANENTLY if permanent else HTTPStatus.FOUND
134
+ self.status = f'{status.value} {status.phrase}'
135
+ self.redirect_url = redirect_url
136
+ self.content = redirect_url.encode('utf-8')
137
137
 
138
- def __call__(self, environ, unused_start_response):
139
- ctx = environ[Context.ENVIRON_CTX]
140
- ctx.add_header('Location', self._redirect_url)
141
- return ctx.response_text(self._status, self._redirect_url)
138
+ def __call__(self, environ, start_response):
139
+ start_response(self.status, [('Content-Type', 'text/plain; charset=utf-8'), ('Location', self.redirect_url)])
140
+ return [self.content]
142
141
 
143
142
 
144
143
  class StaticRequest(Request):
@@ -155,29 +154,34 @@ class StaticRequest(Request):
155
154
  :param str doc_group: The documentation group
156
155
  """
157
156
 
158
- __slots__ = ('headers', 'content', 'etag')
157
+ __slots__ = ('content', 'content_type', 'etag')
159
158
 
160
159
  EXT_TO_CONTENT_TYPE = {
161
- '.css': 'text/css',
162
- '.html': 'text/html',
160
+ '.bare': 'text/plain; charset=utf-8',
161
+ '.css': 'text/css; charset=utf-8',
162
+ '.csv': 'text/csv; charset=utf-8',
163
+ '.gif': 'image/gif',
164
+ '.htm': 'text/html; charset=utf-8',
165
+ '.html': 'text/html; charset=utf-8',
166
+ '.jpeg': 'image/jpeg',
163
167
  '.jpg': 'image/jpeg',
164
- '.js': 'application/javascript',
165
- '.json': 'application/json',
166
- '.md': 'text/plain',
168
+ '.js': 'application/javascript; charset=utf-8',
169
+ '.json': 'application/json; charset=utf-8',
170
+ '.markdown': 'text/markdown; charset=utf-8',
171
+ '.md': 'text/markdown; charset=utf-8',
172
+ '.pdf': 'application/pdf',
167
173
  '.png': 'image/png',
168
- '.svg': 'image/svg+xml',
169
- '.txt': 'text/plain'
174
+ '.smd': 'text/plain; charset=utf-8',
175
+ '.svg': 'image/svg+xml; charset=utf-8',
176
+ '.tif': 'image/tiff',
177
+ '.tiff': 'image/tiff',
178
+ '.txt': 'text/plain; charset=utf-8',
179
+ '.webp': 'image/webp'
170
180
  }
181
+ STATUS_OK = f'{HTTPStatus.OK.value} {HTTPStatus.OK.phrase}'
182
+ STATUS_NOT_MODIFIED = f'{HTTPStatus.NOT_MODIFIED.value} {HTTPStatus.NOT_MODIFIED.phrase}'
171
183
 
172
- def __init__(
173
- self,
174
- name,
175
- content,
176
- content_type=None,
177
- urls=None,
178
- doc=None,
179
- doc_group='Statics'
180
- ):
184
+ def __init__(self, name, content, content_type=None, urls=None, doc=None, doc_group='Statics'):
181
185
  if doc is None:
182
186
  doc = (f'The static resource "{name}"',)
183
187
  if urls is None:
@@ -185,29 +189,27 @@ class StaticRequest(Request):
185
189
  super().__init__(name=name, urls=urls, doc=doc, doc_group=doc_group)
186
190
  self.content = content
187
191
 
188
- # Compute the etag
189
- md5 = hashlib.md5()
190
- md5.update(self.content)
191
- self.etag = md5.hexdigest()
192
-
193
192
  # Compute the content type
194
193
  if content_type is None:
195
194
  content_ext = next(
196
- (ext for ext in (posixpath.splitext(path)[1] for path in (url for _, url in self.urls))if ext in self.EXT_TO_CONTENT_TYPE),
195
+ (ext for ext in (posixpath.splitext(path)[1] for _, path in self.urls) if ext in self.EXT_TO_CONTENT_TYPE),
197
196
  ''
198
- ).lower()
197
+ )
199
198
  content_type = self.EXT_TO_CONTENT_TYPE.get(content_ext)
200
199
  assert content_type, f'Unknown content type for static resource "{name}"'
200
+ self.content_type = content_type
201
201
 
202
- # Compute the headers
203
- self.headers = (('Content-Type', content_type), ('ETag', self.etag))
202
+ # Compute the etag
203
+ md5 = hashlib.md5()
204
+ md5.update(self.content)
205
+ self.etag = md5.hexdigest()
204
206
 
205
207
  def __call__(self, environ, start_response):
206
208
 
207
209
  # Check the etag - is the resource modified?
208
210
  if self.etag == environ.get('HTTP_IF_NONE_MATCH'):
209
- start_response(HTTPStatus.NOT_MODIFIED, [])
211
+ start_response(self.STATUS_NOT_MODIFIED, [])
210
212
  return []
211
213
 
212
- start_response(HTTPStatus.OK, self.headers)
214
+ start_response(self.STATUS_OK, [('Content-Type', self.content_type), ('ETag', self.etag)])
213
215
  return [self.content]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chisel
3
- Version: 1.4.9
3
+ Version: 1.5.0
4
4
  Summary: Lightweight WSGI application framework, schema-validated JSON APIs, and API documentation
5
5
  Home-page: https://github.com/craigahobbs/chisel
6
6
  Author: Craig A. Hobbs
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes