Download a given URL. Codes borrowed from mxnet/gluon/utils.py Parameters ---------- url : str URL to download. path : str, optional Destination path to store downloaded file. By default stores to the current directory with the same name as in url. o
(
url,
path=None,
overwrite=True,
sha1_hash=None,
retries=5,
verify_ssl=True,
log=True,
)
| 108 | |
| 109 | |
| 110 | def download( |
| 111 | url, |
| 112 | path=None, |
| 113 | overwrite=True, |
| 114 | sha1_hash=None, |
| 115 | retries=5, |
| 116 | verify_ssl=True, |
| 117 | log=True, |
| 118 | ): |
| 119 | """Download a given URL. |
| 120 | |
| 121 | Codes borrowed from mxnet/gluon/utils.py |
| 122 | |
| 123 | Parameters |
| 124 | ---------- |
| 125 | url : str |
| 126 | URL to download. |
| 127 | path : str, optional |
| 128 | Destination path to store downloaded file. By default stores to the |
| 129 | current directory with the same name as in url. |
| 130 | overwrite : bool, optional |
| 131 | Whether to overwrite the destination file if it already exists. |
| 132 | By default always overwrites the downloaded file. |
| 133 | sha1_hash : str, optional |
| 134 | Expected sha1 hash in hexadecimal digits. Will ignore existing file when hash is specified |
| 135 | but doesn't match. |
| 136 | retries : integer, default 5 |
| 137 | The number of times to attempt downloading in case of failure or non 200 return codes. |
| 138 | verify_ssl : bool, default True |
| 139 | Verify SSL certificates. |
| 140 | log : bool, default True |
| 141 | Whether to print the progress for download |
| 142 | |
| 143 | Returns |
| 144 | ------- |
| 145 | str |
| 146 | The file path of the downloaded file. |
| 147 | """ |
| 148 | if path is None: |
| 149 | fname = url.split("/")[-1] |
| 150 | # Empty filenames are invalid |
| 151 | assert fname, ( |
| 152 | "Can't construct file-name from this URL. " |
| 153 | "Please set the `path` option manually." |
| 154 | ) |
| 155 | else: |
| 156 | path = os.path.expanduser(path) |
| 157 | if os.path.isdir(path): |
| 158 | fname = os.path.join(path, url.split("/")[-1]) |
| 159 | else: |
| 160 | fname = path |
| 161 | assert retries >= 0, "Number of retries should be at least 0" |
| 162 | |
| 163 | if not verify_ssl: |
| 164 | warnings.warn( |
| 165 | "Unverified HTTPS request is being made (verify_ssl=False). " |
| 166 | "Adding certificate verification is strongly advised." |
| 167 | ) |
no test coverage detected