diff --git a/docs/api.rst b/docs/api.rst index 24a3897..23edc69 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -171,16 +171,14 @@ QueryTags .. autoclass:: QueryTags :members: -Token -~~~~~ -.. autoclass:: Permissions() - :members: - User ~~~~ .. autoclass:: User() :members: +.. autoclass:: hondana.user.UserInfo() + :members: + Utilities --------- diff --git a/docs/types.rst b/docs/types.rst index 11ed3bb..28b50a2 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -1,231 +1,231 @@ Response Types and Payloads =========================== -.. currentmodule:: hondana.types +.. currentmodule:: hondana.types_ Common ------ -.. autoclass:: hondana.types.common.LanguageCode +.. autoclass:: hondana.types_.common.LanguageCode :members: :undoc-members: -.. autoclass:: hondana.types.common.LocalizedString +.. autoclass:: hondana.types_.common.LocalizedString Artist ------ -.. autoclass:: hondana.types.artist.ArtistResponse +.. autoclass:: hondana.types_.artist.ArtistResponse -.. autoclass:: hondana.types.artist.ArtistAttributesResponse +.. autoclass:: hondana.types_.artist.ArtistAttributesResponse -.. autoclass:: hondana.types.artist.GetSingleArtistResponse +.. autoclass:: hondana.types_.artist.GetSingleArtistResponse -.. autoclass:: hondana.types.artist.GetMultiArtistResponse +.. autoclass:: hondana.types_.artist.GetMultiArtistResponse Auth ---- -.. autoclass:: hondana.types.auth.TokenResponse +.. autoclass:: hondana.types_.auth.TokenResponse -.. autoclass:: hondana.types.auth.CheckPayload +.. autoclass:: hondana.types_.auth.CheckPayload -.. autoclass:: hondana.types.auth.RefreshPayload +.. autoclass:: hondana.types_.auth.RefreshPayload -.. autoclass:: hondana.types.auth.LoginPayload +.. autoclass:: hondana.types_.auth.LoginPayload Author ------ -.. autoclass:: hondana.types.author.AuthorResponse +.. autoclass:: hondana.types_.author.AuthorResponse -.. autoclass:: hondana.types.author.AuthorAttributesResponse +.. autoclass:: hondana.types_.author.AuthorAttributesResponse -.. autoclass:: hondana.types.author.GetSingleAuthorResponse +.. autoclass:: hondana.types_.author.GetSingleAuthorResponse -.. autoclass:: hondana.types.author.GetMultiAuthorResponse +.. autoclass:: hondana.types_.author.GetMultiAuthorResponse Chapter ------- -.. autoclass:: hondana.types.chapter.ChapterResponse +.. autoclass:: hondana.types_.chapter.ChapterResponse -.. autoclass:: hondana.types.chapter.ChapterAttributesResponse +.. autoclass:: hondana.types_.chapter.ChapterAttributesResponse -.. autoclass:: hondana.types.chapter.GetSingleChapterResponse +.. autoclass:: hondana.types_.chapter.GetSingleChapterResponse -.. autoclass:: hondana.types.chapter.GetMultiChapterResponse +.. autoclass:: hondana.types_.chapter.GetMultiChapterResponse -.. autoclass:: hondana.types.chapter.GetAtHomeResponse +.. autoclass:: hondana.types_.chapter.GetAtHomeResponse -.. autoclass:: hondana.types.chapter.GetAtHomeChapterResponse +.. autoclass:: hondana.types_.chapter.GetAtHomeChapterResponse -.. autoclass:: hondana.types.chapter.ChapterReadResponse +.. autoclass:: hondana.types_.chapter.ChapterReadResponse -.. autoclass:: hondana.types.chapter.ChapterReadHistoryResponse +.. autoclass:: hondana.types_.chapter.ChapterReadHistoryResponse Cover ----- -.. autoclass:: hondana.types.cover.CoverResponse +.. autoclass:: hondana.types_.cover.CoverResponse -.. autoclass:: hondana.types.cover.CoverAttributesResponse +.. autoclass:: hondana.types_.cover.CoverAttributesResponse -.. autoclass:: hondana.types.cover.GetSingleCoverResponse +.. autoclass:: hondana.types_.cover.GetSingleCoverResponse -.. autoclass:: hondana.types.cover.GetMultiCoverResponse +.. autoclass:: hondana.types_.cover.GetMultiCoverResponse CustomList ---------- -.. autoclass:: hondana.types.custom_list.CustomListResponse +.. autoclass:: hondana.types_.custom_list.CustomListResponse -.. autoclass:: hondana.types.custom_list.CustomListAttributesResponse +.. autoclass:: hondana.types_.custom_list.CustomListAttributesResponse -.. autoclass:: hondana.types.custom_list.GetSingleCustomListResponse +.. autoclass:: hondana.types_.custom_list.GetSingleCustomListResponse -.. autoclass:: hondana.types.custom_list.GetMultiCustomListResponse +.. autoclass:: hondana.types_.custom_list.GetMultiCustomListResponse Errors ------ -.. autoclass:: hondana.types.errors.ErrorType +.. autoclass:: hondana.types_.errors.ErrorType -.. autoclass:: hondana.types.errors.APIError +.. autoclass:: hondana.types_.errors.APIError Legacy ------ -.. autoclass:: hondana.types.legacy.LegacyMappingType +.. autoclass:: hondana.types_.legacy.LegacyMappingType :members: :undoc-members: -.. autoclass:: hondana.types.legacy.LegacyMappingResponse +.. autoclass:: hondana.types_.legacy.LegacyMappingResponse -.. autoclass:: hondana.types.legacy.LegacyMappingAttributesResponse +.. autoclass:: hondana.types_.legacy.LegacyMappingAttributesResponse -.. autoclass:: hondana.types.legacy.GetLegacyMappingResponse +.. autoclass:: hondana.types_.legacy.GetLegacyMappingResponse Manga ----- -.. autoclass:: hondana.types.manga.MangaLinks +.. autoclass:: hondana.types_.manga.MangaLinks -.. autoclass:: hondana.types.manga.MangaResponse +.. autoclass:: hondana.types_.manga.MangaResponse -.. autoclass:: hondana.types.manga.GetMangaResponse +.. autoclass:: hondana.types_.manga.GetMangaResponse -.. autoclass:: hondana.types.manga.MangaAttributesResponse +.. autoclass:: hondana.types_.manga.MangaAttributesResponse -.. autoclass:: hondana.types.manga.MangaRelationAttributesResponse +.. autoclass:: hondana.types_.manga.MangaRelationAttributesResponse -.. autoclass:: hondana.types.manga.MangaRelationCreateResponse +.. autoclass:: hondana.types_.manga.MangaRelationCreateResponse -.. autoclass:: hondana.types.manga.MangaSearchResponse +.. autoclass:: hondana.types_.manga.MangaSearchResponse -.. autoclass:: hondana.types.manga.MangaRelation +.. autoclass:: hondana.types_.manga.MangaRelation -.. autoclass:: hondana.types.manga.MangaRelationResponse +.. autoclass:: hondana.types_.manga.MangaRelationResponse -.. autoclass:: hondana.types.manga.VolumesAndChaptersResponse +.. autoclass:: hondana.types_.manga.VolumesAndChaptersResponse -.. autoclass:: hondana.types.manga.ChaptersResponse +.. autoclass:: hondana.types_.manga.ChaptersResponse -.. autoclass:: hondana.types.manga.GetMangaVolumesAndChaptersResponse +.. autoclass:: hondana.types_.manga.GetMangaVolumesAndChaptersResponse -.. autoclass:: hondana.types.manga.MangaReadMarkersResponse +.. autoclass:: hondana.types_.manga.MangaReadMarkersResponse -.. autoclass:: hondana.types.manga.MangaGroupedReadMarkersResponse +.. autoclass:: hondana.types_.manga.MangaGroupedReadMarkersResponse -.. autoclass:: hondana.types.manga.MangaSingleReadingStatusResponse +.. autoclass:: hondana.types_.manga.MangaSingleReadingStatusResponse -.. autoclass:: hondana.types.manga.MangaMultipleReadingStatusResponse +.. autoclass:: hondana.types_.manga.MangaMultipleReadingStatusResponse Relationship ------------ -.. autoclass:: hondana.types.relationship.RelationshipResponse +.. autoclass:: hondana.types_.relationship.RelationshipResponse Report ------ -.. autoclass:: hondana.types.report.ReportReasonResponse +.. autoclass:: hondana.types_.report.ReportReasonResponse -.. autoclass:: hondana.types.report.GetReportReasonAttributesResponse +.. autoclass:: hondana.types_.report.GetReportReasonAttributesResponse -.. autoclass:: hondana.types.report.GetReportReasonResponse +.. autoclass:: hondana.types_.report.GetReportReasonResponse Scanlator Group --------------- -.. autoclass:: hondana.types.scanlator_group.ScanlationGroupResponse +.. autoclass:: hondana.types_.scanlator_group.ScanlationGroupResponse -.. autoclass:: hondana.types.scanlator_group.ScanlationGroupAttributesResponse +.. autoclass:: hondana.types_.scanlator_group.ScanlationGroupAttributesResponse -.. autoclass:: hondana.types.scanlator_group.GetSingleScanlationGroupResponse +.. autoclass:: hondana.types_.scanlator_group.GetSingleScanlationGroupResponse -.. autoclass:: hondana.types.scanlator_group.GetMultiScanlationGroupResponse +.. autoclass:: hondana.types_.scanlator_group.GetMultiScanlationGroupResponse Settings -------- -.. autoclass:: hondana.types.settings.Settings +.. autoclass:: hondana.types_.settings.Settings -.. autoclass:: hondana.types.settings.SettingsPayload +.. autoclass:: hondana.types_.settings.SettingsPayload Statistics ---------- -.. autoclass:: hondana.types.statistics.StatisticsRatingResponse +.. autoclass:: hondana.types_.statistics.StatisticsRatingResponse -.. autoclass:: hondana.types.statistics.BatchStatisticsRatingResponse +.. autoclass:: hondana.types_.statistics.BatchStatisticsRatingResponse -.. autoclass:: hondana.types.statistics.StatisticsResponse +.. autoclass:: hondana.types_.statistics.StatisticsResponse -.. autoclass:: hondana.types.statistics.BatchStatisticsResponse +.. autoclass:: hondana.types_.statistics.BatchStatisticsResponse -.. autoclass:: hondana.types.statistics.GetStatisticsResponse +.. autoclass:: hondana.types_.statistics.GetStatisticsResponse -.. autoclass:: hondana.types.statistics.BatchGetStatisticsResponse +.. autoclass:: hondana.types_.statistics.BatchGetStatisticsResponse -.. autoclass:: hondana.types.statistics.PersonalMangaRatingsResponse +.. autoclass:: hondana.types_.statistics.PersonalMangaRatingsResponse -.. autoclass:: hondana.types.statistics.GetPersonalMangaRatingsResponse +.. autoclass:: hondana.types_.statistics.GetPersonalMangaRatingsResponse Tags ---- -.. autoclass:: hondana.types.tags.TagResponse +.. autoclass:: hondana.types_.tags.TagResponse -.. autoclass:: hondana.types.tags.TagAttributesResponse +.. autoclass:: hondana.types_.tags.TagAttributesResponse -.. autoclass:: hondana.types.tags.GetTagListResponse +.. autoclass:: hondana.types_.tags.GetTagListResponse Token ----- -.. autoclass:: hondana.types.token.TokenPayload +.. autoclass:: hondana.types_.token.TokenPayload User ---- -.. autoclass:: hondana.types.user.UserResponse +.. autoclass:: hondana.types_.user.UserResponse -.. autoclass:: hondana.types.user.GetUserAttributesResponse +.. autoclass:: hondana.types_.user.GetUserAttributesResponse -.. autoclass:: hondana.types.user.GetSingleUserResponse +.. autoclass:: hondana.types_.user.GetSingleUserResponse -.. autoclass:: hondana.types.user.GetMultiUserResponse +.. autoclass:: hondana.types_.user.GetMultiUserResponse Upload ------ -.. autoclass:: hondana.types.upload.UploadSessionAttributes +.. autoclass:: hondana.types_.upload.UploadSessionAttributes -.. autoclass:: hondana.types.upload.GetUploadSessionResponse +.. autoclass:: hondana.types_.upload.GetUploadSessionResponse -.. autoclass:: hondana.types.upload.ChapterUploadAttributes +.. autoclass:: hondana.types_.upload.ChapterUploadAttributes -.. autoclass:: hondana.types.upload.ChapterUploadData +.. autoclass:: hondana.types_.upload.ChapterUploadData -.. autoclass:: hondana.types.upload.BeginChapterUploadResponse +.. autoclass:: hondana.types_.upload.BeginChapterUploadResponse -.. autoclass:: hondana.types.upload.UploadedChapterPageAttributes +.. autoclass:: hondana.types_.upload.UploadedChapterPageAttributes -.. autoclass:: hondana.types.upload.UploadedChapterDataResponse +.. autoclass:: hondana.types_.upload.UploadedChapterDataResponse -.. autoclass:: hondana.types.upload.UploadedChapterResponse +.. autoclass:: hondana.types_.upload.UploadedChapterResponse diff --git a/examples/create_manga.py b/examples/create_manga.py index c8d1478..93d5248 100644 --- a/examples/create_manga.py +++ b/examples/create_manga.py @@ -7,7 +7,7 @@ if TYPE_CHECKING: - from hondana.types.common import LocalizedString + from hondana.types_.common import LocalizedString # Create your client, auth is needed for this. client = hondana.Client(username="my username", password="my password") diff --git a/hondana/__init__.py b/hondana/__init__.py index d22f357..2c9ae62 100644 --- a/hondana/__init__.py +++ b/hondana/__init__.py @@ -32,7 +32,7 @@ from typing import Literal, NamedTuple from . import query as query -from . import types as types +from . import types_ as types_ from . import utils as utils from .artist import * from .author import * @@ -49,7 +49,6 @@ from .report import * from .scanlator_group import * from .tags import * -from .token import * from .user import * from .utils import MANGA_TAGS as MANGA_TAGS from .utils import MANGADEX_URL_REGEX as MANGADEX_URL_REGEX diff --git a/hondana/artist.py b/hondana/artist.py index b9b9560..1f04ce0 100644 --- a/hondana/artist.py +++ b/hondana/artist.py @@ -34,10 +34,10 @@ from .author import Author from .http import HTTPClient from .manga import Manga - from .types.artist import ArtistAttributesResponse, ArtistResponse - from .types.common import LanguageCode, LocalizedString - from .types.manga import MangaResponse - from .types.relationship import RelationshipResponse + from .types_.artist import ArtistAttributesResponse, ArtistResponse + from .types_.common import LanguageCode, LocalizedString + from .types_.manga import MangaResponse + from .types_.relationship import RelationshipResponse __all__ = ("Artist",) diff --git a/hondana/author.py b/hondana/author.py index a816d88..434d074 100644 --- a/hondana/author.py +++ b/hondana/author.py @@ -34,10 +34,10 @@ from .artist import Artist from .http import HTTPClient from .manga import Manga - from .types.author import AuthorAttributesResponse, AuthorResponse - from .types.common import LanguageCode, LocalizedString - from .types.manga import MangaResponse - from .types.relationship import RelationshipResponse + from .types_.author import AuthorAttributesResponse, AuthorResponse + from .types_.common import LanguageCode, LocalizedString + from .types_.manga import MangaResponse + from .types_.relationship import RelationshipResponse __all__ = ("Author",) diff --git a/hondana/chapter.py b/hondana/chapter.py index dc8f5b5..c6c109c 100644 --- a/hondana/chapter.py +++ b/hondana/chapter.py @@ -58,14 +58,14 @@ from aiohttp import ClientResponse from .http import HTTPClient - from .types.chapter import ChapterResponse, GetAtHomeChapterResponse, GetAtHomeResponse, GetSingleChapterResponse - from .types.common import LanguageCode - from .types.errors import ErrorType - from .types.manga import MangaResponse - from .types.relationship import RelationshipResponse - from .types.scanlator_group import ScanlationGroupResponse - from .types.upload import BeginChapterUploadResponse, GetUploadSessionResponse, UploadedChapterResponse - from .types.user import UserResponse + from .types_.chapter import ChapterResponse, GetAtHomeChapterResponse, GetAtHomeResponse, GetSingleChapterResponse + from .types_.common import LanguageCode + from .types_.errors import ErrorType + from .types_.manga import MangaResponse + from .types_.relationship import RelationshipResponse + from .types_.scanlator_group import ScanlationGroupResponse + from .types_.upload import BeginChapterUploadResponse, GetUploadSessionResponse, UploadedChapterResponse + from .types_.user import UserResponse ChapterUploadT = TypeVar("ChapterUploadT", bound="ChapterUpload") diff --git a/hondana/client.py b/hondana/client.py index df2de96..1d6cbb8 100644 --- a/hondana/client.py +++ b/hondana/client.py @@ -85,8 +85,7 @@ from .report import ReportDetails, UserReport from .scanlator_group import ScanlatorGroup from .tags import Tag -from .token import Permissions -from .user import User +from .user import User, UserInfo from .utils import MISSING, require_authentication @@ -94,9 +93,9 @@ from aiohttp import ClientSession from .tags import QueryTags - from .types import common, legacy, manga - from .types.settings import Settings, SettingsPayload - from .types.token import TokenPayload + from .types_ import common, legacy, manga + from .types_.settings import Settings, SettingsPayload + from .types_.token import TokenPayload _PROJECT_DIR = pathlib.Path(__file__) @@ -282,7 +281,7 @@ async def static_login(self) -> None: await self._http._try_token() @property - def permissions(self) -> Optional[Permissions]: + def user_info(self) -> Optional[UserInfo]: """ This attribute will return a permissions instance for the current logged-in user. @@ -292,7 +291,7 @@ def permissions(self) -> Optional[Permissions]: Returns -------- - :class:`~hondana.Permissions` + :class:`~hondana.user.UserInfo` """ if not self._http._authenticated: return None @@ -307,7 +306,7 @@ def permissions(self) -> Optional[Permissions]: payload += "=" * padding parsed_payload: TokenPayload = json.loads(b64decode(payload)) - return Permissions(parsed_payload) + return UserInfo(parsed_payload) @require_authentication def dump_refresh_token( @@ -440,7 +439,7 @@ async def update_report_reasons(self) -> dict[str, dict[str, str]]: ret[category.value] = {} for inner in data["data"]: key_name = ( - inner["attributes"]["reason"]["en"].lower().replace("-", "").replace("/", " or ").replace(" ", "_") # type: ignore # always in en apparently + inner["attributes"]["reason"]["en"].lower().replace("-", "").replace("/", " or ").replace(" ", "_") # type: ignore # these will always be in the `en` key. ) ret[category.value][key_name] = inner["id"] diff --git a/hondana/collections.py b/hondana/collections.py index 205e53a..48eabe6 100644 --- a/hondana/collections.py +++ b/hondana/collections.py @@ -37,15 +37,15 @@ from .manga import Manga, MangaRelation from .report import Report, UserReport from .scanlator_group import ScanlatorGroup - from .types.author import GetMultiAuthorResponse - from .types.chapter import ChapterReadHistoryResponse, GetMultiChapterResponse - from .types.cover import GetMultiCoverResponse - from .types.custom_list import GetMultiCustomListResponse - from .types.legacy import GetLegacyMappingResponse - from .types.manga import MangaRelationResponse, MangaSearchResponse - from .types.report import GetReportReasonResponse, GetUserReportReasonResponse - from .types.scanlator_group import GetMultiScanlationGroupResponse - from .types.user import GetMultiUserResponse + from .types_.author import GetMultiAuthorResponse + from .types_.chapter import ChapterReadHistoryResponse, GetMultiChapterResponse + from .types_.cover import GetMultiCoverResponse + from .types_.custom_list import GetMultiCustomListResponse + from .types_.legacy import GetLegacyMappingResponse + from .types_.manga import MangaRelationResponse, MangaSearchResponse + from .types_.report import GetReportReasonResponse, GetUserReportReasonResponse + from .types_.scanlator_group import GetMultiScanlationGroupResponse + from .types_.user import GetMultiUserResponse from .user import User __all__ = ( diff --git a/hondana/cover.py b/hondana/cover.py index 93c0376..69c48d3 100644 --- a/hondana/cover.py +++ b/hondana/cover.py @@ -32,10 +32,10 @@ if TYPE_CHECKING: from .http import HTTPClient - from .types.common import LanguageCode - from .types.cover import CoverResponse - from .types.manga import MangaResponse - from .types.user import UserResponse + from .types_.common import LanguageCode + from .types_.cover import CoverResponse + from .types_.manga import MangaResponse + from .types_.user import UserResponse __all__ = ("Cover",) diff --git a/hondana/custom_list.py b/hondana/custom_list.py index fa611a2..3bffb1d 100644 --- a/hondana/custom_list.py +++ b/hondana/custom_list.py @@ -34,10 +34,10 @@ if TYPE_CHECKING: from .http import HTTPClient - from .types.custom_list import CustomListResponse - from .types.manga import MangaResponse - from .types.relationship import RelationshipResponse - from .types.user import UserResponse + from .types_.custom_list import CustomListResponse + from .types_.manga import MangaResponse + from .types_.relationship import RelationshipResponse + from .types_.user import UserResponse __all__ = ("CustomList",) diff --git a/hondana/errors.py b/hondana/errors.py index 78fb646..eba35bb 100644 --- a/hondana/errors.py +++ b/hondana/errors.py @@ -29,7 +29,7 @@ if TYPE_CHECKING: - from .types.errors import ErrorType + from .types_.errors import ErrorType __all__ = ( "AuthenticationRequired", diff --git a/hondana/http.py b/hondana/http.py index 3e9c82c..6958ee2 100644 --- a/hondana/http.py +++ b/hondana/http.py @@ -88,7 +88,7 @@ UserReportIncludes, ) from .tags import QueryTags - from .types import ( + from .types_ import ( artist, author, chapter, @@ -103,11 +103,11 @@ upload, user, ) - from .types.account import GetAccountAvailable - from .types.auth import CheckPayload - from .types.settings import Settings, SettingsPayload - from .types.tags import GetTagListResponse - from .types.token import TokenPayload + from .types_.account import GetAccountAvailable + from .types_.auth import CheckPayload + from .types_.settings import Settings, SettingsPayload + from .types_.tags import GetTagListResponse + from .types_.token import TokenPayload from .utils import MANGADEX_QUERY_PARAM_TYPE T = TypeVar("T") diff --git a/hondana/legacy.py b/hondana/legacy.py index ce8930c..b703686 100644 --- a/hondana/legacy.py +++ b/hondana/legacy.py @@ -28,7 +28,7 @@ if TYPE_CHECKING: from .http import HTTPClient - from .types.legacy import LegacyMappingResponse, LegacyMappingType + from .types_.legacy import LegacyMappingResponse, LegacyMappingType __all__ = ("LegacyItem",) diff --git a/hondana/manga.py b/hondana/manga.py index 01adb89..cdfaaae 100644 --- a/hondana/manga.py +++ b/hondana/manga.py @@ -33,20 +33,20 @@ from .enums import ContentRating, MangaRelationType, MangaState, MangaStatus, PublicationDemographic, ReadingStatus from .query import ArtistIncludes, AuthorIncludes, ChapterIncludes, CoverIncludes, FeedOrderQuery, MangaIncludes from .tags import Tag -from .types.cover import CoverResponse from .utils import MISSING, cached_slot_property, relationship_finder, require_authentication if TYPE_CHECKING: from .http import HTTPClient from .tags import QueryTags - from .types import manga - from .types.artist import ArtistResponse - from .types.author import AuthorResponse - from .types.common import LanguageCode, LocalizedString - from .types.manga import MangaResponse - from .types.relationship import RelationshipResponse - from .types.statistics import BatchStatisticsResponse, PersonalMangaRatingsResponse, StatisticsResponse + from .types_ import manga + from .types_.artist import ArtistResponse + from .types_.author import AuthorResponse + from .types_.common import LanguageCode, LocalizedString + from .types_.cover import CoverResponse + from .types_.manga import MangaResponse + from .types_.relationship import RelationshipResponse + from .types_.statistics import BatchStatisticsResponse, PersonalMangaRatingsResponse, StatisticsResponse __all__ = ( diff --git a/hondana/relationship.py b/hondana/relationship.py index 221e555..8837fa7 100644 --- a/hondana/relationship.py +++ b/hondana/relationship.py @@ -28,7 +28,7 @@ if TYPE_CHECKING: - from .types.relationship import RelationshipResponse + from .types_.relationship import RelationshipResponse __all__ = ("Relationship",) diff --git a/hondana/report.py b/hondana/report.py index a99e2f2..274c1ca 100644 --- a/hondana/report.py +++ b/hondana/report.py @@ -40,8 +40,8 @@ if TYPE_CHECKING: from .http import HTTPClient - from .types.common import LocalizedString - from .types.report import ReportReasonResponse, UserReportReasonResponse + from .types_.common import LocalizedString + from .types_.report import ReportReasonResponse, UserReportReasonResponse __all__ = ( diff --git a/hondana/scanlator_group.py b/hondana/scanlator_group.py index 4f13ad1..3b9ba7b 100644 --- a/hondana/scanlator_group.py +++ b/hondana/scanlator_group.py @@ -31,10 +31,10 @@ if TYPE_CHECKING: from .http import HTTPClient - from .types.common import LanguageCode - from .types.relationship import RelationshipResponse - from .types.scanlator_group import ScanlationGroupResponse - from .types.user import UserResponse + from .types_.common import LanguageCode + from .types_.relationship import RelationshipResponse + from .types_.scanlator_group import ScanlationGroupResponse + from .types_.user import UserResponse from .user import User __all__ = ("ScanlatorGroup",) diff --git a/hondana/tags.py b/hondana/tags.py index 844f241..07718aa 100644 --- a/hondana/tags.py +++ b/hondana/tags.py @@ -31,9 +31,9 @@ if TYPE_CHECKING: - from .types.common import LocalizedString - from .types.relationship import RelationshipResponse - from .types.tags import TagResponse + from .types_.common import LocalizedString + from .types_.relationship import RelationshipResponse + from .types_.tags import TagResponse __all__ = ( diff --git a/hondana/token.py b/hondana/token.py deleted file mode 100644 index bfe4d2c..0000000 --- a/hondana/token.py +++ /dev/null @@ -1,91 +0,0 @@ -""" -The MIT License (MIT) - -Copyright (c) 2021-Present AbstractUmbra - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the "Software"), -to deal in the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. -""" -from __future__ import annotations - -import datetime -from typing import TYPE_CHECKING - - -if TYPE_CHECKING: - from .types.token import TokenPayload - - -__all__ = ("Permissions",) - - -class Permissions: - """ - A helper class for the permission attributes of the logged-in user's token details. - - Attributes - ----------- - type: Literal[``session``] - The type of token we have received. - issuer: Literal[``mangadex.org``] - The issuer of the token. - audience: Literal[``mangadex.org``] - The target audience for the token. - issued_at: :class:`datetime.datetime` - When the token was issued. - not_before: :class:`datetime.datetime` - The datetime that the token is valid from. - expires: :class:`datetime.datetime` - When the token expires. - user_id: :class:`str` - The logged-in user's UUID. - roles: List[:class:`str`] - The list of roles the logged-in user has. - permissions: List[:class:`str`] - The list of permissions this user has. - sid: :class:`str` - At the moment I'm not too sure what this is... - """ - - __slots__ = ( - "type", - "issuer", - "audience", - "issued_at", - "not_before", - "expires", - "user_id", - "roles", - "permissions", - "sid", - ) - - def __init__(self, payload: TokenPayload) -> None: - self.type: str = payload["typ"] - self.issuer: str = payload["iss"] - self.audience: str = payload["aud"] - self.issued_at: datetime.datetime = datetime.datetime.fromtimestamp(payload["iat"], datetime.timezone.utc) - self.not_before: datetime.datetime = datetime.datetime.fromtimestamp(payload["nbf"], datetime.timezone.utc) - self.expires: datetime.datetime = datetime.datetime.fromtimestamp(payload["exp"], datetime.timezone.utc) - self.user_id: str = payload["uid"] - self.roles: list[str] = payload["rol"] - self.permissions: list[str] = payload["prm"] - self.sid: str = payload["sid"] - - def __repr__(self) -> str: - return f"" diff --git a/hondana/types/__init__.py b/hondana/types/__init__.py deleted file mode 100644 index a70eaab..0000000 --- a/hondana/types/__init__.py +++ /dev/null @@ -1,45 +0,0 @@ -""" -The MIT License (MIT) - -Copyright (c) 2021-Present AbstractUmbra - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the "Software"), -to deal in the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. -""" - -from __future__ import annotations - -from . import account as account -from . import auth as auth -from . import author as author -from . import chapter as chapter -from . import common as common -from . import cover as cover -from . import custom_list as custom_list -from . import errors as errors -from . import legacy as legacy -from . import manga as manga -from . import relationship as relationship -from . import report as report -from . import scanlator_group as scanlator_group -from . import settings as settings -from . import statistics as statistics -from . import tags as tags -from . import token as token -from . import upload as upload -from . import user as user diff --git a/hondana/types/account.py b/hondana/types_/account.py similarity index 100% rename from hondana/types/account.py rename to hondana/types_/account.py diff --git a/hondana/types/artist.py b/hondana/types_/artist.py similarity index 100% rename from hondana/types/artist.py rename to hondana/types_/artist.py diff --git a/hondana/types/auth.py b/hondana/types_/auth.py similarity index 100% rename from hondana/types/auth.py rename to hondana/types_/auth.py diff --git a/hondana/types/author.py b/hondana/types_/author.py similarity index 100% rename from hondana/types/author.py rename to hondana/types_/author.py diff --git a/hondana/types/chapter.py b/hondana/types_/chapter.py similarity index 100% rename from hondana/types/chapter.py rename to hondana/types_/chapter.py diff --git a/hondana/types/common.py b/hondana/types_/common.py similarity index 100% rename from hondana/types/common.py rename to hondana/types_/common.py diff --git a/hondana/types/cover.py b/hondana/types_/cover.py similarity index 100% rename from hondana/types/cover.py rename to hondana/types_/cover.py diff --git a/hondana/types/custom_list.py b/hondana/types_/custom_list.py similarity index 100% rename from hondana/types/custom_list.py rename to hondana/types_/custom_list.py diff --git a/hondana/types/errors.py b/hondana/types_/errors.py similarity index 100% rename from hondana/types/errors.py rename to hondana/types_/errors.py diff --git a/hondana/types/legacy.py b/hondana/types_/legacy.py similarity index 100% rename from hondana/types/legacy.py rename to hondana/types_/legacy.py diff --git a/hondana/types/manga.py b/hondana/types_/manga.py similarity index 100% rename from hondana/types/manga.py rename to hondana/types_/manga.py diff --git a/hondana/types/relationship.py b/hondana/types_/relationship.py similarity index 100% rename from hondana/types/relationship.py rename to hondana/types_/relationship.py diff --git a/hondana/types/report.py b/hondana/types_/report.py similarity index 100% rename from hondana/types/report.py rename to hondana/types_/report.py diff --git a/hondana/types/scanlator_group.py b/hondana/types_/scanlator_group.py similarity index 100% rename from hondana/types/scanlator_group.py rename to hondana/types_/scanlator_group.py diff --git a/hondana/types/settings.py b/hondana/types_/settings.py similarity index 100% rename from hondana/types/settings.py rename to hondana/types_/settings.py diff --git a/hondana/types/statistics.py b/hondana/types_/statistics.py similarity index 100% rename from hondana/types/statistics.py rename to hondana/types_/statistics.py diff --git a/hondana/types/tags.py b/hondana/types_/tags.py similarity index 100% rename from hondana/types/tags.py rename to hondana/types_/tags.py diff --git a/hondana/types/token.py b/hondana/types_/token.py similarity index 100% rename from hondana/types/token.py rename to hondana/types_/token.py diff --git a/hondana/types/upload.py b/hondana/types_/upload.py similarity index 100% rename from hondana/types/upload.py rename to hondana/types_/upload.py diff --git a/hondana/types/user.py b/hondana/types_/user.py similarity index 100% rename from hondana/types/user.py rename to hondana/types_/user.py diff --git a/hondana/user.py b/hondana/user.py index baf8983..a67a3d4 100644 --- a/hondana/user.py +++ b/hondana/user.py @@ -23,6 +23,7 @@ """ from __future__ import annotations +import datetime from typing import TYPE_CHECKING, Optional from .query import ScanlatorGroupIncludes @@ -32,13 +33,71 @@ if TYPE_CHECKING: from .http import HTTPClient - from .types.relationship import RelationshipResponse - from .types.scanlator_group import ScanlationGroupResponse - from .types.user import UserResponse + from .types_.relationship import RelationshipResponse + from .types_.scanlator_group import ScanlationGroupResponse + from .types_.token import TokenPayload + from .types_.user import UserResponse __all__ = ("User",) +class UserInfo: + """ + A helper class for the permission attributes of the logged-in user's token details. + + Attributes + ----------- + type: Literal[``session``] + The type of token we have received. + issuer: Literal[``mangadex.org``] + The issuer of the token. + audience: Literal[``mangadex.org``] + The target audience for the token. + issued_at: :class:`datetime.datetime` + When the token was issued. + not_before: :class:`datetime.datetime` + The datetime that the token is valid from. + expires: :class:`datetime.datetime` + When the token expires. + user_id: :class:`str` + The logged-in user's UUID. + roles: List[:class:`str`] + The list of roles the logged-in user has. + permissions: List[:class:`str`] + The list of permissions this user has. + sid: :class:`str` + At the moment I'm not too sure what this is... + """ + + __slots__ = ( + "type", + "issuer", + "audience", + "issued_at", + "not_before", + "expires", + "user_id", + "roles", + "permissions", + "sid", + ) + + def __init__(self, payload: TokenPayload) -> None: + self.type: str = payload["typ"] + self.issuer: str = payload["iss"] + self.audience: str = payload["aud"] + self.issued_at: datetime.datetime = datetime.datetime.fromtimestamp(payload["iat"], datetime.timezone.utc) + self.not_before: datetime.datetime = datetime.datetime.fromtimestamp(payload["nbf"], datetime.timezone.utc) + self.expires: datetime.datetime = datetime.datetime.fromtimestamp(payload["exp"], datetime.timezone.utc) + self.user_id: str = payload["uid"] + self.roles: list[str] = payload["rol"] + self.permissions: list[str] = payload["prm"] + self.sid: str = payload["sid"] + + def __repr__(self) -> str: + return f"" + + class User: """ A class representing a user from the MangaDex API. diff --git a/hondana/utils.py b/hondana/utils.py index f5335a8..e651fab 100644 --- a/hondana/utils.py +++ b/hondana/utils.py @@ -67,14 +67,14 @@ from _typeshed import SupportsRichComparison from typing_extensions import Concatenate, ParamSpec, TypeAlias - from .types.artist import ArtistResponse - from .types.author import AuthorResponse - from .types.chapter import ChapterResponse - from .types.cover import CoverResponse - from .types.manga import MangaResponse - from .types.relationship import RelationshipResponse - from .types.scanlator_group import ScanlationGroupResponse - from .types.user import UserResponse + from .types_.artist import ArtistResponse + from .types_.author import AuthorResponse + from .types_.chapter import ChapterResponse + from .types_.cover import CoverResponse + from .types_.manga import MangaResponse + from .types_.relationship import RelationshipResponse + from .types_.scanlator_group import ScanlationGroupResponse + from .types_.user import UserResponse MANGADEX_QUERY_PARAM_TYPE: TypeAlias = dict[str, Optional[Union[str, int, bool, list[str], dict[str, str]]]] C = TypeVar("C", bound="Any") diff --git a/pyproject.toml b/pyproject.toml index d89c358..4fedfb2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -92,6 +92,8 @@ reportUnnecessaryTypeIgnoreComment = "warning" [tool.pytest.ini_options] asyncio_mode = "strict" +[tool.pytest] +testpaths = ["tests"] [tool.poe.tasks] spec = "python _api_dl.py" diff --git a/tests/test_artist.py b/tests/test_artist.py index 28bf74f..ecc5d21 100644 --- a/tests/test_artist.py +++ b/tests/test_artist.py @@ -12,7 +12,7 @@ if TYPE_CHECKING: - from hondana.types.artist import GetSingleArtistResponse + from hondana.types_.artist import GetSingleArtistResponse PATH: pathlib.Path = pathlib.Path(__file__).parent / "payloads" / "artist.json" diff --git a/tests/test_author.py b/tests/test_author.py index 0c715e6..9122e7a 100644 --- a/tests/test_author.py +++ b/tests/test_author.py @@ -12,7 +12,7 @@ if TYPE_CHECKING: - from hondana.types.author import GetSingleAuthorResponse + from hondana.types_.author import GetSingleAuthorResponse PATH: pathlib.Path = pathlib.Path(__file__).parent / "payloads" / "author.json" diff --git a/tests/test_chapter.py b/tests/test_chapter.py index e6ada90..d2ed175 100644 --- a/tests/test_chapter.py +++ b/tests/test_chapter.py @@ -12,7 +12,7 @@ if TYPE_CHECKING: - from hondana.types.chapter import GetSingleChapterResponse + from hondana.types_.chapter import GetSingleChapterResponse PATH: pathlib.Path = pathlib.Path(__file__).parent / "payloads" / "chapter.json" diff --git a/tests/test_collection.py b/tests/test_collection.py index af5291a..98592eb 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -30,14 +30,14 @@ if TYPE_CHECKING: - from hondana.types.author import GetMultiAuthorResponse - from hondana.types.chapter import GetMultiChapterResponse - from hondana.types.cover import GetMultiCoverResponse - from hondana.types.custom_list import GetMultiCustomListResponse - from hondana.types.legacy import GetLegacyMappingResponse - from hondana.types.manga import MangaRelationResponse, MangaSearchResponse - from hondana.types.scanlator_group import GetMultiScanlationGroupResponse - from hondana.types.user import GetMultiUserResponse + from hondana.types_.author import GetMultiAuthorResponse + from hondana.types_.chapter import GetMultiChapterResponse + from hondana.types_.cover import GetMultiCoverResponse + from hondana.types_.custom_list import GetMultiCustomListResponse + from hondana.types_.legacy import GetLegacyMappingResponse + from hondana.types_.manga import MangaRelationResponse, MangaSearchResponse + from hondana.types_.scanlator_group import GetMultiScanlationGroupResponse + from hondana.types_.user import GetMultiUserResponse PATH: pathlib.Path = pathlib.Path(__file__).parent / "payloads" / "collections" HTTP: HTTPClient = object() # type: ignore # this is just for test purposes. diff --git a/tests/test_cover.py b/tests/test_cover.py index 7815c83..d8beca4 100644 --- a/tests/test_cover.py +++ b/tests/test_cover.py @@ -12,7 +12,7 @@ if TYPE_CHECKING: - from hondana.types.cover import GetSingleCoverResponse + from hondana.types_.cover import GetSingleCoverResponse PATH: pathlib.Path = pathlib.Path(__file__).parent / "payloads" / "cover.json" diff --git a/tests/test_custom_list.py b/tests/test_custom_list.py index 3f152be..b370005 100644 --- a/tests/test_custom_list.py +++ b/tests/test_custom_list.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: - from hondana.types.custom_list import GetSingleCustomListResponse + from hondana.types_.custom_list import GetSingleCustomListResponse PATH: pathlib.Path = pathlib.Path(__file__).parent / "payloads" / "custom_list.json" diff --git a/tests/test_legacy.py b/tests/test_legacy.py index 725418f..53d960e 100644 --- a/tests/test_legacy.py +++ b/tests/test_legacy.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: - from hondana.types.legacy import GetLegacyMappingResponse + from hondana.types_.legacy import GetLegacyMappingResponse PATH: pathlib.Path = pathlib.Path(__file__).parent / "payloads" / "legacy_mapping.json" diff --git a/tests/test_manga.py b/tests/test_manga.py index 13efe5e..3d21495 100644 --- a/tests/test_manga.py +++ b/tests/test_manga.py @@ -13,8 +13,8 @@ if TYPE_CHECKING: - from hondana.types.manga import GetMangaResponse, MangaRelationResponse - from hondana.types.statistics import GetPersonalMangaRatingsResponse, GetStatisticsResponse + from hondana.types_.manga import GetMangaResponse, MangaRelationResponse + from hondana.types_.statistics import GetPersonalMangaRatingsResponse, GetStatisticsResponse PATH: pathlib.Path = pathlib.Path(__file__).parent / "payloads" / "manga.json" diff --git a/tests/test_scanlator_group.py b/tests/test_scanlator_group.py index 5c4ece0..4850f69 100644 --- a/tests/test_scanlator_group.py +++ b/tests/test_scanlator_group.py @@ -12,7 +12,7 @@ if TYPE_CHECKING: - from hondana.types.scanlator_group import GetSingleScanlationGroupResponse + from hondana.types_.scanlator_group import GetSingleScanlationGroupResponse PATH: pathlib.Path = pathlib.Path(__file__).parent / "payloads" / "scanlator_group.json" diff --git a/tests/test_tags.py b/tests/test_tags.py index eff8201..7784f4b 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -12,7 +12,7 @@ if TYPE_CHECKING: - from hondana.types.manga import GetMangaResponse + from hondana.types_.manga import GetMangaResponse PATH: pathlib.Path = pathlib.Path(__file__).parent / "payloads" / "manga.json" diff --git a/tests/test_user.py b/tests/test_user.py index ba703b3..819fad6 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: - from hondana.types.user import GetSingleUserResponse + from hondana.types_.user import GetSingleUserResponse PATH: pathlib.Path = pathlib.Path(__file__).parent / "payloads" / "user.json"