Skip to content

Commit ab68f26

Browse files
committed
improve urlparse
1 parent cd73d04 commit ab68f26

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

fastcore/xtras.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ def urlquote(url):
186186
"Update url's path with `urllib.parse.quote`"
187187
p = list(urlparse(url))
188188
p[2] = urllib.parse.quote(p[2])
189+
for i in range(3,6): p[i] = urllib.parse.quote(p[i], safe="/=&")
189190
return urlunparse(p)
190191

191192
# Cell

nbs/03_xtras.ipynb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@
588588
{
589589
"data": {
590590
"text/plain": [
591-
"['b', 'h', 'd', 'a', 'g', 'f', 'c', 'e']"
591+
"['h', 'b', 'c', 'f', 'g', 'a', 'd', 'e']"
592592
]
593593
},
594594
"execution_count": null,
@@ -1168,6 +1168,7 @@
11681168
" \"Update url's path with `urllib.parse.quote`\"\n",
11691169
" p = list(urlparse(url))\n",
11701170
" p[2] = urllib.parse.quote(p[2])\n",
1171+
" for i in range(3,6): p[i] = urllib.parse.quote(p[i], safe=\"/=&\")\n",
11711172
" return urlunparse(p)"
11721173
]
11731174
},
@@ -1191,6 +1192,26 @@
11911192
"urlquote(\"https://github.com/fastai/fastai/compare/master@{1.day.ago}…master\")"
11921193
]
11931194
},
1195+
{
1196+
"cell_type": "code",
1197+
"execution_count": null,
1198+
"metadata": {},
1199+
"outputs": [
1200+
{
1201+
"data": {
1202+
"text/plain": [
1203+
"'https://www.google.com/search?q=%E4%BD%A0%E5%A5%BD'"
1204+
]
1205+
},
1206+
"execution_count": null,
1207+
"metadata": {},
1208+
"output_type": "execute_result"
1209+
}
1210+
],
1211+
"source": [
1212+
"urlquote(\"https://www.google.com/search?q=你好\")"
1213+
]
1214+
},
11941215
{
11951216
"cell_type": "code",
11961217
"execution_count": null,

0 commit comments

Comments
 (0)