Add new method to .resolve() parameters instead on init

TLObject's __init__ used to call utils.get_input_* methods and
similar to auto-cast things like User into InputPeerUser as
required. Now there's a custom .resolve() method for this purpose
with several advantages:
- Old behaviour still works, autocasts work like usual.

- A request can be constructed and later modified, before the
  autocast only occured on the constructor but now while invoking.

- This allows us to not only use the utils module but also the
  client, so it's even possible to use usernames or phone numbers
  for things that require an InputPeer. This actually assumes
  the TelegramClient subclass is being used and not the bare version
  which would fail when calling .get_input_peer().
This commit is contained in:
Lonami Exo
2018-01-19 11:47:45 +01:00
parent 7c55d42287
commit 1c9fa76ede
3 changed files with 60 additions and 52 deletions

View File

@@ -7,7 +7,7 @@ from signal import signal, SIGINT, SIGTERM, SIGABRT
from threading import Lock
from time import sleep
from . import version
from . import version, utils
from .crypto import rsa
from .errors import (
RPCError, BrokenAuthKeyError, ServerError, FloodWaitError,
@@ -420,6 +420,9 @@ class TelegramBareClient:
if self._background_error:
raise self._background_error
for request in requests:
request.resolve(self, utils)
# For logging purposes
if len(requests) == 1:
which = type(requests[0]).__name__