Skip to content

Added a support to be able to use the port 2197 as alternative port to send notifications. #70

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

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
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ docs/_build/
target/

# PyCharm
.idea
.idea

# Virtual Envs
.venv/
venv/

# PyEnv files
.python-version
3 changes: 3 additions & 0 deletions aioapns/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(
[NotificationRequest, NotificationResult], Awaitable[None]
]
] = None,
use_alternative_port: bool = False,
) -> None:
self.pool: APNsBaseConnectionPool
self.err_func = err_func
Expand All @@ -46,6 +47,7 @@ def __init__(
ssl_context=ssl_context,
proxy_host=proxy_host,
proxy_port=proxy_port,
use_alternative_port=use_alternative_port,
)
elif key and key_id and team_id and topic:
self.pool = APNsKeyConnectionPool(
Expand All @@ -59,6 +61,7 @@ def __init__(
ssl_context=ssl_context,
proxy_host=proxy_host,
proxy_port=proxy_port,
use_alternative_port=use_alternative_port,
)
else:
raise ValueError(
Expand Down
16 changes: 16 additions & 0 deletions aioapns/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def __init__(
self.push_type = push_type
self.apns_topic = apns_topic

def __str__(self) -> str:
return str(
{"device_token": self.device_token, "message": self.message}
)

def __repr__(self) -> str:
return str({a: str(getattr(self, a)) for a in self.__slots__})


class NotificationResult:
__slots__ = ("notification_id", "status", "description", "timestamp")
Expand All @@ -70,6 +78,14 @@ def __init__(
def is_successful(self) -> bool:
return self.status == APNS_RESPONSE_CODE.SUCCESS

def __str__(self) -> str:
return str(
{"notification_id": self.notification_id, "status": self.status}
)

def __repr__(self) -> str:
return str({a: str(getattr(self, a)) for a in self.__slots__})


class DynamicBoundedSemaphore(asyncio.BoundedSemaphore):
_bound_value: int
Expand Down
8 changes: 8 additions & 0 deletions aioapns/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ def __init__(
use_sandbox: bool = False,
proxy_host: Optional[str] = None,
proxy_port: Optional[int] = None,
use_alternative_port: bool = False,
) -> None:
self.apns_topic = topic
self.max_connections = max_connections
Expand All @@ -339,6 +340,9 @@ def __init__(
self.protocol_class = APNsDevelopmentClientProtocol
else:
self.protocol_class = APNsProductionClientProtocol
if use_alternative_port:
# The same alternative port adopted by apns2
self.protocol_class.APNS_PORT = 2197

self.loop = asyncio.get_event_loop()
self.connections: List[APNsBaseClientProtocol] = []
Expand Down Expand Up @@ -472,6 +476,7 @@ def __init__(
ssl_context: Optional[ssl.SSLContext] = None,
proxy_host: Optional[str] = None,
proxy_port: Optional[int] = None,
use_alternative_port: bool = False,
) -> None:
super(APNsCertConnectionPool, self).__init__(
topic=topic,
Expand All @@ -480,6 +485,7 @@ def __init__(
use_sandbox=use_sandbox,
proxy_host=proxy_host,
proxy_port=proxy_port,
use_alternative_port=use_alternative_port,
)

self.cert_file = cert_file
Expand Down Expand Up @@ -535,6 +541,7 @@ def __init__(
ssl_context: Optional[ssl.SSLContext] = None,
proxy_host: Optional[str] = None,
proxy_port: Optional[int] = None,
use_alternative_port: bool = False,
) -> None:
super(APNsKeyConnectionPool, self).__init__(
topic=topic,
Expand All @@ -543,6 +550,7 @@ def __init__(
use_sandbox=use_sandbox,
proxy_host=proxy_host,
proxy_port=proxy_port,
use_alternative_port=use_alternative_port,
)

self.ssl_context = ssl_context or ssl.create_default_context()
Expand Down