|
1 | 1 | # AUTOGENERATED! DO NOT EDIT! File to edit: nbs/03_xtras.ipynb (unless otherwise specified). |
2 | 2 |
|
3 | 3 | __all__ = ['dict2obj', 'repr_dict', 'is_listy', 'shufflish', 'mapped', 'IterLen', 'ReindexCollection', 'open_file', |
4 | | - 'save_pickle', 'load_pickle', 'maybe_open', 'image_size', 'bunzip', 'join_path_file', 'urlwrap', 'urlopen', |
5 | | - 'urlread', 'urljson', 'urlcheck', 'urlclean', 'urlsave', 'urlvalid', 'untar_dir', 'repo_details', 'run', |
6 | | - 'do_request', 'threaded', 'start_server', 'start_client', 'sort_by_run', 'trace', 'round_multiple', |
| 4 | + 'save_pickle', 'load_pickle', 'maybe_open', 'image_size', 'bunzip', 'join_path_file', 'urlquote', 'urlwrap', |
| 5 | + 'urlopen', 'urlread', 'urljson', 'urlcheck', 'urlclean', 'urlsave', 'urlvalid', 'untar_dir', 'repo_details', |
| 6 | + 'run', 'do_request', 'threaded', 'start_server', 'start_client', 'sort_by_run', 'trace', 'round_multiple', |
7 | 7 | 'modified_env', 'ContextManagers', 'str2bool', 'set_num_threads', 'ProcessPoolExecutor', |
8 | 8 | 'ThreadPoolExecutor', 'parallel', 'run_procs', 'parallel_gen'] |
9 | 9 |
|
@@ -181,10 +181,17 @@ def join_path_file(file, path, ext=''): |
181 | 181 | # Cell |
182 | 182 | _ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36' |
183 | 183 |
|
| 184 | +# Cell |
| 185 | +def urlquote(url): |
| 186 | + "Update url's path with `urllib.parse.quote`" |
| 187 | + p = list(urlparse(url)) |
| 188 | + p[2] = urllib.parse.quote(p[2]) |
| 189 | + return urlunparse(p) |
| 190 | + |
184 | 191 | # Cell |
185 | 192 | def urlwrap(url): |
186 | 193 | "Wrap `url` in a urllib `Request` with a user-agent header" |
187 | | - if not isinstance(url,Request): url = Request(url) |
| 194 | + if not isinstance(url,Request): url = Request(urlquote(url)) |
188 | 195 | url.headers['User-Agent'] = _ua |
189 | 196 | return url |
190 | 197 |
|
|
0 commit comments