Skip to content

Commit

Permalink
util: net: sync_urlretrieve(): Return pathlib.Path object instead of …
Browse files Browse the repository at this point in the history
…string

Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
  • Loading branch information
pdxjohnny committed Jul 15, 2021
1 parent ca3e51f commit 274321a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions dffml/util/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import functools
import contextlib
import dataclasses
import email.message
import urllib.request
from typing import List, Union
from typing import List, Union, Tuple

from .os import chdir
from .file import validate_file_hash
from .log import LOGGER, get_download_logger
Expand Down Expand Up @@ -136,14 +138,15 @@ def sync_urlretrieve(
url: Union[str, urllib.request.Request],
protocol_allowlist: List[str] = DEFAULT_PROTOCOL_ALLOWLIST,
**kwargs,
):
) -> Tuple[pathlib.Path, email.message.EmailMessage]:
"""
Check that ``url`` has a protocol defined in ``protocol_allowlist``, then
return the result of calling :py:func:`urllib.request.urlretrieve` passing
it ``url`` and any keyword arguments.
"""
validate_protocol(url, protocol_allowlist=protocol_allowlist)
return urllib.request.urlretrieve(url, **kwargs)
path, headers = urllib.request.urlretrieve(url, **kwargs)
return pathlib.Path(path), headers


def sync_urlretrieve_and_validate(
Expand Down

0 comments on commit 274321a

Please sign in to comment.