Skip to content

Commit

Permalink
remove usages of app.loop since it's deprecated in aiohttp 2.0 (#149)
Browse files Browse the repository at this point in the history
* remove usages of app.loop since it's deprecated in aiohttp 2.0

* use sockjs at head to support aiohttp 2.0.

* fix pretest

* fix domain

* fix GET

* fix twd2
  • Loading branch information
iceboy233 authored and twd2 committed Apr 2, 2017
1 parent dfddffe commit 11e817d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 7 additions & 7 deletions vj4/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import functools
import logging
from os import path

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion vj4/handler/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions vj4/handler/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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)
3 changes: 2 additions & 1 deletion vj4/handler/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions vj4/handler/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 11e817d

Please sign in to comment.