-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from pomponchik/develop
0.0.26
- Loading branch information
Showing
21 changed files
with
768 additions
and
97 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
venv | ||
venv2 | ||
.pytest_cache | ||
*.egg-info | ||
build | ||
|
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 +1 @@ | ||
ignore = ['E501', 'E712'] | ||
ignore = ['E501', 'E712', 'F821'] |
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
Empty file.
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,7 @@ | ||
from enum import Enum | ||
|
||
|
||
class CancelCause(Enum): | ||
CANCELLED = 1 | ||
SUPERPOWER = 2 | ||
NOT_CANCELLED = 3 |
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,53 @@ | ||
import weakref | ||
from sys import getrefcount | ||
from typing import Dict, Union, Optional, Any | ||
from types import TracebackType | ||
from collections.abc import Coroutine | ||
from time import sleep as sync_sleep | ||
from asyncio import sleep as async_sleep | ||
|
||
|
||
class WaitCoroutineWrapper(Coroutine): # type: ignore[type-arg] | ||
def __init__(self, step: Union[int, float], token_for_wait: 'AbstractToken', token_for_check: 'AbstractToken') -> None: # type: ignore[name-defined] | ||
self.step = step | ||
self.token_for_wait = token_for_wait | ||
self.token_for_check = token_for_check | ||
|
||
self.flags: Dict[str, bool] = {} | ||
self.coroutine = self.async_wait(step, self.flags, token_for_wait, token_for_check) | ||
|
||
weakref.finalize(self, self.sync_wait, step, self.flags, token_for_wait, token_for_check, self.coroutine) | ||
|
||
def __await__(self) -> Any: | ||
return self.coroutine.__await__() | ||
|
||
def send(self, value: Any) -> Any: | ||
return self.coroutine.send(value) | ||
|
||
def throw(self, exception_type: Any, value: Optional[Any] = None, traceback: Optional[TracebackType] = None) -> Any: | ||
pass # pragma: no cover | ||
|
||
def close(self) -> None: | ||
pass # pragma: no cover | ||
|
||
@staticmethod | ||
def sync_wait(step: Union[int, float], flags: Dict[str, bool], token_for_wait: 'AbstractToken', token_for_check: 'AbstractToken', wrapped_coroutine: Coroutine) -> None: # type: ignore[type-arg, name-defined] | ||
if not flags.get('used', False): | ||
if getrefcount(wrapped_coroutine) < 5: | ||
wrapped_coroutine.close() | ||
|
||
while token_for_wait: | ||
sync_sleep(step) | ||
|
||
token_for_check.check() | ||
|
||
@staticmethod | ||
async def async_wait(step: Union[int, float], flags: Dict[str, bool], token_for_wait: 'AbstractToken', token_for_check: 'AbstractToken') -> None: # type: ignore[name-defined] | ||
flags['used'] = True | ||
|
||
while token_for_wait: | ||
await async_sleep(step) | ||
|
||
await async_sleep(0) | ||
|
||
token_for_check.check() |
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,16 @@ | ||
from typing import Dict | ||
from dataclasses import dataclass | ||
from sys import version_info | ||
|
||
from cantok.tokens.abstract.cancel_cause import CancelCause | ||
|
||
|
||
if version_info >= (3, 10): | ||
addictional_fields: Dict[str, bool] = {'slots': True} # pragma: no cover | ||
else: | ||
addictional_fields = {} # pragma: no cover | ||
|
||
@dataclass(frozen=True, **addictional_fields) # type: ignore[call-overload, unused-ignore] | ||
class CancellationReport: | ||
cause: CancelCause | ||
from_token: 'AbstractToken' # type: ignore[name-defined] |
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
Empty file.
Oops, something went wrong.