move some exception handling code
This commit is contained in:
@@ -182,16 +182,7 @@ def main():
|
|||||||
except exception.NoExtractorError:
|
except exception.NoExtractorError:
|
||||||
print("No suitable extractor found for URL '", url, "'",
|
print("No suitable extractor found for URL '", url, "'",
|
||||||
sep="", file=sys.stderr)
|
sep="", file=sys.stderr)
|
||||||
except exception.AuthenticationError:
|
|
||||||
print("Authentication failed. Please provide a valid "
|
|
||||||
"username/password pair.", file=sys.stderr)
|
|
||||||
except exception.AuthorizationError:
|
|
||||||
print("You do not have permission to access the resource ",
|
|
||||||
"at '", url, "'", sep="", file=sys.stderr)
|
|
||||||
except exception.NotFoundError as err:
|
|
||||||
res = str(err) or "resource (gallery/image/user)"
|
|
||||||
print("The ", res, " at '", url, "' does not exist",
|
|
||||||
sep="", file=sys.stderr)
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\nKeyboardInterrupt", file=sys.stderr)
|
print("\nKeyboardInterrupt", file=sys.stderr)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
# it under the terms of the GNU General Public License version 2 as
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
# published by the Free Software Foundation.
|
# published by the Free Software Foundation.
|
||||||
|
|
||||||
|
import sys
|
||||||
import json
|
import json
|
||||||
import hashlib
|
import hashlib
|
||||||
from . import extractor, downloader, config, util, path, output, exception
|
from . import extractor, downloader, config, util, path, output, exception
|
||||||
@@ -16,6 +17,7 @@ class Job():
|
|||||||
"""Base class for Job-types"""
|
"""Base class for Job-types"""
|
||||||
|
|
||||||
def __init__(self, url):
|
def __init__(self, url):
|
||||||
|
self.url = url
|
||||||
self.extractor = extractor.find(url)
|
self.extractor = extractor.find(url)
|
||||||
if self.extractor is None:
|
if self.extractor is None:
|
||||||
raise exception.NoExtractorError(url)
|
raise exception.NoExtractorError(url)
|
||||||
@@ -53,6 +55,16 @@ class Job():
|
|||||||
self.extractor.category, msg[1]
|
self.extractor.category, msg[1]
|
||||||
)
|
)
|
||||||
# TODO: support for multiple message versions
|
# TODO: support for multiple message versions
|
||||||
|
except exception.AuthenticationError:
|
||||||
|
print("Authentication failed. Please provide a valid "
|
||||||
|
"username/password pair.", file=sys.stderr)
|
||||||
|
except exception.AuthorizationError:
|
||||||
|
print("You do not have permission to access the resource ",
|
||||||
|
"at '", self.url, "'", sep="", file=sys.stderr)
|
||||||
|
except exception.NotFoundError as err:
|
||||||
|
res = str(err) or "resource (gallery/image/user)"
|
||||||
|
print("The ", res, " at '", self.url, "' does not exist",
|
||||||
|
sep="", file=sys.stderr)
|
||||||
except exception.StopExtraction:
|
except exception.StopExtraction:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user