Skip to content

Commit cd73d04

Browse files
committed
fixes #211
1 parent c9f5428 commit cd73d04

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

fastcore/_nbdev.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"image_size": "03_xtras.ipynb",
149149
"bunzip": "03_xtras.ipynb",
150150
"join_path_file": "03_xtras.ipynb",
151+
"urlquote": "03_xtras.ipynb",
151152
"urlwrap": "03_xtras.ipynb",
152153
"urlopen": "03_xtras.ipynb",
153154
"urlread": "03_xtras.ipynb",

fastcore/xtras.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/03_xtras.ipynb (unless otherwise specified).
22

33
__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',
77
'modified_env', 'ContextManagers', 'str2bool', 'set_num_threads', 'ProcessPoolExecutor',
88
'ThreadPoolExecutor', 'parallel', 'run_procs', 'parallel_gen']
99

@@ -181,10 +181,17 @@ def join_path_file(file, path, ext=''):
181181
# Cell
182182
_ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'
183183

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+
184191
# Cell
185192
def urlwrap(url):
186193
"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))
188195
url.headers['User-Agent'] = _ua
189196
return url
190197

nbs/03_xtras.ipynb

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@
588588
{
589589
"data": {
590590
"text/plain": [
591-
"['a', 'c', 'f', 'd', 'g', 'e', 'b', 'h']"
591+
"['b', 'h', 'd', 'a', 'g', 'f', 'c', 'e']"
592592
]
593593
},
594594
"execution_count": null,
@@ -1157,6 +1157,40 @@
11571157
"_ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'"
11581158
]
11591159
},
1160+
{
1161+
"cell_type": "code",
1162+
"execution_count": null,
1163+
"metadata": {},
1164+
"outputs": [],
1165+
"source": [
1166+
"#export\n",
1167+
"def urlquote(url):\n",
1168+
" \"Update url's path with `urllib.parse.quote`\"\n",
1169+
" p = list(urlparse(url))\n",
1170+
" p[2] = urllib.parse.quote(p[2])\n",
1171+
" return urlunparse(p)"
1172+
]
1173+
},
1174+
{
1175+
"cell_type": "code",
1176+
"execution_count": null,
1177+
"metadata": {},
1178+
"outputs": [
1179+
{
1180+
"data": {
1181+
"text/plain": [
1182+
"'https://github.com/fastai/fastai/compare/master%40%7B1.day.ago%7D%E2%80%A6master'"
1183+
]
1184+
},
1185+
"execution_count": null,
1186+
"metadata": {},
1187+
"output_type": "execute_result"
1188+
}
1189+
],
1190+
"source": [
1191+
"urlquote(\"https://github.com/fastai/fastai/compare/master@{1.day.ago}…master\")"
1192+
]
1193+
},
11601194
{
11611195
"cell_type": "code",
11621196
"execution_count": null,
@@ -1166,7 +1200,7 @@
11661200
"#export\n",
11671201
"def urlwrap(url):\n",
11681202
" \"Wrap `url` in a urllib `Request` with a user-agent header\"\n",
1169-
" if not isinstance(url,Request): url = Request(url)\n",
1203+
" if not isinstance(url,Request): url = Request(urlquote(url))\n",
11701204
" url.headers['User-Agent'] = _ua\n",
11711205
" return url"
11721206
]

0 commit comments

Comments
 (0)