[exception] rename 'LoginRequired' to 'AuthRequired'

This commit is contained in:
Mike Fährmann
2025-07-20 22:02:52 +02:00
parent 668556251c
commit f0de034889
6 changed files with 19 additions and 11 deletions

View File

@@ -16,7 +16,7 @@ Exception
│ ├── HttpError │ ├── HttpError
│ │ └── ChallengeError │ │ └── ChallengeError
│ ├── AuthorizationError │ ├── AuthorizationError
│ │ └── LoginRequired │ │ └── AuthRequired
│ ├── AuthenticationError │ ├── AuthenticationError
│ └── NotFoundError │ └── NotFoundError
├── InputError ├── InputError
@@ -93,12 +93,20 @@ class AuthenticationError(ExtractionError):
class AuthorizationError(ExtractionError): class AuthorizationError(ExtractionError):
"""Insufficient privileges to access a resource""" """Insufficient privileges to access a resource"""
default = "Insufficient privileges to access the specified resource" default = "Insufficient privileges to access this resource"
code = 16 code = 16
class LoginRequired(AuthorizationError): class AuthRequired(AuthorizationError):
default = "Account credentials or cookies required" default = "Account credentials required"
def __init__(self, required=None, message=None):
if required and not message:
if isinstance(required, str):
message = f"{required} required"
else:
message = f"{' or '.join(required)} required"
AuthorizationError.__init__(self, message)
class NotFoundError(ExtractionError): class NotFoundError(ExtractionError):

View File

@@ -206,7 +206,7 @@ class CivitaiExtractor(Extractor):
if "Authorization" not in self.api.headers and \ if "Authorization" not in self.api.headers and \
not self.cookies.get( not self.cookies.get(
"__Secure-civitai-token", domain=".civitai.com"): "__Secure-civitai-token", domain=".civitai.com"):
raise exception.LoginRequired("'api-key' or cookies needed") raise exception.AuthRequired(("'api-key'", "cookies"))
def _parse_query(self, value): def _parse_query(self, value):
return text.parse_query_list( return text.parse_query_list(

View File

@@ -216,9 +216,9 @@ class FacebookExtractor(Extractor):
res = self.request(url, **kwargs) res = self.request(url, **kwargs)
if res.url.startswith(self.root + "/login"): if res.url.startswith(self.root + "/login"):
raise exception.LoginRequires( raise exception.AuthRequired(
f"You must be logged in to continue viewing images." message=(f"You must be logged in to continue viewing images."
f"{LEFT_OFF_TXT}" f"{LEFT_OFF_TXT}")
) )
if b'{"__dr":"CometErrorRoot.react"}' in res.content: if b'{"__dr":"CometErrorRoot.react"}' in res.content:

View File

@@ -341,7 +341,7 @@ class IwaraAPI():
def favorites(self, type): def favorites(self, type):
if not self.username: if not self.username:
raise exception.LoginRequired("'username' and 'password' needed") raise exception.AuthRequired("'username' & 'password'")
endpoint = f"/favorites/{type}s" endpoint = f"/favorites/{type}s"
return self._pagination(endpoint) return self._pagination(endpoint)

View File

@@ -31,7 +31,7 @@ class MadokamiMangaExtractor(MadokamiExtractor):
def items(self): def items(self):
username, password = self._get_auth_info() username, password = self._get_auth_info()
if not username: if not username:
raise exception.LoginRequired("Missing 'username' & 'password'") raise exception.AuthRequired("'username' & 'password'")
self.session.auth = util.HTTPBasicAuth(username, password) self.session.auth = util.HTTPBasicAuth(username, password)
url = f"{self.root}/Manga/{self.groups[0]}" url = f"{self.root}/Manga/{self.groups[0]}"

View File

@@ -63,7 +63,7 @@ __tests__ = (
"#comment" : "no username & password", "#comment" : "no username & password",
"#class" : madokami.MadokamiMangaExtractor, "#class" : madokami.MadokamiMangaExtractor,
"#auth" : False, "#auth" : False,
"#exception": exception.LoginRequired, "#exception": exception.AuthRequired,
}, },
) )