diff --git a/debugger_protocol/schema/__main__.py b/debugger_protocol/schema/__main__.py index 773502de..fb9817a6 100644 --- a/debugger_protocol/schema/__main__.py +++ b/debugger_protocol/schema/__main__.py @@ -24,7 +24,7 @@ def handle_download(source=UPSTREAM, target=VENDORED, *, with _open_url(source) as infile: with _open(target, 'wb') as outfile: meta = download(source, infile, outfile, - _open=_open) + _open_url=_open_url) # Save the metadata. metafile, _ = open_metadata(target, 'w', diff --git a/debugger_protocol/schema/_util.py b/debugger_protocol/schema/_util.py index a0bb544f..dbb70781 100644 --- a/debugger_protocol/schema/_util.py +++ b/debugger_protocol/schema/_util.py @@ -9,10 +9,10 @@ def open_url(url): return urllib.request.urlopen(url) -def get_revision(url, *, _open=open_url): +def get_revision(url, *, _open_url=open_url): """Return the revision corresponding to the given URL.""" if url.startswith('https://github.com/'): - return github_get_revision(url, _open=_open) + return github_get_revision(url, _open_url=_open_url) else: raise NotImplementedError @@ -35,7 +35,7 @@ GH_RESOURCE_RE = re.compile(r'^https://github.com' r'/(?P.*)$') -def github_get_revision(url, *, _open=open_url): +def github_get_revision(url, *, _open_url=open_url): """Return the full commit hash corresponding to the given URL.""" m = GH_RESOURCE_RE.match(url) if not m: @@ -44,7 +44,7 @@ def github_get_revision(url, *, _open=open_url): revurl = ('https://api.github.com/repos/{}/{}/commits/{}' ).format(org, repo, ref) - with _open(revurl) as revinfo: + with _open_url(revurl) as revinfo: raw = revinfo.read() data = json.loads(raw.decode()) return data['sha'] diff --git a/debugger_protocol/schema/upstream.py b/debugger_protocol/schema/upstream.py index b46a057d..db40f27e 100644 --- a/debugger_protocol/schema/upstream.py +++ b/debugger_protocol/schema/upstream.py @@ -10,10 +10,11 @@ from .metadata import Metadata URL = 'https://github.com/Microsoft/vscode-debugadapter-node/raw/master/debugProtocol.json' # noqa -def download(source, infile, outfile, *, _now=datetime.utcnow, _open=open_url): +def download(source, infile, outfile, *, + _now=datetime.utcnow, _open_url=open_url): """Return the corresponding metadata after downloading the schema file.""" timestamp = _now() - revision = get_revision(source, _open=_open) + revision = get_revision(source, _open_url=_open_url) data = infile.read() checksum = get_checksum(data) @@ -31,5 +32,5 @@ def read(url, *, _open_url=open_url): # TODO: Ensure it's a 404 error? raise SchemaFileError('schema file at {!r} not found'.format(url)) with infile: - upstream = download(url, infile, outfile, _open=_open_url) + upstream = download(url, infile, outfile, _open_url=_open_url) return outfile.getvalue(), upstream diff --git a/tests/debugger_protocol/schema/test_upstream.py b/tests/debugger_protocol/schema/test_upstream.py index 39b100b5..75c6503a 100644 --- a/tests/debugger_protocol/schema/test_upstream.py +++ b/tests/debugger_protocol/schema/test_upstream.py @@ -21,7 +21,7 @@ class DownloadTests(unittest.TestCase): infile, outfile, _now=(lambda: now), - _open=(lambda _: buf), + _open_url=(lambda _: buf), ) rcvd = outfile.getvalue() diff --git a/tests/debugger_protocol/schema/test_util.py b/tests/debugger_protocol/schema/test_util.py index d24a265e..e048105c 100644 --- a/tests/debugger_protocol/schema/test_util.py +++ b/tests/debugger_protocol/schema/test_util.py @@ -10,7 +10,7 @@ class GetRevisionTests(unittest.TestCase): buf = io.BytesIO( b'{"sha": "fc2395ca3564fb2afded8d90ddbe38dad1bf86f1"}') revision = get_revision('https://github.com/x/y/raw/master/z', - _open=lambda _: buf) + _open_url=lambda _: buf) self.assertEqual(revision, 'fc2395ca3564fb2afded8d90ddbe38dad1bf86f1')