diff --git a/requirements.txt b/requirements.txt index e212c048..52e6ad11 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ -aiohttp<2.0.0 # sockjs doesn't support 2.0+ +aiohttp>=2.0.5 jinja2>=2.9.0 -sockjs>=0.5.0 +# sockjs at head supports aiohttp 2.0, but not released yet. +git+https://github.com/aio-libs/sockjs.git motor hoedown accept diff --git a/vj4/app.py b/vj4/app.py index ea1d692d..38cff9c5 100644 --- a/vj4/app.py +++ b/vj4/app.py @@ -1,5 +1,4 @@ import asyncio -import functools import logging from os import path @@ -47,7 +46,8 @@ def __init__(self): # Initialize components. staticmanifest.init(static_path) locale.load_translations(translation_path) - self.loop.run_until_complete(asyncio.gather(tools.ensure_all_indexes(), bus.init())) + asyncio.get_event_loop().run_until_complete( + asyncio.gather(tools.ensure_all_indexes(), bus.init())) smallcache.init() # Load views. @@ -101,12 +101,12 @@ def get(self, id, create=False, request=None): timeout=self.timeout, loop=self.loop, debug=self.debug)) return self[id] + loop = asyncio.get_event_loop() sockjs.add_endpoint(Application(), handler, name=name, prefix=prefix, - manager=Manager(name, Application(), handler, Application().loop)) - sockjs.add_endpoint(Application(), handler, - name=name + '_with_domain_id', prefix='/d/{domain_id}' + prefix, - manager=Manager(name + '_with_domain_id', Application(), handler, - Application().loop)) + manager=Manager(name, Application(), handler, loop)) + sockjs.add_endpoint( + Application(), handler, name=name + '_with_domain_id', prefix='/d/{domain_id}' + prefix, + manager=Manager(name + '_with_domain_id', Application(), handler, loop)) return conn return decorate diff --git a/vj4/handler/base.py b/vj4/handler/base.py index 728a225d..2971a7f1 100644 --- a/vj4/handler/base.py +++ b/vj4/handler/base.py @@ -413,7 +413,7 @@ def wrapped(self, **kwargs): def get_argument(func): @functools.wraps(func) def wrapped(self, **kwargs): - return func(self, **kwargs, **self.request.GET) + return func(self, **kwargs, **self.request.query) return wrapped diff --git a/vj4/handler/domain.py b/vj4/handler/domain.py index d2be3698..2eaf6114 100644 --- a/vj4/handler/domain.py +++ b/vj4/handler/domain.py @@ -119,9 +119,9 @@ async def post_set_user(self, *, uid: int, role: str): @base.require_perm(builtin.PERM_EDIT_PERM) @base.require_csrf_token @base.sanitize - async def post_set_users(self, *, uid: int, role: str): + async def post_set_users(self, *, uid: int, role: str=None): try: - uids = map(int, self.request.POST.getall('uid')) + uids = map(int, (await self.request.post()).getall('uid')) except ValueError: raise error.ValidationError('uid') if role: @@ -148,7 +148,7 @@ async def post(self, **kwargs): new_roles = dict() for role in self.domain['roles']: perms = 0 - for perm in self.request.POST.getall(role, []): + for perm in (await self.request.post()).getall(role, []): perm = int(perm) if perm in builtin.PERMS_BY_KEY: perms |= perm @@ -181,5 +181,5 @@ async def post_set(self, *, role: str, perm: int=builtin.DEFAULT_PERMISSIONS): @base.require_csrf_token @base.sanitize async def post_delete(self, *, role: str): - await domain.delete_roles(self.domain_id, self.request.POST.getall('role')) + await domain.delete_roles(self.domain_id, (await self.request.post()).getall('role')) self.json_or_redirect(self.url) diff --git a/vj4/handler/fs.py b/vj4/handler/fs.py index 6c83e933..5587e153 100644 --- a/vj4/handler/fs.py +++ b/vj4/handler/fs.py @@ -101,7 +101,8 @@ async def stream_data(self, *, secret: str, headers_only: bool=False): grid_out = await fs.get_by_secret(secret) self.response.content_type = grid_out.content_type or 'application/octet-stream' - self.response.content_length = grid_out.length + # FIXME(iceboy): For some reason setting response.content_length doesn't work in aiohttp 2.0.5. + self.response.headers['Content-Length'] = str(grid_out.length) # Cache control. self.response.last_modified = grid_out.upload_date diff --git a/vj4/handler/problem.py b/vj4/handler/problem.py index 15cb2fd2..b634afc7 100644 --- a/vj4/handler/problem.py +++ b/vj4/handler/problem.py @@ -233,8 +233,8 @@ async def post(self, *, pid: document.convert_doc_id, lang: str, code: str, pdoc = await problem.get(self.domain_id, pid) # don't need to check hidden status # create zip file, TODO(twd2): check file size - content = list(zip(self.request.POST.getall('data_input'), - self.request.POST.getall('data_output'))) + post = await self.request.post() + content = list(zip(post.getall('data_input'), post.getall('data_output'))) output_buffer = io.BytesIO() zip_file = zipfile.ZipFile(output_buffer, 'a', zipfile.ZIP_DEFLATED) config_content = str(len(content)) + '\n'