Fix is_connected intent and calls from 6226fa9

This commit is contained in:
Lonami Exo 2019-06-15 20:54:47 +02:00
parent 80e86e98ff
commit 0b69d7fd7b
4 changed files with 7 additions and 6 deletions

View File

@ -137,7 +137,7 @@ class AuthMethods(MessageParseMethods, UserMethods):
async def _start(
self, phone, password, bot_token, force_sms,
code_callback, first_name, last_name, max_attempts):
if not self.is_connected():
if not self.is_connected:
await self.connect()
if await self.is_user_authorized():

View File

@ -432,6 +432,7 @@ class TelegramBaseClient(abc.ABC):
self._updates_handle = self._loop.create_task(self._update_loop())
@property
def is_connected(self: 'TelegramClient') -> bool:
"""
Returns ``True`` if the user has connected.
@ -441,11 +442,11 @@ class TelegramBaseClient(abc.ABC):
Example
.. code-block:: python
while client.is_connected():
while client.is_connected:
await asyncio.sleep(1)
"""
sender = getattr(self, '_sender', None)
return sender and sender.is_connected()
return sender and sender.is_connected
def disconnect(self: 'TelegramClient'):
"""

View File

@ -323,7 +323,7 @@ class UpdateMethods(UserMethods):
async def _update_loop(self: 'TelegramClient'):
# Pings' ID don't really need to be secure, just "random"
rnd = lambda: random.randrange(-2**63, 2**63)
while self.is_connected():
while self.is_connected:
try:
await asyncio.wait_for(
self.disconnected, timeout=60, loop=self._loop
@ -425,7 +425,7 @@ class UpdateMethods(UserMethods):
)
break
except Exception as e:
if not isinstance(e, asyncio.CancelledError) or self.is_connected():
if not isinstance(e, asyncio.CancelledError) or self.is_connected:
name = getattr(callback, '__name__', repr(callback))
self._log[__name__].exception('Unhandled exception on %s',
name)

View File

@ -228,7 +228,7 @@ class App(tkinter.Tk):
"""
Sends a message. Does nothing if the client is not connected.
"""
if not self.cl.is_connected():
if not self.cl.is_connected:
return
# The user needs to configure a chat where the message should be sent.