Skip to content

Commit

Permalink
asyncio fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ferran committed Sep 10, 2018
1 parent 31b38f9 commit feb6db7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
2.0.1 (unreleased)
2.0.1 (2018-09-10)
------------------

- Nothing changed yet.
- Using "async with" instead of "with" [lferran]


2.0.0 (2018-06-05)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.1.dev0
2.0.1
24 changes: 12 additions & 12 deletions guillotina_oauth/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ async def get_temp_token(self, request, payload=None, ttl=None, clear=False,
data['ttl'] = ttl
if not authorization:
authorization = request.headers.get('Authorization', '')
with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with session.post(
self.server + 'get_temp_token',
json=data,
Expand All @@ -259,7 +259,7 @@ async def get_temp_token(self, request, payload=None, ttl=None, clear=False,

async def grant_scope_roles(self, request, user, roles=[]):
request = get_current_request()
with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with session.post(
self.server + 'grant_scope_roles',
json={
Expand All @@ -282,7 +282,7 @@ async def grant_scope_roles(self, request, user, roles=[]):

async def deny_scope_roles(self, request, user, roles=[]):
request = get_current_request()
with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with session.post(
self.server + 'deny_scope_roles',
json={
Expand All @@ -304,7 +304,7 @@ async def deny_scope_roles(self, request, user, roles=[]):

async def retrieve_temp_data(self, request, token):
request = get_current_request()
with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with session.get(
self.server + 'retrieve_temp_data?token=' + token,
headers={
Expand All @@ -327,7 +327,7 @@ async def check_scope_id(self, scope, service=False):
if service:
data['service_token'] = await self.service_token
url = self.server + 'check_scope_id'
with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with session.get(
url,
params=data,
Expand All @@ -354,7 +354,7 @@ async def get_user(self, username, scope, service=False):
url = self.server + 'service_get_user'
else:
url = self.server + 'get_user'
with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with session.post(
url,
data=json.dumps(data),
Expand All @@ -377,7 +377,7 @@ async def set_account_metadata(self, scope, payload, client_id, service=False):
url = join(self.server, 'service_set_account_metadata')
else:
url = join(self.server, 'set_account_metadata')
with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with session.post(
url,
data=json.dumps(data),
Expand Down Expand Up @@ -406,7 +406,7 @@ async def modify_limit(self, scope, name, value, client_id='', service=False):
url = join(self.server, 'service_modify_scope_limit')
else:
url = join(self.server, 'modify_scope_limit')
with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with session.post(
url,
data=json.dumps(data),
Expand All @@ -433,7 +433,7 @@ async def get_account_metadata(self, scope, client_id='', service=False):
url = join(self.server, 'get_metadata_by_service')
else:
url = join(self.server, 'get_metadata')
with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with session.post(
url,
data=json.dumps(data),
Expand All @@ -460,7 +460,7 @@ async def add_scope(self, scope, admin_user, urls=None):
'urls': urls
}
url = self.server + 'add_scope'
with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with session.post(
url,
data=json.dumps(data),
Expand Down Expand Up @@ -498,7 +498,7 @@ async def add_user(self, username, email, password, send_email=True,
headers = {
'Authorization': request.headers.get('Authorization', '')
}
with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with session.post(
self.server + 'add_user',
data=json.dumps(data),
Expand All @@ -514,7 +514,7 @@ async def call_auth(self, url, params, headers={}, future=None,
method, needs_decode = REST_API[url]

result = None
with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
async with aiohttp.ClientSession(conn_timeout=self.conn_timeout) as session:
if method == 'GET':
logger.debug('GET ' + self.server + url)
async with session.get(
Expand Down

0 comments on commit feb6db7

Please sign in to comment.