overhaul exception stuff
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2015-2018 Mike Fährmann
|
||||
# Copyright 2015-2019 Mike Fährmann
|
||||
#
|
||||
# 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
|
||||
@@ -17,63 +17,90 @@ Exception
|
||||
| +-- AuthorizationError
|
||||
| +-- NotFoundError
|
||||
| +-- HttpError
|
||||
+-- DownloadError
|
||||
| +-- DownloadComplete
|
||||
| +-- DownloadRetry
|
||||
+-- NoExtractorError
|
||||
+-- FormatError
|
||||
| +-- FilenameFormatError
|
||||
| +-- DirectoryFormatError
|
||||
+-- FilterError
|
||||
+-- NoExtractorError
|
||||
+-- StopExtraction
|
||||
"""
|
||||
|
||||
|
||||
class GalleryDLException(Exception):
|
||||
"""Base class for GalleryDL exceptions"""
|
||||
default = None
|
||||
msgfmt = None
|
||||
code = 1
|
||||
|
||||
def __init__(self, message=None):
|
||||
if not message:
|
||||
message = self.default
|
||||
elif isinstance(message, Exception):
|
||||
message = "{}: {}".format(message.__class__.__name__, message)
|
||||
if self.msgfmt:
|
||||
message = self.msgfmt.format(message)
|
||||
Exception.__init__(self, message)
|
||||
|
||||
|
||||
class ExtractionError(GalleryDLException):
|
||||
"""Base class for exceptions during information extraction"""
|
||||
|
||||
|
||||
class HttpError(ExtractionError):
|
||||
"""HTTP request during data extraction failed"""
|
||||
default = "HTTP request failed"
|
||||
code = 4
|
||||
|
||||
|
||||
class NotFoundError(ExtractionError):
|
||||
"""Requested resource (gallery/image) could not be found"""
|
||||
msgfmt = "Requested {} could not be found"
|
||||
default = "resource (gallery/image)"
|
||||
code = 8
|
||||
|
||||
|
||||
class AuthenticationError(ExtractionError):
|
||||
"""Invalid or missing login information"""
|
||||
"""Invalid or missing login credentials"""
|
||||
default = "Invalid or missing login credentials"
|
||||
code = 16
|
||||
|
||||
|
||||
class AuthorizationError(ExtractionError):
|
||||
"""Insufficient privileges to access a resource"""
|
||||
|
||||
|
||||
class NotFoundError(ExtractionError):
|
||||
"""Requested resource (gallery/image) does not exist"""
|
||||
|
||||
|
||||
class HttpError(ExtractionError):
|
||||
"""HTTP request during extraction failed"""
|
||||
|
||||
|
||||
class DownloadError(GalleryDLException):
|
||||
"""Base class for exceptions during file downloads"""
|
||||
|
||||
|
||||
class DownloadRetry(DownloadError):
|
||||
"""Download attempt failed and should be retried"""
|
||||
|
||||
|
||||
class DownloadComplete(DownloadError):
|
||||
"""Output file of attempted download is already complete"""
|
||||
|
||||
|
||||
class NoExtractorError(GalleryDLException):
|
||||
"""No extractor can handle the given URL"""
|
||||
default = "Insufficient privileges to access a resource"
|
||||
code = 16
|
||||
|
||||
|
||||
class FormatError(GalleryDLException):
|
||||
"""Error while building output path"""
|
||||
"""Error while building output paths"""
|
||||
code = 32
|
||||
|
||||
|
||||
class FilenameFormatError(FormatError):
|
||||
"""Error while building output filenames"""
|
||||
msgfmt = "Applying filename format string failed ({})"
|
||||
|
||||
|
||||
class DirectoryFormatError(FormatError):
|
||||
"""Error while building output directory paths"""
|
||||
msgfmt = "Applying directory format string failed ({})"
|
||||
|
||||
|
||||
class FilterError(GalleryDLException):
|
||||
"""Error while evaluating a filter expression"""
|
||||
msgfmt = "Evaluating filter expression failed ({})"
|
||||
code = 32
|
||||
|
||||
|
||||
class NoExtractorError(GalleryDLException):
|
||||
"""No extractor can handle the given URL"""
|
||||
code = 64
|
||||
|
||||
|
||||
class StopExtraction(GalleryDLException):
|
||||
"""Extraction should stop"""
|
||||
"""Stop data extraction"""
|
||||
|
||||
def __init__(self, message=None):
|
||||
GalleryDLException.__init__(self)
|
||||
self.message = message
|
||||
self.code = 1 if message else 0
|
||||
|
||||
Reference in New Issue
Block a user