diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 77f986e..00e2aa0 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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) diff --git a/VERSION b/VERSION index a69e585..38f77a6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.1.dev0 +2.0.1 diff --git a/guillotina_oauth/oauth.py b/guillotina_oauth/oauth.py index 7687721..6574abd 100644 --- a/guillotina_oauth/oauth.py +++ b/guillotina_oauth/oauth.py @@ -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, @@ -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={ @@ -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={ @@ -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={ @@ -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, @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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( @@ -566,14 +566,14 @@ async def call_auth(self, url, params, headers={}, future=None, # try to get new one and retry this... await self.refresh_service_token() await resp.release() - session.close() + await session.close() return await self.call_auth(url, params, headers=headers, future=future, retry=True, **kw) else: logger.error( f'OAUTH SERVER ERROR({url}) {resp.status} {text}') await resp.release() - session.close() + await session.close() if future is not None: future.set_result(result) else: