From d6b0694be2970bb2a2c54520b564bf340f7cd158 Mon Sep 17 00:00:00 2001 From: maxzhx Date: Mon, 23 Aug 2021 22:09:51 +0800 Subject: [PATCH] add tuple type to credential input --- apns2/client.py | 4 ++-- apns2/credentials.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apns2/client.py b/apns2/client.py index 0947350..6621e10 100644 --- a/apns2/client.py +++ b/apns2/client.py @@ -47,12 +47,12 @@ class APNsClient(object): ALTERNATIVE_PORT = 2197 def __init__(self, - credentials: Union[Credentials, str], + credentials: Union[Credentials, str, tuple], use_sandbox: bool = False, use_alternative_port: bool = False, proto: Optional[str] = None, json_encoder: Optional[type] = None, password: Optional[str] = None, proxy_host: Optional[str] = None, proxy_port: Optional[int] = None, heartbeat_period: Optional[float] = None) -> None: - if isinstance(credentials, str): + if isinstance(credentials, str) or isinstance(credentials, tuple): self.__credentials = CertificateCredentials(credentials, password) # type: Credentials else: self.__credentials = credentials diff --git a/apns2/credentials.py b/apns2/credentials.py index 028093e..574cc09 100644 --- a/apns2/credentials.py +++ b/apns2/credentials.py @@ -1,5 +1,5 @@ import time -from typing import Optional, Tuple, TYPE_CHECKING +from typing import Optional, Tuple, Union, TYPE_CHECKING import jwt @@ -32,7 +32,7 @@ def get_authorization_header(self, topic: Optional[str]) -> Optional[str]: # Credentials subclass for certificate authentication class CertificateCredentials(Credentials): - def __init__(self, cert_file: Optional[str] = None, password: Optional[str] = None, + def __init__(self, cert_file: Union[str, tuple, None] = None, password: Optional[str] = None, cert_chain: Optional[str] = None) -> None: ssl_context = init_context(cert=cert_file, cert_password=password) if cert_chain: