fix that aiohttp uses 'read()' on response, but tornado doesn't

This commit is contained in:
lilydjwg 2017-07-08 15:48:03 +08:00
parent 3226a76cfe
commit 19be32164f
2 changed files with 10 additions and 8 deletions

View File

@ -28,12 +28,10 @@ async def get_version(name, conf):
sort_version_key = sort_version_keys[conf.get("sort_version_key", "parse_version")]
async with session.get(conf['url'], headers=headers, **kwargs) as res:
version = None
body = (await res.read()).decode(encoding)
try:
body = (await res.read()).decode(encoding)
try:
version = max(regex.findall(body), key=sort_version_key)
except ValueError:
logger.error('%s: version string not found.', name)
finally:
return name, version
version = max(regex.findall(body), key=sort_version_key)
except ValueError:
version = None
logger.error('%s: version string not found.', name)
return name, version

View File

@ -59,5 +59,9 @@ class ResponseManager:
async def json_response(self):
return json.loads(self.body.decode('utf-8'))
async def read(self):
return self.body
HTTPResponse.json = json_response
HTTPResponse.read = read
session = Session()