Upgrade Sanic to 18.12.0

Had to fix CSV streaming generation to correctly use await.
This commit is contained in:
Simon Willison 2018-12-30 21:37:00 -08:00
commit 7e756ad097
3 changed files with 7 additions and 7 deletions

View file

@ -884,13 +884,13 @@ class LimitedWriter:
self.limit_bytes = limit_mb * 1024 * 1024 self.limit_bytes = limit_mb * 1024 * 1024
self.bytes_count = 0 self.bytes_count = 0
def write(self, bytes): async def write(self, bytes):
self.bytes_count += len(bytes) self.bytes_count += len(bytes)
if self.limit_bytes and (self.bytes_count > self.limit_bytes): if self.limit_bytes and (self.bytes_count > self.limit_bytes):
raise WriteLimitExceeded("CSV contains more than {} bytes".format( raise WriteLimitExceeded("CSV contains more than {} bytes".format(
self.limit_bytes self.limit_bytes
)) ))
self.writer.write(bytes) await self.writer.write(bytes)
_infinities = {float("inf"), float("-inf")} _infinities = {float("inf"), float("-inf")}

View file

@ -261,13 +261,13 @@ class BaseView(RenderMixin):
request, database, hash, **kwargs request, database, hash, **kwargs
) )
if first: if first:
writer.writerow(headings) await writer.writerow(headings)
first = False first = False
next = data.get("next") next = data.get("next")
for row in data["rows"]: for row in data["rows"]:
if not expanded_columns: if not expanded_columns:
# Simple path # Simple path
writer.writerow(row) await writer.writerow(row)
else: else:
# Look for {"value": "label": } dicts and expand # Look for {"value": "label": } dicts and expand
new_row = [] new_row = []
@ -277,10 +277,10 @@ class BaseView(RenderMixin):
new_row.append(cell["label"]) new_row.append(cell["label"])
else: else:
new_row.append(cell) new_row.append(cell)
writer.writerow(new_row) await writer.writerow(new_row)
except Exception as e: except Exception as e:
print('caught this', e) print('caught this', e)
r.write(str(e)) await r.write(str(e))
return return
content_type = "text/plain; charset=utf-8" content_type = "text/plain; charset=utf-8"

View file

@ -36,7 +36,7 @@ setup(
install_requires=[ install_requires=[
'click==6.7', 'click==6.7',
'click-default-group==1.2', 'click-default-group==1.2',
'Sanic==0.7.0', 'sanic==18.12.0',
'Jinja2==2.10', 'Jinja2==2.10',
'hupper==1.0', 'hupper==1.0',
'pint==0.8.1', 'pint==0.8.1',