diff --git a/requirements.txt b/requirements.txt index 06274e1..fc5f9b3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,4 @@ beautifulsoup4 pytz cairosvg httpx -pydantic +pydantic~=2.5 diff --git a/utils/resources_manager.py b/utils/resources_manager.py index 49b5c44..4722ff0 100644 --- a/utils/resources_manager.py +++ b/utils/resources_manager.py @@ -23,7 +23,7 @@ class ResourcesManager: def parse_index(self, index: str): """Parses the index.""" - return Index.parse_raw(index) + return Index.model_validate_json(index) def sync_fetch(self, filepath: str): """Fetches files in sync mode.""" diff --git a/utils/resources_models.py b/utils/resources_models.py index f214fa1..da68e75 100644 --- a/utils/resources_models.py +++ b/utils/resources_models.py @@ -10,7 +10,7 @@ SPDX-License-Identifier: LiLiQ-Rplus-1.1 from collections.abc import Mapping from datetime import datetime -from pydantic import BaseModel +from pydantic import BaseModel, RootModel class File(BaseModel): @@ -22,18 +22,17 @@ class File(BaseModel): return repr(self) -class Resource(BaseModel, Mapping): - # 'A Beautiful Hack' https://github.com/samuelcolvin/pydantic/issues/1802 - __root__: dict[str, list[File]] +class Resource(RootModel, Mapping): + root: dict[str, list[File]] def __getitem__(self, key: str) -> list[File]: - return self.__root__[key] + return self.root[key] def __iter__(self): - return iter(self.__root__) + return iter(self.root) def __len__(self) -> int: - return len(self.__root__) + return len(self.root) # For some reason those were not the same??? def __str__(self) -> str: @@ -41,7 +40,7 @@ class Resource(BaseModel, Mapping): # Make the repr more logical (despite the technical inaccuracy) def __repr_args__(self): - return self.__root__.items() + return self.root.items() class Index(BaseModel, Mapping):