1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Added InputFile

This commit is contained in:
_run
2022-08-01 12:40:43 +05:00
parent 914c5fdf0c
commit 65b353ffae
2 changed files with 32 additions and 0 deletions

View File

@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
from io import IOBase
import logging
import os
from pathlib import Path
from typing import Dict, List, Optional, Union
from abc import ABC
@@ -6601,3 +6604,23 @@ class ChatAdministratorRights(JsonDeserializable, JsonSerializable, Dictionaryab
class InputFile:
def __init__(self, file) -> None:
self._file, self.file_name = self._resolve_file(file)
def _resolve_file(self, file):
if isinstance(file, str):
_file = open(file, 'rb')
return _file, os.path.basename(file.name)
elif isinstance(file, IOBase):
return file, os.path.basename(file.name)
elif isinstance(file, Path):
_file = open(file, 'rb')
return _file, os.path.basename(file.name)
else:
raise TypeError("File must be a string or a file-like object(pathlib.Path, io.IOBase).")
@property
def file(self):
return self._file