mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-03 21:24:35 +03:00
Revisit and remove a few TODOs
This commit is contained in:
parent
ebfe8ebf40
commit
463847ad50
|
@ -138,7 +138,6 @@ class ChatMethods(UserMethods):
|
||||||
return
|
return
|
||||||
|
|
||||||
elif isinstance(entity, types.InputPeerChat):
|
elif isinstance(entity, types.InputPeerChat):
|
||||||
# TODO We *could* apply the `filter` here ourselves
|
|
||||||
full = await self(
|
full = await self(
|
||||||
functions.messages.GetFullChatRequest(entity.chat_id))
|
functions.messages.GetFullChatRequest(entity.chat_id))
|
||||||
if not isinstance(
|
if not isinstance(
|
||||||
|
|
|
@ -111,7 +111,7 @@ class DialogMethods(UserMethods):
|
||||||
return dialogs
|
return dialogs
|
||||||
|
|
||||||
@async_generator
|
@async_generator
|
||||||
async def iter_drafts(self): # TODO: Ability to provide a `filter`
|
async def iter_drafts(self):
|
||||||
"""
|
"""
|
||||||
Iterator over all open draft messages.
|
Iterator over all open draft messages.
|
||||||
|
|
||||||
|
|
|
@ -219,13 +219,6 @@ class TelegramBaseClient(abc.ABC):
|
||||||
self._last_ping = datetime.now()
|
self._last_ping = datetime.now()
|
||||||
self._ping_delay = timedelta(minutes=1)
|
self._ping_delay = timedelta(minutes=1)
|
||||||
|
|
||||||
# Also have another delay for GetStateRequest.
|
|
||||||
#
|
|
||||||
# If the connection is kept alive for long without invoking any
|
|
||||||
# high level request the server simply stops sending updates.
|
|
||||||
# TODO maybe we can have ._last_request instead if any req works?
|
|
||||||
self._last_state = datetime.now()
|
|
||||||
self._state_delay = timedelta(hours=1)
|
|
||||||
self._state = None
|
self._state = None
|
||||||
self._updates_handle = None
|
self._updates_handle = None
|
||||||
self._last_request = time.time()
|
self._last_request = time.time()
|
||||||
|
@ -295,8 +288,6 @@ class TelegramBaseClient(abc.ABC):
|
||||||
Disconnects from Telegram.
|
Disconnects from Telegram.
|
||||||
"""
|
"""
|
||||||
await self._sender.disconnect()
|
await self._sender.disconnect()
|
||||||
# TODO What to do with the update state? Does it belong here?
|
|
||||||
# self.session.set_update_state(0, self.updates.get_update_state(0))
|
|
||||||
self.session.close()
|
self.session.close()
|
||||||
|
|
||||||
async def _switch_dc(self, new_dc):
|
async def _switch_dc(self, new_dc):
|
||||||
|
|
|
@ -25,11 +25,6 @@ __log__ = logging.getLogger(__name__)
|
||||||
_reconnect_sentinel = object()
|
_reconnect_sentinel = object()
|
||||||
|
|
||||||
|
|
||||||
# TODO Create some kind of "ReconnectionPolicy" that allows specifying
|
|
||||||
# what should be done in case of some errors, with some sane defaults.
|
|
||||||
# For instance, should all messages be set with an error upon network
|
|
||||||
# loss? Should we try reconnecting forever? A certain amount of times?
|
|
||||||
# A timeout? What about recoverable errors, like connection reset?
|
|
||||||
class MTProtoSender:
|
class MTProtoSender:
|
||||||
"""
|
"""
|
||||||
MTProto Mobile Protocol sender
|
MTProto Mobile Protocol sender
|
||||||
|
@ -386,10 +381,6 @@ class MTProtoSender:
|
||||||
Besides `connect`, only this method ever receives data.
|
Besides `connect`, only this method ever receives data.
|
||||||
"""
|
"""
|
||||||
while self._user_connected and not self._reconnecting:
|
while self._user_connected and not self._reconnecting:
|
||||||
# TODO Are there more exceptions besides timeout?
|
|
||||||
# Disconnecting or switching off WiFi only resulted in
|
|
||||||
# timeouts, and once the network was back it continued
|
|
||||||
# on its own after a short delay.
|
|
||||||
try:
|
try:
|
||||||
__log__.debug('Receiving items from the network...')
|
__log__.debug('Receiving items from the network...')
|
||||||
body = await self._connection.recv()
|
body = await self._connection.recv()
|
||||||
|
|
|
@ -20,7 +20,6 @@ class GzipPacked(TLObject):
|
||||||
Note that this only applies to content related requests.
|
Note that this only applies to content related requests.
|
||||||
"""
|
"""
|
||||||
data = bytes(request)
|
data = bytes(request)
|
||||||
# TODO This threshold could be configurable
|
|
||||||
if isinstance(request, TLRequest) and len(data) > 512:
|
if isinstance(request, TLRequest) and len(data) > 512:
|
||||||
gzipped = bytes(GzipPacked(data))
|
gzipped = bytes(GzipPacked(data))
|
||||||
return gzipped if len(gzipped) < len(data) else data
|
return gzipped if len(gzipped) < len(data) else data
|
||||||
|
@ -28,7 +27,6 @@ class GzipPacked(TLObject):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def __bytes__(self):
|
def __bytes__(self):
|
||||||
# TODO Maybe compress level could be an option
|
|
||||||
return struct.pack('<I', GzipPacked.CONSTRUCTOR_ID) + \
|
return struct.pack('<I', GzipPacked.CONSTRUCTOR_ID) + \
|
||||||
TLObject.serialize_bytes(gzip.compress(self.data))
|
TLObject.serialize_bytes(gzip.compress(self.data))
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,6 @@ class UpdateState:
|
||||||
for u in update.updates:
|
for u in update.updates:
|
||||||
u._entities = entities
|
u._entities = entities
|
||||||
self._updates.put(u)
|
self._updates.put(u)
|
||||||
# TODO Handle "tl.UpdatesTooLong"
|
|
||||||
else:
|
else:
|
||||||
update._entities = {}
|
update._entities = {}
|
||||||
self._updates.put(update)
|
self._updates.put(update)
|
||||||
|
|
|
@ -80,7 +80,6 @@ def _find_title(html_file):
|
||||||
def _build_menu(docs, filename, root, relative_main_index):
|
def _build_menu(docs, filename, root, relative_main_index):
|
||||||
"""Builds the menu using the given DocumentWriter up to 'filename',
|
"""Builds the menu using the given DocumentWriter up to 'filename',
|
||||||
which must be a file (it cannot be a directory)"""
|
which must be a file (it cannot be a directory)"""
|
||||||
# TODO Maybe this could be part of DocsWriter itself, "build path menu"
|
|
||||||
filename = _get_relative_path(filename, root)
|
filename = _get_relative_path(filename, root)
|
||||||
docs.add_menu('API', relative_main_index)
|
docs.add_menu('API', relative_main_index)
|
||||||
|
|
||||||
|
@ -238,7 +237,6 @@ def _write_html_pages(tlobjects, errors, layer, input_res, output_dir):
|
||||||
# Save 'Type: [Constructors]' for use in both:
|
# Save 'Type: [Constructors]' for use in both:
|
||||||
# * Seeing the return type or constructors belonging to the same type.
|
# * Seeing the return type or constructors belonging to the same type.
|
||||||
# * Generating the types documentation, showing available constructors.
|
# * Generating the types documentation, showing available constructors.
|
||||||
# TODO Tried using 'defaultdict(list)' with strange results, make it work.
|
|
||||||
original_paths = {
|
original_paths = {
|
||||||
'css': 'css',
|
'css': 'css',
|
||||||
'arrow': 'img/arrow.svg',
|
'arrow': 'img/arrow.svg',
|
||||||
|
@ -254,14 +252,11 @@ def _write_html_pages(tlobjects, errors, layer, input_res, output_dir):
|
||||||
for k, v in original_paths.items()}
|
for k, v in original_paths.items()}
|
||||||
|
|
||||||
original_paths['default_css'] = 'light' # docs.<name>.css, local path
|
original_paths['default_css'] = 'light' # docs.<name>.css, local path
|
||||||
type_to_constructors = {}
|
type_to_constructors = defaultdict(list)
|
||||||
type_to_functions = {}
|
type_to_functions = defaultdict(list)
|
||||||
for tlobject in tlobjects:
|
for tlobject in tlobjects:
|
||||||
d = type_to_functions if tlobject.is_function else type_to_constructors
|
d = type_to_functions if tlobject.is_function else type_to_constructors
|
||||||
if tlobject.result in d:
|
d[tlobject.result].append(tlobject)
|
||||||
d[tlobject.result].append(tlobject)
|
|
||||||
else:
|
|
||||||
d[tlobject.result] = [tlobject]
|
|
||||||
|
|
||||||
for t, cs in type_to_constructors.items():
|
for t, cs in type_to_constructors.items():
|
||||||
type_to_constructors[t] = list(sorted(cs, key=lambda c: c.name))
|
type_to_constructors[t] = list(sorted(cs, key=lambda c: c.name))
|
||||||
|
@ -412,7 +407,6 @@ def _write_html_pages(tlobjects, errors, layer, input_res, output_dir):
|
||||||
docs.write_text('You can import these from '
|
docs.write_text('You can import these from '
|
||||||
'<code>telethon.errors</code>.')
|
'<code>telethon.errors</code>.')
|
||||||
|
|
||||||
# TODO Bit hacky, make everything like this? (prepending '../')
|
|
||||||
depth = '../' * (2 if tlobject.namespace else 1)
|
depth = '../' * (2 if tlobject.namespace else 1)
|
||||||
docs.add_script(src='prependPath = "{}";'.format(depth))
|
docs.add_script(src='prependPath = "{}";'.format(depth))
|
||||||
docs.add_script(relative_src=paths['search.js'])
|
docs.add_script(relative_src=paths['search.js'])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user