mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-11-14 21:10:40 +00:00
Subclass TLRequest for content-related objects
This commit is contained in:
@@ -1 +1 @@
|
||||
from .tlobject import TLObject
|
||||
from .tlobject import TLObject, TLRequest
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import gzip
|
||||
import struct
|
||||
|
||||
from .. import TLObject
|
||||
from .. import TLObject, TLRequest
|
||||
|
||||
|
||||
class GzipPacked(TLObject):
|
||||
@@ -21,7 +21,7 @@ class GzipPacked(TLObject):
|
||||
"""
|
||||
data = bytes(request)
|
||||
# TODO This threshold could be configurable
|
||||
if request.content_related and len(data) > 512:
|
||||
if isinstance(request, TLRequest) and len(data) > 512:
|
||||
gzipped = bytes(GzipPacked(data))
|
||||
return gzipped if len(gzipped) < len(data) else data
|
||||
else:
|
||||
|
||||
@@ -11,13 +11,10 @@ class MessageContainer(TLObject):
|
||||
CONSTRUCTOR_ID = 0x73f1f8dc
|
||||
|
||||
def __init__(self, messages):
|
||||
super().__init__()
|
||||
self.content_related = False
|
||||
self.messages = messages
|
||||
|
||||
def to_dict(self, recursive=True):
|
||||
return {
|
||||
'content_related': self.content_related,
|
||||
'messages':
|
||||
([] if self.messages is None else [
|
||||
None if x is None else x.to_dict() for x in self.messages
|
||||
|
||||
@@ -3,16 +3,11 @@ from datetime import datetime, date
|
||||
|
||||
|
||||
class TLObject:
|
||||
def __init__(self):
|
||||
# TODO Perhaps content_related makes more sense as another type?
|
||||
# Something like class TLRequest(TLObject), request inherit this
|
||||
self.content_related = False # Only requests/functions/queries are
|
||||
|
||||
# These should not be overrode
|
||||
@staticmethod
|
||||
def pretty_format(obj, indent=None):
|
||||
"""Pretty formats the given object as a string which is returned.
|
||||
If indent is None, a single line will be returned.
|
||||
"""
|
||||
Pretty formats the given object as a string which is returned.
|
||||
If indent is None, a single line will be returned.
|
||||
"""
|
||||
if indent is None:
|
||||
if isinstance(obj, TLObject):
|
||||
@@ -136,11 +131,6 @@ class TLObject:
|
||||
|
||||
raise TypeError('Cannot interpret "{}" as a date.'.format(dt))
|
||||
|
||||
# These are nearly always the same for all subclasses
|
||||
@staticmethod
|
||||
def read_result(reader):
|
||||
return reader.tgread_object()
|
||||
|
||||
def __eq__(self, o):
|
||||
return isinstance(o, type(self)) and self.to_dict() == o.to_dict()
|
||||
|
||||
@@ -153,16 +143,24 @@ class TLObject:
|
||||
def stringify(self):
|
||||
return TLObject.pretty_format(self, indent=0)
|
||||
|
||||
# These should be overrode
|
||||
async def resolve(self, client, utils):
|
||||
pass
|
||||
|
||||
def to_dict(self):
|
||||
return {}
|
||||
raise NotImplementedError
|
||||
|
||||
def __bytes__(self):
|
||||
return b''
|
||||
raise NotImplementedError
|
||||
|
||||
@classmethod
|
||||
def from_reader(cls, reader):
|
||||
return TLObject()
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class TLRequest(TLObject):
|
||||
"""
|
||||
Represents a content-related `TLObject` (a request that can be sent).
|
||||
"""
|
||||
@staticmethod
|
||||
def read_result(reader):
|
||||
return reader.tgread_object()
|
||||
|
||||
async def resolve(self, client, utils):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user