mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-05 03:22:29 +00:00
Avoid relying on .__iter__ to tell iterators apart
.send_file() would fail with stream objects (those from open()) since they are iterable, and asserting that they weren't bytes or str was not enough.
This commit is contained in:
@@ -5,6 +5,7 @@ to convert between an entity like an User, Chat, etc. into its Input version)
|
||||
import math
|
||||
import mimetypes
|
||||
import re
|
||||
import types
|
||||
from mimetypes import add_type, guess_extension
|
||||
|
||||
from .tl.types import (
|
||||
@@ -341,6 +342,17 @@ def is_video(file):
|
||||
(mimetypes.guess_type(file)[0] or '').startswith('video/'))
|
||||
|
||||
|
||||
def is_list_like(obj):
|
||||
"""
|
||||
Returns True if the given object looks like a list.
|
||||
|
||||
Checking if hasattr(obj, '__iter__') and ignoring str/bytes is not
|
||||
enough. Things like open() are also iterable (and probably many
|
||||
other things), so just support the commonly known list-like objects.
|
||||
"""
|
||||
return isinstance(obj, (list, tuple, set, dict, types.GeneratorType))
|
||||
|
||||
|
||||
def parse_phone(phone):
|
||||
"""Parses the given phone, or returns None if it's invalid"""
|
||||
if isinstance(phone, int):
|
||||
|
Reference in New Issue
Block a user