File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ def getVcr(self):
24
24
cm = myvcr .use_cassette (fp )
25
25
return cm
26
26
27
- async def test_basics (self ):
27
+ def test_basics (self ):
28
28
29
29
args = s_getrefs .parse_args ([
30
30
s_data .path ('attack-flow' , 'attack-flow-schema-2.0.0.json' )
Original file line number Diff line number Diff line change 1
1
import sys
2
2
import json
3
3
import urllib
4
+ import asyncio
4
5
import logging
5
6
import pathlib
6
7
import argparse
7
8
8
- import requests
9
+ import aiohttp
9
10
10
11
import synapse .exc as s_exc
11
12
import synapse .data as s_data
@@ -20,7 +21,13 @@ def download_refs_handler(uri):
20
21
This function downloads the JSON schema at the given URI, parses the given
21
22
URI to get the path component, and then saves the referenced schema to the
22
23
'jsonschemas' directory of synapse.data.
24
+
25
+ This function runs its own asyncio loop for each URI being requested.
23
26
'''
27
+ ret = asyncio .run (_download_refs_handler (uri ))
28
+ return ret
29
+
30
+ async def _download_refs_handler (uri ):
24
31
25
32
try :
26
33
parts = urllib .parse .urlparse (uri )
@@ -45,8 +52,12 @@ def download_refs_handler(uri):
45
52
46
53
# Get the data from the interwebs
47
54
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 ())
50
61
51
62
# Save the json schema to disk
52
63
with filepath .open ('w' ) as fp :
You can’t perform that action at this time.
0 commit comments