mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
feat(InputFile): adding Pathlib to supporting types for files
This commit is contained in:
parent
1e2fe72aca
commit
fb237ca65e
1 changed files with 8 additions and 1 deletions
|
|
@ -4,6 +4,8 @@ import io
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import secrets
|
import secrets
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
|
|
@ -25,7 +27,7 @@ class InputFile(base.TelegramObject):
|
||||||
https://core.telegram.org/bots/api#inputfile
|
https://core.telegram.org/bots/api#inputfile
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, path_or_bytesio, filename=None, conf=None):
|
def __init__(self, path_or_bytesio: Union[str, io.IOBase, Path], filename=None, conf=None):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
:param path_or_bytesio:
|
:param path_or_bytesio:
|
||||||
|
|
@ -45,6 +47,11 @@ class InputFile(base.TelegramObject):
|
||||||
elif isinstance(path_or_bytesio, _WebPipe):
|
elif isinstance(path_or_bytesio, _WebPipe):
|
||||||
self._path = None
|
self._path = None
|
||||||
self._file = path_or_bytesio
|
self._file = path_or_bytesio
|
||||||
|
|
||||||
|
elif isinstance(path_or_bytesio, Path):
|
||||||
|
self._file = path_or_bytesio.open("rb")
|
||||||
|
self._path = path_or_bytesio.resolve()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise TypeError('Not supported file type.')
|
raise TypeError('Not supported file type.')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue