mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
_open -> _open_url
This commit is contained in:
parent
65fff09ee5
commit
0d71d2cf75
5 changed files with 11 additions and 10 deletions
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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<path>.*)$')
|
||||
|
||||
|
||||
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']
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class DownloadTests(unittest.TestCase):
|
|||
infile,
|
||||
outfile,
|
||||
_now=(lambda: now),
|
||||
_open=(lambda _: buf),
|
||||
_open_url=(lambda _: buf),
|
||||
)
|
||||
rcvd = outfile.getvalue()
|
||||
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue