2015-12-12 00:11:05 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2022-01-23 17:31:07 +01:00
|
|
|
# Copyright 2015-2022 Mike Fährmann
|
2015-12-12 00:11:05 +01:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
|
2017-08-05 16:11:46 +02:00
|
|
|
"""Exception classes used by gallery-dl
|
2017-01-30 19:40:15 +01:00
|
|
|
|
2017-08-05 16:11:46 +02:00
|
|
|
Class Hierarchy:
|
|
|
|
|
|
|
|
Exception
|
|
|
|
+-- GalleryDLException
|
|
|
|
+-- ExtractionError
|
|
|
|
| +-- AuthenticationError
|
|
|
|
| +-- AuthorizationError
|
|
|
|
| +-- NotFoundError
|
|
|
|
| +-- HttpError
|
2017-08-11 21:48:37 +02:00
|
|
|
+-- FormatError
|
2019-10-27 23:05:00 +01:00
|
|
|
| +-- FilenameFormatError
|
|
|
|
| +-- DirectoryFormatError
|
2017-09-08 17:52:00 +02:00
|
|
|
+-- FilterError
|
2019-10-27 23:05:00 +01:00
|
|
|
+-- NoExtractorError
|
2017-08-05 16:11:46 +02:00
|
|
|
+-- StopExtraction
|
2021-05-12 02:22:28 +02:00
|
|
|
+-- TerminateExtraction
|
2017-08-05 16:11:46 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
class GalleryDLException(Exception):
|
|
|
|
"""Base class for GalleryDL exceptions"""
|
2019-10-27 23:05:00 +01:00
|
|
|
default = None
|
|
|
|
msgfmt = None
|
|
|
|
code = 1
|
|
|
|
|
2022-01-23 17:31:07 +01:00
|
|
|
def __init__(self, message=None, fmt=True):
|
2019-10-27 23:05:00 +01:00
|
|
|
if not message:
|
|
|
|
message = self.default
|
|
|
|
elif isinstance(message, Exception):
|
|
|
|
message = "{}: {}".format(message.__class__.__name__, message)
|
2022-01-23 17:31:07 +01:00
|
|
|
if self.msgfmt and fmt:
|
2019-10-27 23:05:00 +01:00
|
|
|
message = self.msgfmt.format(message)
|
|
|
|
Exception.__init__(self, message)
|
2017-08-05 16:11:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ExtractionError(GalleryDLException):
|
|
|
|
"""Base class for exceptions during information extraction"""
|
2016-07-14 14:57:42 +02:00
|
|
|
|
2017-01-30 19:40:15 +01:00
|
|
|
|
2019-10-27 23:05:00 +01:00
|
|
|
class HttpError(ExtractionError):
|
|
|
|
"""HTTP request during data extraction failed"""
|
|
|
|
default = "HTTP request failed"
|
|
|
|
code = 4
|
2016-09-24 13:26:19 +02:00
|
|
|
|
2020-07-30 18:23:26 +02:00
|
|
|
def __init__(self, message, response=None):
|
|
|
|
ExtractionError.__init__(self, message)
|
|
|
|
self.response = response
|
|
|
|
self.status = response.status_code if response else 0
|
|
|
|
|
2017-01-30 19:40:15 +01:00
|
|
|
|
2017-08-05 16:11:46 +02:00
|
|
|
class NotFoundError(ExtractionError):
|
2019-10-27 23:05:00 +01:00
|
|
|
"""Requested resource (gallery/image) could not be found"""
|
|
|
|
msgfmt = "Requested {} could not be found"
|
|
|
|
default = "resource (gallery/image)"
|
|
|
|
code = 8
|
2017-08-05 16:11:46 +02:00
|
|
|
|
|
|
|
|
2019-10-27 23:05:00 +01:00
|
|
|
class AuthenticationError(ExtractionError):
|
|
|
|
"""Invalid or missing login credentials"""
|
|
|
|
default = "Invalid or missing login credentials"
|
|
|
|
code = 16
|
2018-09-05 18:15:33 +02:00
|
|
|
|
|
|
|
|
2019-10-27 23:05:00 +01:00
|
|
|
class AuthorizationError(ExtractionError):
|
|
|
|
"""Insufficient privileges to access a resource"""
|
2019-11-08 20:58:53 +01:00
|
|
|
default = "Insufficient privileges to access the specified resource"
|
2019-10-27 23:05:00 +01:00
|
|
|
code = 16
|
2017-11-10 21:35:53 +01:00
|
|
|
|
|
|
|
|
2019-10-27 23:05:00 +01:00
|
|
|
class FormatError(GalleryDLException):
|
|
|
|
"""Error while building output paths"""
|
|
|
|
code = 32
|
2017-11-10 21:35:53 +01:00
|
|
|
|
|
|
|
|
2019-10-27 23:05:00 +01:00
|
|
|
class FilenameFormatError(FormatError):
|
|
|
|
"""Error while building output filenames"""
|
|
|
|
msgfmt = "Applying filename format string failed ({})"
|
2017-08-05 16:11:46 +02:00
|
|
|
|
|
|
|
|
2019-10-27 23:05:00 +01:00
|
|
|
class DirectoryFormatError(FormatError):
|
|
|
|
"""Error while building output directory paths"""
|
|
|
|
msgfmt = "Applying directory format string failed ({})"
|
2017-08-11 21:48:37 +02:00
|
|
|
|
|
|
|
|
2017-09-08 17:52:00 +02:00
|
|
|
class FilterError(GalleryDLException):
|
|
|
|
"""Error while evaluating a filter expression"""
|
2019-10-27 23:05:00 +01:00
|
|
|
msgfmt = "Evaluating filter expression failed ({})"
|
|
|
|
code = 32
|
|
|
|
|
|
|
|
|
|
|
|
class NoExtractorError(GalleryDLException):
|
|
|
|
"""No extractor can handle the given URL"""
|
|
|
|
code = 64
|
2017-09-08 17:52:00 +02:00
|
|
|
|
|
|
|
|
2017-08-05 16:11:46 +02:00
|
|
|
class StopExtraction(GalleryDLException):
|
2019-10-27 23:05:00 +01:00
|
|
|
"""Stop data extraction"""
|
|
|
|
|
2019-10-28 16:06:36 +01:00
|
|
|
def __init__(self, message=None, *args):
|
2019-10-27 23:05:00 +01:00
|
|
|
GalleryDLException.__init__(self)
|
2019-10-28 16:06:36 +01:00
|
|
|
self.message = message % args if args else message
|
2019-10-27 23:05:00 +01:00
|
|
|
self.code = 1 if message else 0
|
2021-05-12 02:22:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TerminateExtraction(GalleryDLException):
|
|
|
|
"""Terminate data extraction"""
|
|
|
|
code = 0
|