aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/exception.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2019-11-10 22:14:10 -0500
committerLibravatarUnit 193 <unit193@ubuntu.com>2019-11-10 22:14:10 -0500
commit0c73e982fa596da07f23b377621ab894a9e64884 (patch)
tree96f6a40a5656c15a2ec7217a8a1efcff5827bcbb /gallery_dl/exception.py
parent40f5fe6edef268632d3bc484e85e5b37bad67bff (diff)
New upstream version 1.11.1upstream/1.11.1
Diffstat (limited to 'gallery_dl/exception.py')
-rw-r--r--gallery_dl/exception.py81
1 files changed, 54 insertions, 27 deletions
diff --git a/gallery_dl/exception.py b/gallery_dl/exception.py
index 3e86177..783e2b2 100644
--- a/gallery_dl/exception.py
+++ b/gallery_dl/exception.py
@@ -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 AuthenticationError(ExtractionError):
- """Invalid or missing login information"""
-
-
-class AuthorizationError(ExtractionError):
- """Insufficient privileges to access a resource"""
+class HttpError(ExtractionError):
+ """HTTP request during data extraction failed"""
+ default = "HTTP request failed"
+ code = 4
class NotFoundError(ExtractionError):
- """Requested resource (gallery/image) does not exist"""
-
-
-class HttpError(ExtractionError):
- """HTTP request during extraction failed"""
+ """Requested resource (gallery/image) could not be found"""
+ msgfmt = "Requested {} could not be found"
+ default = "resource (gallery/image)"
+ code = 8
-class DownloadError(GalleryDLException):
- """Base class for exceptions during file downloads"""
+class AuthenticationError(ExtractionError):
+ """Invalid or missing login credentials"""
+ default = "Invalid or missing login credentials"
+ code = 16
-class DownloadRetry(DownloadError):
- """Download attempt failed and should be retried"""
+class AuthorizationError(ExtractionError):
+ """Insufficient privileges to access a resource"""
+ default = "Insufficient privileges to access the specified resource"
+ code = 16
-class DownloadComplete(DownloadError):
- """Output file of attempted download is already complete"""
+class FormatError(GalleryDLException):
+ """Error while building output paths"""
+ code = 32
-class NoExtractorError(GalleryDLException):
- """No extractor can handle the given URL"""
+class FilenameFormatError(FormatError):
+ """Error while building output filenames"""
+ msgfmt = "Applying filename format string failed ({})"
-class FormatError(GalleryDLException):
- """Error while building output path"""
+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, *args):
+ GalleryDLException.__init__(self)
+ self.message = message % args if args else message
+ self.code = 1 if message else 0