move some exception handling code

pull/13/head
Mike Fährmann 8 years ago
parent 6208d9dd79
commit 24f41e13b3
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -182,16 +182,7 @@ def main():
except exception.NoExtractorError:
print("No suitable extractor found for URL '", url, "'",
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:
print("\nKeyboardInterrupt", file=sys.stderr)

@ -6,6 +6,7 @@
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
import sys
import json
import hashlib
from . import extractor, downloader, config, util, path, output, exception
@ -16,6 +17,7 @@ class Job():
"""Base class for Job-types"""
def __init__(self, url):
self.url = url
self.extractor = extractor.find(url)
if self.extractor is None:
raise exception.NoExtractorError(url)
@ -53,6 +55,16 @@ class Job():
self.extractor.category, msg[1]
)
# 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:
pass

Loading…
Cancel
Save