diff options
author | Alex Grönholm <alex.gronholm@nextday.fi> | 2022-01-01 23:34:37 +0200 |
---|---|---|
committer | Alex Grönholm <alex.gronholm@nextday.fi> | 2022-01-02 00:40:13 +0200 |
commit | 46076956fed73635ee05db51f9116096039e9cde (patch) | |
tree | 6dfea242ef0ff1f5fc807cb864275c1b381425ba /src/apscheduler/eventbrokers | |
parent | a9b8d6caa1db4afd29b769e52da7ddd937726c84 (diff) | |
download | apscheduler-46076956fed73635ee05db51f9116096039e9cde.tar.gz |
Upgraded attrs and its imports
We now import "attrs" instead of "attr".
Diffstat (limited to 'src/apscheduler/eventbrokers')
-rw-r--r-- | src/apscheduler/eventbrokers/async_adapter.py | 4 | ||||
-rw-r--r-- | src/apscheduler/eventbrokers/async_local.py | 8 | ||||
-rw-r--r-- | src/apscheduler/eventbrokers/asyncpg.py | 8 | ||||
-rw-r--r-- | src/apscheduler/eventbrokers/base.py | 14 | ||||
-rw-r--r-- | src/apscheduler/eventbrokers/local.py | 10 | ||||
-rw-r--r-- | src/apscheduler/eventbrokers/mqtt.py | 18 | ||||
-rw-r--r-- | src/apscheduler/eventbrokers/redis.py | 14 |
7 files changed, 38 insertions, 38 deletions
diff --git a/src/apscheduler/eventbrokers/async_adapter.py b/src/apscheduler/eventbrokers/async_adapter.py index a91aae3..3f1e13f 100644 --- a/src/apscheduler/eventbrokers/async_adapter.py +++ b/src/apscheduler/eventbrokers/async_adapter.py @@ -2,7 +2,7 @@ from __future__ import annotations from functools import partial -import attr +import attrs from anyio import to_thread from anyio.from_thread import BlockingPortal @@ -13,7 +13,7 @@ from apscheduler.util import reentrant @reentrant -@attr.define(eq=False) +@attrs.define(eq=False) class AsyncEventBrokerAdapter(LocalAsyncEventBroker): original: EventBroker portal: BlockingPortal diff --git a/src/apscheduler/eventbrokers/async_local.py b/src/apscheduler/eventbrokers/async_local.py index 79030f3..cb0fb96 100644 --- a/src/apscheduler/eventbrokers/async_local.py +++ b/src/apscheduler/eventbrokers/async_local.py @@ -4,7 +4,7 @@ from asyncio import iscoroutine from contextlib import AsyncExitStack from typing import Any, Callable -import attr +import attrs from anyio import create_task_group from anyio.abc import TaskGroup @@ -15,10 +15,10 @@ from .base import BaseEventBroker @reentrant -@attr.define(eq=False) +@attrs.define(eq=False) class LocalAsyncEventBroker(AsyncEventBroker, BaseEventBroker): - _task_group: TaskGroup = attr.field(init=False) - _exit_stack: AsyncExitStack = attr.field(init=False) + _task_group: TaskGroup = attrs.field(init=False) + _exit_stack: AsyncExitStack = attrs.field(init=False) async def __aenter__(self) -> LocalAsyncEventBroker: self._exit_stack = AsyncExitStack() diff --git a/src/apscheduler/eventbrokers/asyncpg.py b/src/apscheduler/eventbrokers/asyncpg.py index 93bfd6a..ca58da9 100644 --- a/src/apscheduler/eventbrokers/asyncpg.py +++ b/src/apscheduler/eventbrokers/asyncpg.py @@ -3,7 +3,7 @@ from __future__ import annotations from contextlib import asynccontextmanager from typing import TYPE_CHECKING, AsyncContextManager, AsyncGenerator, Callable -import attr +import attrs from anyio import TASK_STATUS_IGNORED, sleep from asyncpg import Connection from asyncpg.pool import Pool @@ -19,11 +19,11 @@ if TYPE_CHECKING: @reentrant -@attr.define(eq=False) +@attrs.define(eq=False) class AsyncpgEventBroker(LocalAsyncEventBroker, DistributedEventBrokerMixin): connection_factory: Callable[[], AsyncContextManager[Connection]] - channel: str = attr.field(kw_only=True, default='apscheduler') - max_idle_time: float = attr.field(kw_only=True, default=30) + channel: str = attrs.field(kw_only=True, default='apscheduler') + max_idle_time: float = attrs.field(kw_only=True, default=30) @classmethod def from_asyncpg_pool(cls, pool: Pool) -> AsyncpgEventBroker: diff --git a/src/apscheduler/eventbrokers/base.py b/src/apscheduler/eventbrokers/base.py index 9947f68..8ec4dcb 100644 --- a/src/apscheduler/eventbrokers/base.py +++ b/src/apscheduler/eventbrokers/base.py @@ -4,7 +4,7 @@ from base64 import b64decode, b64encode from logging import Logger, getLogger from typing import Any, Callable, Iterable, Optional -import attr +import attrs from .. import events from ..abc import EventBroker, Serializer, Subscription @@ -12,7 +12,7 @@ from ..events import Event from ..exceptions import DeserializationError -@attr.define(eq=False, frozen=True) +@attrs.define(eq=False, frozen=True) class LocalSubscription(Subscription): callback: Callable[[Event], Any] event_types: Optional[set[type[Event]]] @@ -24,10 +24,10 @@ class LocalSubscription(Subscription): self._source.unsubscribe(self.token) -@attr.define(eq=False) +@attrs.define(eq=False) class BaseEventBroker(EventBroker): - _logger: Logger = attr.field(init=False) - _subscriptions: dict[object, LocalSubscription] = attr.field(init=False, factory=dict) + _logger: Logger = attrs.field(init=False) + _subscriptions: dict[object, LocalSubscription] = attrs.field(init=False, factory=dict) def __attrs_post_init__(self) -> None: self._logger = getLogger(self.__class__.__module__) @@ -50,11 +50,11 @@ class DistributedEventBrokerMixin: _logger: Logger def generate_notification(self, event: Event) -> bytes: - serialized = self.serializer.serialize(attr.asdict(event)) + serialized = self.serializer.serialize(attrs.asdict(event)) return event.__class__.__name__.encode('ascii') + b' ' + serialized def generate_notification_str(self, event: Event) -> str: - serialized = self.serializer.serialize(attr.asdict(event)) + serialized = self.serializer.serialize(attrs.asdict(event)) return event.__class__.__name__ + ' ' + b64encode(serialized).decode('ascii') def _reconstitute_event(self, event_type: str, serialized: bytes) -> Optional[Event]: diff --git a/src/apscheduler/eventbrokers/local.py b/src/apscheduler/eventbrokers/local.py index acf0c9a..fd345a1 100644 --- a/src/apscheduler/eventbrokers/local.py +++ b/src/apscheduler/eventbrokers/local.py @@ -6,7 +6,7 @@ from contextlib import ExitStack from threading import Lock from typing import Any, Callable, Iterable, Optional -import attr +import attrs from ..abc import Subscription from ..events import Event @@ -15,11 +15,11 @@ from .base import BaseEventBroker @reentrant -@attr.define(eq=False) +@attrs.define(eq=False) class LocalEventBroker(BaseEventBroker): - _executor: ThreadPoolExecutor = attr.field(init=False) - _exit_stack: ExitStack = attr.field(init=False) - _subscriptions_lock: Lock = attr.field(init=False, factory=Lock) + _executor: ThreadPoolExecutor = attrs.field(init=False) + _exit_stack: ExitStack = attrs.field(init=False) + _subscriptions_lock: Lock = attrs.field(init=False, factory=Lock) def __enter__(self): self._exit_stack = ExitStack() diff --git a/src/apscheduler/eventbrokers/mqtt.py b/src/apscheduler/eventbrokers/mqtt.py index dbdffe4..60e7195 100644 --- a/src/apscheduler/eventbrokers/mqtt.py +++ b/src/apscheduler/eventbrokers/mqtt.py @@ -3,7 +3,7 @@ from __future__ import annotations from concurrent.futures import Future from typing import Any, Optional -import attr +import attrs from paho.mqtt.client import Client, MQTTMessage from paho.mqtt.properties import Properties from paho.mqtt.reasoncodes import ReasonCodes @@ -17,16 +17,16 @@ from .local import LocalEventBroker @reentrant -@attr.define(eq=False) +@attrs.define(eq=False) class MQTTEventBroker(LocalEventBroker, DistributedEventBrokerMixin): client: Client - serializer: Serializer = attr.field(factory=JSONSerializer) - host: str = attr.field(kw_only=True, default='localhost') - port: int = attr.field(kw_only=True, default=1883) - topic: str = attr.field(kw_only=True, default='apscheduler') - subscribe_qos: int = attr.field(kw_only=True, default=0) - publish_qos: int = attr.field(kw_only=True, default=0) - _ready_future: Future[None] = attr.field(init=False) + serializer: Serializer = attrs.field(factory=JSONSerializer) + host: str = attrs.field(kw_only=True, default='localhost') + port: int = attrs.field(kw_only=True, default=1883) + topic: str = attrs.field(kw_only=True, default='apscheduler') + subscribe_qos: int = attrs.field(kw_only=True, default=0) + publish_qos: int = attrs.field(kw_only=True, default=0) + _ready_future: Future[None] = attrs.field(init=False) def __enter__(self): super().__enter__() diff --git a/src/apscheduler/eventbrokers/redis.py b/src/apscheduler/eventbrokers/redis.py index 68b86e0..eae5678 100644 --- a/src/apscheduler/eventbrokers/redis.py +++ b/src/apscheduler/eventbrokers/redis.py @@ -4,7 +4,7 @@ from concurrent.futures import Future from threading import Thread from typing import Optional -import attr +import attrs from redis import ConnectionPool, Redis from ..abc import Serializer @@ -16,14 +16,14 @@ from .local import LocalEventBroker @reentrant -@attr.define(eq=False) +@attrs.define(eq=False) class RedisEventBroker(LocalEventBroker, DistributedEventBrokerMixin): client: Redis - serializer: Serializer = attr.field(factory=JSONSerializer) - channel: str = attr.field(kw_only=True, default='apscheduler') - message_poll_interval: float = attr.field(kw_only=True, default=0.05) - _stopped: bool = attr.field(init=False, default=True) - _ready_future: Future[None] = attr.field(init=False) + serializer: Serializer = attrs.field(factory=JSONSerializer) + channel: str = attrs.field(kw_only=True, default='apscheduler') + message_poll_interval: float = attrs.field(kw_only=True, default=0.05) + _stopped: bool = attrs.field(init=False, default=True) + _ready_future: Future[None] = attrs.field(init=False) @classmethod def from_url(cls, url: str, db: Optional[str] = None, decode_components: bool = False, |