17
17
# You should have received a copy of the GNU Lesser Public License
18
18
# along with this program. If not, see [http://www.gnu.org/licenses/].
19
19
"""This module contains an object that represents a Telegram File."""
20
-
21
20
from os .path import basename
22
21
22
+ from future .backports .urllib import parse as urllib_parse
23
+
23
24
from telegram import TelegramObject
24
25
25
26
@@ -46,8 +47,7 @@ def __init__(self, file_id, bot, file_size=None, file_path=None, **kwargs):
46
47
47
48
# Optionals
48
49
self .file_size = file_size
49
- if file_path :
50
- self .file_path = str (file_path )
50
+ self .file_path = file_path
51
51
52
52
self .bot = bot
53
53
@@ -91,7 +91,10 @@ def download(self, custom_path=None, out=None, timeout=None):
91
91
if custom_path is not None and out is not None :
92
92
raise ValueError ('custom_path and out are mutually exclusive' )
93
93
94
- url = self .file_path
94
+ # Convert any UTF-8 char into a url encoded ASCII string.
95
+ sres = urllib_parse .urlsplit (self .file_path )
96
+ url = urllib_parse .urlunsplit (urllib_parse .SplitResult (
97
+ sres .scheme , sres .netloc , urllib_parse .quote (sres .path ), sres .query , sres .fragment ))
95
98
96
99
if out :
97
100
buf = self .bot .request .retrieve (url )
@@ -101,6 +104,6 @@ def download(self, custom_path=None, out=None, timeout=None):
101
104
if custom_path :
102
105
filename = custom_path
103
106
else :
104
- filename = basename (url )
107
+ filename = basename (self . file_path )
105
108
106
109
self .bot .request .download (url , filename , timeout = timeout )
0 commit comments