From 47ee2170ce5ef89f3a51046a40a1346eb84f5071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Tue, 17 Oct 2023 14:45:56 +0200 Subject: [PATCH] fix deprecated calls --- api/ovdashboard_api/__init__.py | 2 +- api/ovdashboard_api/config.py | 8 ++++---- api/ovdashboard_api/dav_calendar.py | 4 ++-- api/ovdashboard_api/routers/v1/_common.py | 2 +- api/ovdashboard_api/settings.py | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api/ovdashboard_api/__init__.py b/api/ovdashboard_api/__init__.py index eceaae6..67b78ba 100644 --- a/api/ovdashboard_api/__init__.py +++ b/api/ovdashboard_api/__init__.py @@ -43,4 +43,4 @@ class LogConfig(BaseModel): } -dictConfig(LogConfig().dict()) +dictConfig(LogConfig().model_dump()) diff --git a/api/ovdashboard_api/config.py b/api/ovdashboard_api/config.py index 35eb98b..776e800 100644 --- a/api/ovdashboard_api/config.py +++ b/api/ovdashboard_api/config.py @@ -2,13 +2,13 @@ Python representation of the "config.txt" file inside the WebDAV directory. """ +import tomllib from io import BytesIO from logging import getLogger -from tomllib import loads as toml_loads from typing import Any +import tomli_w from pydantic import BaseModel -from tomli_w import dump as toml_dump from webdav3.exceptions import RemoteResourceNotFound from .dav_common import caldav_list @@ -119,7 +119,7 @@ class Config(BaseModel): dav_file = DavFile(SETTINGS.config_path) try: - cfg = cls.parse_obj(toml_loads(await dav_file.as_string)) + cfg = cls.model_validate(tomllib.loads(await dav_file.as_string)) except RemoteResourceNotFound: _logger.warning( @@ -130,7 +130,7 @@ class Config(BaseModel): cfg.calendar.aggregates["All Events"] = list(await caldav_list()) buffer = BytesIO() - toml_dump(cfg.dict(), buffer) + tomli_w.dump(cfg.model_dump(), buffer) buffer.seek(0) await dav_file.write(buffer.read()) diff --git a/api/ovdashboard_api/dav_calendar.py b/api/ovdashboard_api/dav_calendar.py index e3f2eda..ab824be 100644 --- a/api/ovdashboard_api/dav_calendar.py +++ b/api/ovdashboard_api/dav_calendar.py @@ -67,7 +67,7 @@ class CalEvent(BaseModel): Compare all properties. """ - return self.dict() == other.dict() + return self.model_dump() == other.model_dump() @classmethod def from_vevent(cls, event: Component) -> "CalEvent": @@ -101,7 +101,7 @@ class CalEvent(BaseModel): del data["duration"] - return cls.parse_obj(data) + return cls.model_validate(data) @AsyncTTL(time_to_live=SETTINGS.cache_time, maxsize=SETTINGS.cache_size) diff --git a/api/ovdashboard_api/routers/v1/_common.py b/api/ovdashboard_api/routers/v1/_common.py index a7fd440..09fe1b5 100644 --- a/api/ovdashboard_api/routers/v1/_common.py +++ b/api/ovdashboard_api/routers/v1/_common.py @@ -57,7 +57,7 @@ class FileNameLister: async def remote_path(self) -> str: cfg = await Config.get() - return str(cfg.dict()[self.path_name]) + return str(cfg.model_dump()[self.path_name]) async def __call__(self) -> Iterator[str]: try: diff --git a/api/ovdashboard_api/settings.py b/api/ovdashboard_api/settings.py index 2a39141..db42f46 100644 --- a/api/ovdashboard_api/settings.py +++ b/api/ovdashboard_api/settings.py @@ -94,7 +94,7 @@ class Settings(BaseSettings): host="example.com", username="ovdashboard", password="secret", - ).dict() + ).model_dump() for key in default_dav: # if "webdav" value is not specified, use default