Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
future>=0.15.2
future>=0.16.0
certifi
13 changes: 8 additions & 5 deletions telegram/files/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram File."""

from os.path import basename

from future.backports.urllib import parse as urllib_parse

from telegram import TelegramObject


Expand All @@ -46,8 +47,7 @@ def __init__(self, file_id, bot, file_size=None, file_path=None, **kwargs):

# Optionals
self.file_size = file_size
if file_path:
self.file_path = str(file_path)
self.file_path = file_path

self.bot = bot

Expand Down Expand Up @@ -91,7 +91,10 @@ def download(self, custom_path=None, out=None, timeout=None):
if custom_path is not None and out is not None:
raise ValueError('custom_path and out are mutually exclusive')

url = self.file_path
# Convert any UTF-8 char into a url encoded ASCII string.
sres = urllib_parse.urlsplit(self.file_path)
url = urllib_parse.urlunsplit(urllib_parse.SplitResult(
sres.scheme, sres.netloc, urllib_parse.quote(sres.path), sres.query, sres.fragment))

if out:
buf = self.bot.request.retrieve(url)
Expand All @@ -101,6 +104,6 @@ def download(self, custom_path=None, out=None, timeout=None):
if custom_path:
filename = custom_path
else:
filename = basename(url)
filename = basename(self.file_path)

self.bot.request.download(url, filename, timeout=timeout)