Rename is_connected as connected

Since it makes more sense this way, because the former sounds
like a method when it's not.
This commit is contained in:
Lonami Exo 2019-06-16 11:44:01 +02:00
parent 6d4c8ba8ff
commit f9ca17c99f
6 changed files with 10 additions and 12 deletions

View File

@ -45,7 +45,7 @@ Base
connect
disconnect
is_connected
connected
disconnected
loop

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.connected:
await self.connect()
if await self.is_user_authorized():

View File

@ -432,20 +432,18 @@ class TelegramBaseClient(abc.ABC):
self._updates_handle = self._loop.create_task(self._update_loop())
@property
def is_connected(self: 'TelegramClient') -> bool:
def connected(self: 'TelegramClient') -> bool:
"""
Returns ``True`` if the user has connected.
This method is **not** asynchronous (don't use ``await`` on it).
Property which is ``True`` if the user has connected.
Example
.. code-block:: python
while client.is_connected:
while client.connected:
await asyncio.sleep(1)
"""
sender = getattr(self, '_sender', None)
return sender and sender.is_connected
return sender and sender.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.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.connected:
name = getattr(callback, '__name__', repr(callback))
self._log[__name__].exception('Unhandled exception on %s',
name)

View File

@ -123,7 +123,7 @@ class MTProtoSender:
self._user_connected = True
@property
def is_connected(self):
def connected(self):
return self._user_connected
async def disconnect(self):

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.connected:
return
# The user needs to configure a chat where the message should be sent.