2
2
import hashlib
3
3
import os
4
4
import urllib .request as request
5
- from urllib .parse import urlparse
5
+ from urllib .parse import urlparse , unquote
6
6
7
7
from cleo .io .io import IO
8
8
@@ -129,31 +129,32 @@ def collect_info(self, payload: dict) -> dict:
129
129
info ["cells" ] = payload ["cells" ]
130
130
return info
131
131
132
- def download_file (self , url : str ) -> str :
132
+ def download_file (self , url : str ) -> tuple [ str , str ] :
133
133
file_name = os .path .basename (urlparse (url ).path )
134
+ unquoted_file_name = unquote (file_name )
134
135
if self ._config .download :
135
- if file_name :
136
- name , extension = os .path .splitext (file_name )
136
+ if unquoted_file_name :
137
+ name , extension = os .path .splitext (unquoted_file_name )
137
138
138
139
if not extension :
139
- return file_name , url
140
+ return unquoted_file_name , url
140
141
141
142
url_hash = hashlib .blake2s (
142
143
urlparse (url ).path .encode ()
143
144
).hexdigest ()[:8 ]
144
- downloaded_file_name = f"{ url_hash } _{ file_name } "
145
+ downloaded_file_name = f"{ url_hash } _{ unquoted_file_name } "
145
146
146
147
fullpath = os .path .join (
147
148
self ._config .tmp_path , downloaded_file_name
148
149
)
149
150
150
151
if self ._io :
151
- self ._io .write_line (status ("Downloading" , f"{ file_name } " ))
152
+ self ._io .write_line (status ("Downloading" , f"{ unquoted_file_name } " ))
152
153
request .urlretrieve (url , fullpath )
153
154
self ._io .write_line (
154
155
success (
155
156
"Downloaded" ,
156
- f'"{ file_name } " -> "{ downloaded_file_name } "' ,
157
+ f'"{ unquoted_file_name } " -> "{ downloaded_file_name } "' ,
157
158
)
158
159
)
159
160
else :
@@ -163,7 +164,7 @@ def download_file(self, url: str) -> str:
163
164
if self ._io :
164
165
self ._io .write_line (error (f"invalid { url } " ))
165
166
else :
166
- return file_name , url
167
+ return unquoted_file_name , url
167
168
168
169
def to_string (self , blocks : dict ) -> str :
169
170
return self .convert (blocks )
0 commit comments