Update 'apns2/client.py'

- fix backward compatibility
This commit is contained in:
2022-04-17 10:29:38 +03:00
parent 04bbafd195
commit 34fd0d0264
+17 -15
View File
@@ -89,8 +89,9 @@ class APNsClient(object):
def send_notification(self, token_hex: str, notification: Payload, topic: Optional[str] = None, def send_notification(self, token_hex: str, notification: Payload, topic: Optional[str] = None,
priority: NotificationPriority = NotificationPriority.Immediate, priority: NotificationPriority = NotificationPriority.Immediate,
expiration: Optional[int] = None, collapse_id: Optional[str] = None) -> None: expiration: Optional[int] = None, collapse_id: Optional[str] = None) -> None:
stream_id = self.send_notification_async(token_hex, notification, topic, priority, expiration, collapse_id) stream_id, reason = self.send_notification_async(token_hex, notification, topic, priority, expiration, collapse_id)
result = self.get_notification_result(stream_id) result = self.get_notification_result(stream_id, reason)
print(123, result)
if result != 'Success': if result != 'Success':
if isinstance(result, tuple): if isinstance(result, tuple):
reason, info = result reason, info = result
@@ -242,16 +243,17 @@ class APNsClient(object):
connection fails, the function retries up to MAX_CONNECTION_RETRIES times. connection fails, the function retries up to MAX_CONNECTION_RETRIES times.
""" """
retries = 0 retries = 0
while retries < MAX_CONNECTION_RETRIES: return
# noinspection PyBroadException # while retries < MAX_CONNECTION_RETRIES:
try: # # noinspection PyBroadException
self._connection.connect() # try:
logger.info('Connected to APNs') # self._connection.connect()
return # logger.info('Connected to APNs')
except Exception: # pylint: disable=broad-except # return
# close the connnection, otherwise next connect() call would do nothing # except Exception: # pylint: disable=broad-except
self._connection.close() # # close the connnection, otherwise next connect() call would do nothing
retries += 1 # self._connection.close()
logger.exception('Failed connecting to APNs (attempt %s of %s)', retries, MAX_CONNECTION_RETRIES) # retries += 1
# logger.exception('Failed connecting to APNs (attempt %s of %s)', retries, MAX_CONNECTION_RETRIES)
raise ConnectionFailed() #
# raise ConnectionFailed()