mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-01-27 01:34:29 +03:00
Fix classes MRO and abstractmethod usage
Furthermore utils needs to access the message by reference through types.Message because it is patched and replaced.
This commit is contained in:
parent
1c0d595205
commit
ace7254344
|
@ -8,7 +8,7 @@ from ... import utils, errors
|
||||||
|
|
||||||
# TODO Figure out a way to have the code generator error on missing fields
|
# TODO Figure out a way to have the code generator error on missing fields
|
||||||
# Maybe parsing the init function alone if that's possible.
|
# Maybe parsing the init function alone if that's possible.
|
||||||
class Message(abc.ABC, TLObject, ChatGetter, SenderGetter):
|
class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
||||||
"""
|
"""
|
||||||
This custom class aggregates both :tl:`Message` and
|
This custom class aggregates both :tl:`Message` and
|
||||||
:tl:`MessageService` to ease accessing their members.
|
:tl:`MessageService` to ease accessing their members.
|
||||||
|
|
|
@ -3,7 +3,7 @@ import struct
|
||||||
from datetime import datetime, date, timedelta
|
from datetime import datetime, date, timedelta
|
||||||
|
|
||||||
|
|
||||||
class TLObject(abc.ABC):
|
class TLObject:
|
||||||
CONSTRUCTOR_ID = None
|
CONSTRUCTOR_ID = None
|
||||||
SUBCLASS_OF_ID = None
|
SUBCLASS_OF_ID = None
|
||||||
|
|
||||||
|
@ -141,21 +141,18 @@ class TLObject(abc.ABC):
|
||||||
def stringify(self):
|
def stringify(self):
|
||||||
return TLObject.pretty_format(self, indent=0)
|
return TLObject.pretty_format(self, indent=0)
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def __bytes__(self):
|
def __bytes__(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@abc.abstractmethod
|
|
||||||
def from_reader(cls, reader):
|
def from_reader(cls, reader):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class TLRequest(abc.ABC, TLObject):
|
class TLRequest(TLObject):
|
||||||
"""
|
"""
|
||||||
Represents a content-related `TLObject` (a request that can be sent).
|
Represents a content-related `TLObject` (a request that can be sent).
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -7,12 +7,13 @@ import math
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import types
|
|
||||||
from collections import UserList
|
from collections import UserList
|
||||||
from mimetypes import guess_extension
|
from mimetypes import guess_extension
|
||||||
|
from types import GeneratorType
|
||||||
|
|
||||||
from .extensions import markdown, html
|
from .extensions import markdown, html
|
||||||
from .helpers import add_surrogate, del_surrogate
|
from .helpers import add_surrogate, del_surrogate
|
||||||
|
from .tl import types
|
||||||
from .tl.types import (
|
from .tl.types import (
|
||||||
Channel, ChannelForbidden, Chat, ChatEmpty, ChatForbidden, ChatFull,
|
Channel, ChannelForbidden, Chat, ChatEmpty, ChatForbidden, ChatFull,
|
||||||
ChatPhoto, InputPeerChannel, InputPeerChat, InputPeerUser, InputPeerEmpty,
|
ChatPhoto, InputPeerChannel, InputPeerChat, InputPeerUser, InputPeerEmpty,
|
||||||
|
@ -23,7 +24,7 @@ from .tl.types import (
|
||||||
MessageMediaUnsupported, MessageMediaVenue, InputMediaContact,
|
MessageMediaUnsupported, MessageMediaVenue, InputMediaContact,
|
||||||
InputMediaDocument, InputMediaEmpty, InputMediaGame,
|
InputMediaDocument, InputMediaEmpty, InputMediaGame,
|
||||||
InputMediaGeoPoint, InputMediaPhoto, InputMediaVenue, InputDocument,
|
InputMediaGeoPoint, InputMediaPhoto, InputMediaVenue, InputDocument,
|
||||||
DocumentEmpty, InputDocumentEmpty, Message, GeoPoint, InputGeoPoint,
|
DocumentEmpty, InputDocumentEmpty, GeoPoint, InputGeoPoint,
|
||||||
GeoPointEmpty, InputGeoPointEmpty, Photo, InputPhoto, PhotoEmpty,
|
GeoPointEmpty, InputGeoPointEmpty, Photo, InputPhoto, PhotoEmpty,
|
||||||
InputPhotoEmpty, FileLocation, ChatPhotoEmpty, UserProfilePhotoEmpty,
|
InputPhotoEmpty, FileLocation, ChatPhotoEmpty, UserProfilePhotoEmpty,
|
||||||
FileLocationUnavailable, InputMediaUploadedDocument, ChannelFull,
|
FileLocationUnavailable, InputMediaUploadedDocument, ChannelFull,
|
||||||
|
@ -256,7 +257,7 @@ def get_input_document(document):
|
||||||
if isinstance(document, MessageMediaDocument):
|
if isinstance(document, MessageMediaDocument):
|
||||||
return get_input_document(document.document)
|
return get_input_document(document.document)
|
||||||
|
|
||||||
if isinstance(document, Message):
|
if isinstance(document, types.Message):
|
||||||
return get_input_document(document.media)
|
return get_input_document(document.media)
|
||||||
|
|
||||||
_raise_cast_fail(document, 'InputDocument')
|
_raise_cast_fail(document, 'InputDocument')
|
||||||
|
@ -299,7 +300,7 @@ def get_input_geo(geo):
|
||||||
if isinstance(geo, MessageMediaGeo):
|
if isinstance(geo, MessageMediaGeo):
|
||||||
return get_input_geo(geo.geo)
|
return get_input_geo(geo.geo)
|
||||||
|
|
||||||
if isinstance(geo, Message):
|
if isinstance(geo, types.Message):
|
||||||
return get_input_geo(geo.media)
|
return get_input_geo(geo.media)
|
||||||
|
|
||||||
_raise_cast_fail(geo, 'InputGeoPoint')
|
_raise_cast_fail(geo, 'InputGeoPoint')
|
||||||
|
@ -390,7 +391,7 @@ def get_input_media(media, is_photo=False):
|
||||||
ChatPhotoEmpty, UserProfilePhotoEmpty, FileLocationUnavailable)):
|
ChatPhotoEmpty, UserProfilePhotoEmpty, FileLocationUnavailable)):
|
||||||
return InputMediaEmpty()
|
return InputMediaEmpty()
|
||||||
|
|
||||||
if isinstance(media, Message):
|
if isinstance(media, types.Message):
|
||||||
return get_input_media(media.media, is_photo=is_photo)
|
return get_input_media(media.media, is_photo=is_photo)
|
||||||
|
|
||||||
_raise_cast_fail(media, 'InputMedia')
|
_raise_cast_fail(media, 'InputMedia')
|
||||||
|
@ -549,7 +550,7 @@ def get_input_location(location):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
_raise_cast_fail(location, 'InputFileLocation')
|
_raise_cast_fail(location, 'InputFileLocation')
|
||||||
|
|
||||||
if isinstance(location, Message):
|
if isinstance(location, types.Message):
|
||||||
location = location.media
|
location = location.media
|
||||||
|
|
||||||
if isinstance(location, MessageMediaDocument):
|
if isinstance(location, MessageMediaDocument):
|
||||||
|
@ -622,7 +623,7 @@ def is_list_like(obj):
|
||||||
other things), so just support the commonly known list-like objects.
|
other things), so just support the commonly known list-like objects.
|
||||||
"""
|
"""
|
||||||
return isinstance(obj, (list, tuple, set, dict,
|
return isinstance(obj, (list, tuple, set, dict,
|
||||||
UserList, types.GeneratorType))
|
UserList, GeneratorType))
|
||||||
|
|
||||||
|
|
||||||
def parse_phone(phone):
|
def parse_phone(phone):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user