Skip to content

Commit c80a8eb

Browse files
authored
Merge branch 'master' into bender/SYN-7932/fix_sigint_cmdloop
2 parents 814c273 + d37450a commit c80a8eb

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

synapse/tests/test_utils_getrefs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def getVcr(self):
2424
cm = myvcr.use_cassette(fp)
2525
return cm
2626

27-
async def test_basics(self):
27+
def test_basics(self):
2828

2929
args = s_getrefs.parse_args([
3030
s_data.path('attack-flow', 'attack-flow-schema-2.0.0.json')

synapse/utils/getrefs.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import sys
22
import json
33
import urllib
4+
import asyncio
45
import logging
56
import pathlib
67
import argparse
78

8-
import requests
9+
import aiohttp
910

1011
import synapse.exc as s_exc
1112
import synapse.data as s_data
@@ -20,7 +21,13 @@ def download_refs_handler(uri):
2021
This function downloads the JSON schema at the given URI, parses the given
2122
URI to get the path component, and then saves the referenced schema to the
2223
'jsonschemas' directory of synapse.data.
24+
25+
This function runs its own asyncio loop for each URI being requested.
2326
'''
27+
ret = asyncio.run(_download_refs_handler(uri))
28+
return ret
29+
30+
async def _download_refs_handler(uri):
2431

2532
try:
2633
parts = urllib.parse.urlparse(uri)
@@ -45,8 +52,12 @@ def download_refs_handler(uri):
4552

4653
# Get the data from the interwebs
4754
logger.info(f'Downloading schema from {uri}.')
48-
resp = requests.get(uri)
49-
data = resp.json()
55+
async with aiohttp.ClientSession() as session:
56+
async with session.get(uri) as resp:
57+
resp.raise_for_status()
58+
buf = await resp.read()
59+
60+
data = json.loads(buf.decode())
5061

5162
# Save the json schema to disk
5263
with filepath.open('w') as fp:

0 commit comments

Comments
 (0)