-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite: APNs: Scoped App Tokens (#101)
+ Adds a lot of new API surface around filters + Adds CI type checking and linting
- Loading branch information
1 parent
b1c30a9
commit ce88a8e
Showing
17 changed files
with
495 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Pyright | ||
on: [push, pull_request] | ||
jobs: | ||
pyright: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
cache: 'pip' | ||
|
||
- run: | | ||
python -m venv .venv | ||
source .venv/bin/activate | ||
pip install -e '.[test,cli]' | ||
- run: echo "$PWD/.venv/bin" >> $GITHUB_PATH | ||
- uses: jakebailey/pyright-action@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: Ruff | ||
on: [push, pull_request] | ||
jobs: | ||
ruff: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: chartboost/ruff-action@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
__all__ = ["protocol", "create_apns_connection", "activate"] | ||
__all__ = ["protocol", "create_apns_connection", "activate", "filters"] | ||
|
||
from . import protocol | ||
from .lifecycle import create_apns_connection | ||
from . import filters, protocol | ||
from .albert import activate | ||
from .lifecycle import create_apns_connection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import logging | ||
from typing import Callable, Optional, Type, TypeVar | ||
|
||
from pypush.apns import protocol | ||
|
||
T1 = TypeVar("T1") | ||
T2 = TypeVar("T2") | ||
Filter = Callable[[T1], Optional[T2]] | ||
|
||
# Chain with proper types so that subsequent filters only need to take output type of previous filter | ||
T_IN = TypeVar("T_IN", bound=protocol.Command) | ||
T_MIDDLE = TypeVar("T_MIDDLE", bound=protocol.Command) | ||
T_OUT = TypeVar("T_OUT", bound=protocol.Command) | ||
|
||
|
||
def chain(first: Filter[T_IN, T_MIDDLE], second: Filter[T_MIDDLE, T_OUT]): | ||
def filter(command: T_IN) -> Optional[T_OUT]: | ||
logging.debug(f"Filtering {command} with {first} and {second}") | ||
filtered = first(command) | ||
if filtered is None: | ||
return None | ||
return second(filtered) | ||
|
||
return filter | ||
|
||
|
||
T = TypeVar("T", bound=protocol.Command) | ||
|
||
|
||
def cmd(type: Type[T]) -> Filter[protocol.Command, T]: | ||
def filter(command: protocol.Command) -> Optional[T]: | ||
if isinstance(command, type): | ||
return command | ||
return None | ||
|
||
return filter | ||
|
||
|
||
def ALL(c): | ||
return c | ||
|
||
|
||
def NONE(_): | ||
return None |
Oops, something went wrong.