Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tuple type to credential input #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apns2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use isinstance(credentials, (str, tuple))

self.__credentials = CertificateCredentials(credentials, password) # type: Credentials
else:
self.__credentials = credentials
Expand Down
4 changes: 2 additions & 2 deletions apns2/credentials.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from typing import Optional, Tuple, TYPE_CHECKING
from typing import Optional, Tuple, Union, TYPE_CHECKING

import jwt

Expand Down Expand Up @@ -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:
Expand Down