Tiny style fixes

This commit is contained in:
Dmitry D. Chernov 2019-02-07 06:55:34 +10:00
parent c8f16a4e89
commit fc2977fc0d
2 changed files with 7 additions and 9 deletions

View File

@ -75,12 +75,10 @@ def strip_text(text, entities):
def retry_range(retries): def retry_range(retries):
""" """
Generates an integer sequence starting from 1. If `retries` is Generates an integer sequence starting from 1. If `retries` is
negative or ``None`` then sequence is infinite, otherwise it will not a zero or a positive integer value, the sequence will be
end at `retries + 1`. infinite, otherwise it will end at `retries + 1`.
""" """
yield 1 yield 1
if retries is None:
retries = -1
attempt = 0 attempt = 0
while attempt != retries: while attempt != retries:
attempt += 1 attempt += 1

View File

@ -218,7 +218,7 @@ class MTProtoSender:
await self._connection.connect(timeout=self._connect_timeout) await self._connection.connect(timeout=self._connect_timeout)
except (ConnectionError, asyncio.TimeoutError) as e: except (ConnectionError, asyncio.TimeoutError) as e:
self._log.warning('Attempt {} at connecting failed: {}: {}' self._log.warning('Attempt {} at connecting failed: {}: {}'
.format(attempt, type(e).__name__, e)) .format(attempt, type(e).__name__, e))
await asyncio.sleep(self._delay) await asyncio.sleep(self._delay)
else: else:
break break
@ -246,7 +246,7 @@ class MTProtoSender:
break break
except (SecurityError, AssertionError) as e: except (SecurityError, AssertionError) as e:
self._log.warning('Attempt {} at new auth_key failed: {}' self._log.warning('Attempt {} at new auth_key failed: {}'
.format(attempt, e)) .format(attempt, e))
await asyncio.sleep(self._delay) await asyncio.sleep(self._delay)
else: else:
e = ConnectionError('auth_key generation failed {} time(s)' e = ConnectionError('auth_key generation failed {} time(s)'
@ -276,7 +276,7 @@ class MTProtoSender:
self._connection.disconnect() self._connection.disconnect()
finally: finally:
self._log.debug('Cancelling {} pending message(s)...' self._log.debug('Cancelling {} pending message(s)...'
.format(len(self._pending_state))) .format(len(self._pending_state)))
for state in self._pending_state.values(): for state in self._pending_state.values():
if error and not state.future.done(): if error and not state.future.done():
state.future.set_exception(error) state.future.set_exception(error)
@ -515,7 +515,7 @@ class MTProtoSender:
raise ValueError('Not an upload.File') raise ValueError('Not an upload.File')
except (TypeNotFoundError, ValueError): except (TypeNotFoundError, ValueError):
self._log.info('Received response without parent request: {}' self._log.info('Received response without parent request: {}'
.format(rpc_result.body)) .format(rpc_result.body))
return return
if rpc_result.error: if rpc_result.error:
@ -555,7 +555,7 @@ class MTProtoSender:
async def _handle_update(self, message): async def _handle_update(self, message):
self._log.debug('Handling update {}' self._log.debug('Handling update {}'
.format(message.obj.__class__.__name__)) .format(message.obj.__class__.__name__))
if self._update_callback: if self._update_callback:
await self._update_callback(message.obj) await self._update_callback(message.obj)