From 7ffeb8ff57a2e621cd04c6945bd8cba03b54d010 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Thu, 24 Aug 2017 01:11:48 +0300 Subject: [PATCH] Fix filename in InputFile and provide to change filename in send_document. --- aiogram/__init__.py | 2 +- aiogram/bot/base.py | 10 ++++++---- aiogram/bot/bot.py | 7 +++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/aiogram/__init__.py b/aiogram/__init__.py index be669f7c..e2ad4091 100644 --- a/aiogram/__init__.py +++ b/aiogram/__init__.py @@ -1,6 +1,6 @@ from .bot import Bot from .utils.versions import Version, Stage -VERSION = Version(0, 4, 1, stage=Stage.DEV, build=0) +VERSION = Version(0, 4, 2, stage=Stage.DEV, build=0) __version__ = VERSION.version diff --git a/aiogram/bot/base.py b/aiogram/bot/base.py index a37e7243..3a300ed9 100644 --- a/aiogram/bot/base.py +++ b/aiogram/bot/base.py @@ -164,8 +164,6 @@ class BaseBot: # You can use file ID or URL in the most of requests payload[file_type] = file files = None - elif isinstance(file, (io.IOBase, io.FileIO)): - files = {file_type: file.read()} else: files = {file_type: file} @@ -435,7 +433,8 @@ class BaseBot: disable_notification: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, reply_markup: Optional[Union[ - types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, Dict, String]] = None) -> Dict: + types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, Dict, String]] = None, + filename: Optional[str]=None) -> Dict: """ Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. @@ -456,10 +455,13 @@ class BaseBot: :param reply_markup: Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, Dict, String] (Optional) - Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. + :param filename: Set file name :return: On success, the sent Message is returned. """ reply_markup = prepare_arg(reply_markup) - payload = generate_payload(**locals(), exclude=['document']) + if filename: + document = (filename, document) + payload = generate_payload(**locals(), exclude=['document', 'filename']) return await self.send_file('document', api.Methods.SEND_DOCUMENT, document, payload) diff --git a/aiogram/bot/bot.py b/aiogram/bot/bot.py index b5fa8d12..3e4606c5 100644 --- a/aiogram/bot/bot.py +++ b/aiogram/bot/bot.py @@ -272,7 +272,8 @@ class Bot(BaseBot): reply_to_message_id: Optional[Integer] = None, reply_markup: Optional[Union[ types.InlineKeyboardMarkup, - types.ReplyKeyboardMarkup, Dict, String]] = None) -> types.Message: + types.ReplyKeyboardMarkup, Dict, String]] = None, + filename: Optional[str] = None) -> types.Message: """ Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. @@ -293,12 +294,14 @@ class Bot(BaseBot): :param reply_markup: Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, Dict, String] (Optional) - Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. + :param filename: Set file name :return: On success, the sent Message is returned. (serialized) """ raw = super(Bot, self).send_document(chat_id=chat_id, document=document, caption=caption, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, - reply_markup=reply_markup) + reply_markup=reply_markup, + filename=filename) return self.prepare_object(types.Message.deserialize(await raw)) async def send_video(self, chat_id: Union[Integer, String],